Skip to content

Commit

Permalink
IN-392 Changes sf services and spree services to build returns too
Browse files Browse the repository at this point in the history
  • Loading branch information
reinaldob committed Dec 16, 2014
1 parent 110cef5 commit 393d803
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 17 deletions.
2 changes: 1 addition & 1 deletion lib/SF_services/return.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ def find_order(id)
results.any? ? results.first['Id'] : nil
end

def upsert!(payment_attr = {}, order_code, email)
def upsert!(payment_attr = {}, order_code)
order_id = find_order(order_code)

payment_attr = payment_attr.merge( { 'ParentId' => order_id } ) if order_id.present?
Expand Down
4 changes: 4 additions & 0 deletions lib/integrations/base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -32,5 +32,9 @@ def line_item_service
def payment_service
@payment_service ||= SFService::Payment.new(config)
end

def return_service
@return_service ||= SFService::Return.new(config)
end
end
end
20 changes: 4 additions & 16 deletions lib/integrations/return.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,33 +10,21 @@ def initialize(config, object)

def handle_all!
@object.each { |_return| handle _return }
@object.each { |_return| handle_payment _return }
end

def handle _return
returned_items = _return["inventory_units"].map{|item| item["variant"]["sku"]}
returned_counts = returned_items.inject(Hash.new(0)) { |total, item| total[item] += 1; total }
result = "Returned items: "
returned_counts.each { |item_name, count| result += "#{item_name}: (#{count}) " }
order_service.update!(order_params(_return).merge({"Notes__c" => result}))
end

def handle_payment _return
payment_service.upsert!(payment_params(_return), _return["order_id"], order(_return)["Email__c"])
#.merge({"extra" => result})
return_service.upsert!(return_params(_return), _return['order_id'])
end

private

def order _return
@order ||= order_service.find(_return["order_id"])
end

def order_params _return
Integration::Builder::OrderFromSf.new(order(_return)).build
end

def payment_params _return
Integration::Builder::PaymentFromReturn.new(_return).build
def return_params _return
Integration::Builder::Return.new(_return).build
end
end
end
1 change: 1 addition & 0 deletions lib/salesforce_integration.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
require 'integrations/builders/payment'
require 'integrations/builders/payment_from_return'
require 'integrations/builders/order_product'
require 'integrations/builders/return'

require 'SF_services/base'
require 'SF_services/account'
Expand Down

0 comments on commit 393d803

Please sign in to comment.