From d7a54d92fd1bc44a8d2865c3edd4990be054df13 Mon Sep 17 00:00:00 2001 From: Jordan Brough Date: Tue, 16 Aug 2016 22:39:13 -0600 Subject: [PATCH 1/2] Remove ItemAdjustments#update in apply_free_shipping_promotions Let it be invoked via OrderUpdater#update instead. --- core/app/models/spree/order.rb | 4 +--- core/spec/models/spree/order_spec.rb | 12 ++++-------- 2 files changed, 5 insertions(+), 11 deletions(-) diff --git a/core/app/models/spree/order.rb b/core/app/models/spree/order.rb index 7ce729868b8..9b6b9d73070 100644 --- a/core/app/models/spree/order.rb +++ b/core/app/models/spree/order.rb @@ -511,9 +511,7 @@ def create_proposed_shipments def apply_free_shipping_promotions Spree::PromotionHandler::FreeShipping.new(self).activate - shipments.each { |shipment| ItemAdjustments.new(shipment).update } - updater.update_shipment_total - persist_totals + update! end # Clean shipments and make order back to address state diff --git a/core/spec/models/spree/order_spec.rb b/core/spec/models/spree/order_spec.rb index 63ff4dfaf5f..a3d6923ce50 100644 --- a/core/spec/models/spree/order_spec.rb +++ b/core/spec/models/spree/order_spec.rb @@ -591,16 +591,12 @@ def merge!(other_order, user = nil) context "#apply_free_shipping_promotions" do it "calls out to the FreeShipping promotion handler" do - shipment = double('Shipment') - allow(order).to receive_messages shipments: [shipment] - expect(Spree::PromotionHandler::FreeShipping).to receive(:new).and_return(handler = double) - expect(handler).to receive(:activate) + expect_any_instance_of(Spree::PromotionHandler::FreeShipping).to( + receive(:activate) + ).and_call_original - expect(Spree::ItemAdjustments).to receive(:new).with(shipment).and_return(adjuster = double) - expect(adjuster).to receive(:update) + expect(order.updater).to receive(:update).and_call_original - expect(order.updater).to receive(:update_shipment_total) - expect(order.updater).to receive(:persist_totals) order.apply_free_shipping_promotions end end From bee73374f7119d5a48241a9aa1716c1769579735 Mon Sep 17 00:00:00 2001 From: Jordan Brough Date: Wed, 17 Aug 2016 06:05:13 -0600 Subject: [PATCH 2/2] Remove ItemAdjustments#update from OrderContents `reload_totals` is called just after this and it invokes ItemAdjustments#update on its own. --- core/app/models/spree/order_contents.rb | 1 - 1 file changed, 1 deletion(-) diff --git a/core/app/models/spree/order_contents.rb b/core/app/models/spree/order_contents.rb index 18c6d601d29..5c317dd9351 100644 --- a/core/app/models/spree/order_contents.rb +++ b/core/app/models/spree/order_contents.rb @@ -119,7 +119,6 @@ def after_add_or_remove(line_item, options = {}) shipment = options[:shipment] shipment.present? ? shipment.update_amounts : order.ensure_updated_shipments PromotionHandler::Cart.new(order, line_item).activate - ItemAdjustments.new(line_item).update reload_totals line_item end