diff --git a/core/app/models/spree/in_memory_order_updater.rb b/core/app/models/spree/in_memory_order_updater.rb index fc59a8a29f..9624bff84d 100644 --- a/core/app/models/spree/in_memory_order_updater.rb +++ b/core/app/models/spree/in_memory_order_updater.rb @@ -117,7 +117,7 @@ def update_adjustments(persist:) # http://www.hmrc.gov.uk/vat/managing/charging/discounts-etc.htm#1 # It also fits the criteria for sales tax as outlined here: # http://www.boe.ca.gov/formspubs/pub113/ - update_promotions + update_promotions(persist:) update_taxes update_item_totals(persist:) end @@ -153,8 +153,12 @@ def update_adjustment_total(persist:) recalculate_order_total end - def update_promotions - Spree::Config.promotions.order_adjuster_class.new(order).call + def update_promotions(persist:) + if persist + Spree::Config.promotions.order_adjuster_class + else + InMemoryOrderAdjuster + end.new(order).call end def update_taxes @@ -239,5 +243,13 @@ def log_state_change(name) ) end end + + class InMemoryOrderAdjuster + def initialize(order) + end + + def call + end + end end end diff --git a/core/spec/models/spree/in_memory_order_updater_spec.rb b/core/spec/models/spree/in_memory_order_updater_spec.rb index 91ce3451bb..9794ca8995 100644 --- a/core/spec/models/spree/in_memory_order_updater_spec.rb +++ b/core/spec/models/spree/in_memory_order_updater_spec.rb @@ -166,6 +166,17 @@ module Spree line_item.additional_tax_total }.from(1).to(2) end + + context "when recalculating the order in memory" do + it "raises an error" do + order_adjuster = double + allow(order_adjuster).to receive(:call) { raise NotImplementedError } + allow(Spree::InMemoryOrderUpdater::InMemoryOrderAdjuster).to receive(:new).and_return(order_adjuster) + + expect{described_class.new(order).recalculate(persist: false)} + .to raise_error(NotImplementedError) + end + end end context 'with a custom tax_calculator_class' do