Skip to content

Commit

Permalink
Pass product id on to line item service
Browse files Browse the repository at this point in the history
  • Loading branch information
huoxito committed Dec 16, 2014
1 parent 7ade76d commit 041906a
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 37 deletions.
11 changes: 2 additions & 9 deletions lib/SF_services/line_item.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,20 +16,13 @@ def find_line_item(order_id, product_id)
results.any? ? results.first['Id'] : nil
end

def upsert!(line_item_attr = {}, opportunity_id, product_code)
# FIXME product ids are already fetched before on the stack
results = salesforce.query("select Id from Product2 where ProductCode = '#{product_code}'")
raise SalesfoceIntegrationError, "Product #{product_code} not found" unless results.first

product_id = results.first["Id"]

def upsert!(line_item_attr = {}, opportunity_id, product_id)
# FIXME same here standard price book id is already fetched before
unless standard = salesforce.query("select Id from Pricebook2 where isStandard=true").first
raise SalesfoceIntegrationError, "Standard price book not found for #{product_code}"
raise SalesfoceIntegrationError, "Standard price book when building opportunity line"
end

standard_id = standard['Id']
product_id = results.first['Id']

pricebookentry = SFService::Base.new "PricebookEntry", config

Expand Down
24 changes: 0 additions & 24 deletions lib/integrations/line_item.rb

This file was deleted.

17 changes: 14 additions & 3 deletions lib/integrations/order.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ def upsert!
opportunity_id = order_service.upsert! params

product_integration = Product.new(config, object[:order])
line_item_integration = LineItem.new(config, object[:order])
line_item_integration = LineItem.new(config)

object[:order][:line_items].each do |line_item|

Expand All @@ -27,9 +27,9 @@ def upsert!

product_id = product_integration.create! params
end
end

LineItem.new(config, object[:order]).upsert! opportunity_id
line_item_integration.upsert! line_item, opportunity_id, product_id
end
end

private
Expand All @@ -38,4 +38,15 @@ def order_params
Builder::Order.new(object[:order]).build
end
end

class LineItem < Base
def upsert!(item, opportunity_id, product_id)
params = build_oportunity_line item
line_item_service.upsert!(params, opportunity_id, product_id)
end

def build_oportunity_line(item)
Builder::LineItem.new(item).build
end
end
end
1 change: 0 additions & 1 deletion lib/salesforce_integration.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
require 'integrations/contact_account'
require 'integrations/product'
require 'integrations/order'
require 'integrations/line_item'
require 'integrations/payment'
require 'integrations/return'

Expand Down

0 comments on commit 041906a

Please sign in to comment.