Skip to content

Commit

Permalink
Do not call Spree::PromotionHandler::Shipping when SFP is active
Browse files Browse the repository at this point in the history
SolidusFriendlyPromotions does not need this call, and it could be
actively harmful if SFP is active.
  • Loading branch information
mamhoff authored and Astr0surf3r committed Nov 14, 2024
1 parent 81ce9fe commit 824abb7
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
23 changes: 23 additions & 0 deletions friendly_promotions/spec/models/spree/order_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit 824abb7

Please sign in to comment.