From e46a06df35f8d1d792905462f81229d28af215ca Mon Sep 17 00:00:00 2001 From: Calvin Yu Date: Wed, 11 Jan 2017 00:32:08 -0500 Subject: [PATCH] Apply tax on discounted price --- app/models/spree/line_item_decorator.rb | 2 +- app/models/spree/tax_cloud.rb | 12 +++++++++++- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/app/models/spree/line_item_decorator.rb b/app/models/spree/line_item_decorator.rb index 986f8ee..fba5977 100644 --- a/app/models/spree/line_item_decorator.rb +++ b/app/models/spree/line_item_decorator.rb @@ -1,6 +1,6 @@ Spree::LineItem.class_eval do def tax_cloud_cache_key - key = "Spree::LineItem #{id}: #{quantity}x<#{variant.cache_key}>@#{price}#{currency}" + key = "Spree::LineItem #{id}: #{quantity}x<#{variant.cache_key}>@#{price}#{currency}promo_total<#{promo_total}>" if order.ship_address key << "shipped_to<#{order.ship_address.try(:cache_key)}>" elsif order.bill_address diff --git a/app/models/spree/tax_cloud.rb b/app/models/spree/tax_cloud.rb index a5d1728..bab3a9c 100644 --- a/app/models/spree/tax_cloud.rb +++ b/app/models/spree/tax_cloud.rb @@ -42,13 +42,23 @@ def self.address_from_spree_address(address) end def self.cart_item_from_item(item, index) + + puts '!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!' + puts '!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!' + puts "promo_tota: #{item.promo_total}" + puts "quantity: #{item.quantity}" + puts "price: #{item.price}" + puts '!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!' + puts '!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!' + + case item when Spree::LineItem ::TaxCloud::CartItem.new( index: index, item_id: item.try(:variant).try(:sku).present? ? item.try(:variant).try(:sku) : "LineItem #{item.id}", tic: (item.product.tax_cloud_tic || Spree::Config.taxcloud_default_product_tic), - price: item.price, + price: item.quantity == 0 ? item.price : (item.promo_total / item.quantity) + item.price, quantity: item.quantity ) when Spree::Shipment