From 824abb73fe7262c0b352de324d1f7c307a0f0e13 Mon Sep 17 00:00:00 2001 From: Martin Meyerhoff Date: Fri, 27 Oct 2023 14:32:58 +0200 Subject: [PATCH] Do not call Spree::PromotionHandler::Shipping when SFP is active SolidusFriendlyPromotions does not need this call, and it could be actively harmful if SFP is active. --- .../order_decorator.rb | 8 +++++++ .../spec/models/spree/order_spec.rb | 23 +++++++++++++++++++ 2 files changed, 31 insertions(+) diff --git a/friendly_promotions/app/decorators/models/solidus_friendly_promotions/order_decorator.rb b/friendly_promotions/app/decorators/models/solidus_friendly_promotions/order_decorator.rb index 20ae5aa75ca..f360230f8b4 100644 --- a/friendly_promotions/app/decorators/models/solidus_friendly_promotions/order_decorator.rb +++ b/friendly_promotions/app/decorators/models/solidus_friendly_promotions/order_decorator.rb @@ -29,6 +29,14 @@ def reset_current_discounts shipments.each(&:reset_current_discounts) end + def apply_shipping_promotions + if Spree::Config.promotion_adjuster_class <= SolidusFriendlyPromotions::OrderDiscounter + recalculate + else + super + end + end + Spree::Order.prepend self end end diff --git a/friendly_promotions/spec/models/spree/order_spec.rb b/friendly_promotions/spec/models/spree/order_spec.rb index 6be2cbff349..d880ca5605f 100644 --- a/friendly_promotions/spec/models/spree/order_spec.rb +++ b/friendly_promotions/spec/models/spree/order_spec.rb @@ -33,4 +33,27 @@ expect { subject }.to change { SolidusFriendlyPromotions::OrderPromotion.count }.from(1).to(0) end end + + describe "#apply_shipping_promotions" do + let(:order) { build(:order) } + subject { order.apply_shipping_promotions } + + it "does not call Spree::PromotionHandler::Shipping" do + expect(Spree::PromotionHandler::Shipping).not_to receive(:new) + subject + end + + context "if solidus_friendly_promotions is not active" do + around do |example| + Spree::Config.promotion_adjuster_class = Spree::Promotion::OrderAdjustmentsRecalculator + example.run + Spree::Config.promotion_adjuster_class = SolidusFriendlyPromotions::OrderDiscounter + end + + it "does call the promotion handler shipping" do + expect(Spree::PromotionHandler::Shipping).to receive(:new).and_call_original + subject + end + end + end end