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 20ae5aa7..f360230f 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 6be2cbff..d880ca56 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