Skip to content

Commit

Permalink
Merge pull request #4515 from seand7565/seand7565/add_eligibility_che…
Browse files Browse the repository at this point in the history
…ck_to_free_shipping

Add eligibility check to free shipping action
  • Loading branch information
kennyadsl authored Aug 25, 2022
2 parents 232baab + ac240e0 commit 12c0390
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
1 change: 1 addition & 0 deletions core/app/models/spree/promotion/actions/free_shipping.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ class FreeShipping < Spree::PromotionAction
def perform(payload = {})
order = payload[:order]
promotion_code = payload[:promotion_code]
return false unless promotion.eligible? order

created_adjustments = order.shipments.map do |shipment|
next if promotion_credit_exists?(shipment)
Expand Down
11 changes: 11 additions & 0 deletions core/spec/models/spree/promotion/actions/free_shipping_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,17 @@
end
end

context "when given order is ineligible for promotion" do
it "does not create any discounts" do
allow(promotion).to receive(:eligible?).with(order).and_return false

expect(action.perform(payload)).to be false
expect(promotion.usage_count).to eq(0)
expect(order.shipment_adjustments.count).to eq(0)
expect(order.shipment_adjustments.map(&:promotion_code)).to eq []
end
end

context "when a number of the orders shipments already have free shipping" do
let(:shipments) { order.shipments }

Expand Down

0 comments on commit 12c0390

Please sign in to comment.