diff options
author | Jared Norman <jared@super.gd> | 2019-02-06 17:10:01 -0800 |
---|---|---|
committer | Jared Norman <jared@super.gd> | 2019-02-06 17:10:01 -0800 |
commit | 9a83ec4cda37760aad82373dc422cadbb33eddfe (patch) | |
tree | a136292d1398688018c92c415b7d6b31dae59d47 /lib | |
parent | 495f343ce7c93421bbde12745a127aff59ef30d0 (diff) |
Provide Spree line items to label makerv0.6.0
Diffstat (limited to 'lib')
-rw-r--r-- | lib/super_good/solidus_taxjar.rb | 2 | ||||
-rw-r--r-- | lib/super_good/solidus_taxjar/tax_calculator.rb | 18 |
2 files changed, 13 insertions, 7 deletions
diff --git a/lib/super_good/solidus_taxjar.rb b/lib/super_good/solidus_taxjar.rb index ef9497d..818947d 100644 --- a/lib/super_good/solidus_taxjar.rb +++ b/lib/super_good/solidus_taxjar.rb @@ -26,6 +26,6 @@ module SuperGood } self.taxable_address_check = ->(address) { true } self.shipping_tax_label_maker = ->(shipment, shipping_tax) { "Sales Tax" } - self.line_item_tax_label_maker = ->(taxjar_line_item) { "Sales Tax" } + self.line_item_tax_label_maker = ->(taxjar_line_item, spree_line_item) { "Sales Tax" } end end diff --git a/lib/super_good/solidus_taxjar/tax_calculator.rb b/lib/super_good/solidus_taxjar/tax_calculator.rb index 91ff6c0..5052814 100644 --- a/lib/super_good/solidus_taxjar/tax_calculator.rb +++ b/lib/super_good/solidus_taxjar/tax_calculator.rb @@ -35,12 +35,18 @@ module SuperGood def line_item_taxes @line_item_taxes ||= - taxjar_breakdown.line_items.map do |line_item| + taxjar_breakdown.line_items.map do |taxjar_line_item| + spree_line_item_id = taxjar_line_item.id.to_i + + # Searching in memory because this association is loaded and most + # orders aren't going to have a huge number of line items. + spree_line_item = order.line_items.find { |li| li.id == spree_line_item_id } + Spree::Tax::ItemTax.new( - item_id: line_item.id.to_i, - label: line_item_tax_label(line_item), + item_id: spree_line_item_id, + label: line_item_tax_label(taxjar_line_item, spree_line_item), tax_rate: tax_rate, - amount: line_item.tax_collectable, + amount: taxjar_line_item.tax_collectable, included_in_price: false ) end @@ -141,8 +147,8 @@ module SuperGood ) end - def line_item_tax_label(taxjar_line_item) - SuperGood::SolidusTaxJar.line_item_tax_label_maker.(taxjar_line_item) + def line_item_tax_label(taxjar_line_item, spree_line_item) + SuperGood::SolidusTaxJar.line_item_tax_label_maker.(taxjar_line_item, spree_line_item) end end end |