Skip to content

Commit

Permalink
Merge pull request #61 from friendlycart/do-not-call-shipping-handler
Browse files Browse the repository at this point in the history
Do not call Spree::PromotionHandler::Shipping when SFP is active
  • Loading branch information
mamhoff authored Oct 27, 2023
2 parents 700aa86 + ebdd020 commit 78f89b1
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 78f89b1

Please sign in to comment.