Skip to content

Commit

Permalink
Also check connected promotions in the promotion shipping handler
Browse files Browse the repository at this point in the history
  • Loading branch information
jordan-brough authored and fylooi committed Sep 8, 2017
1 parent 4c8b3c6 commit 2c34832
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 4 deletions.
10 changes: 6 additions & 4 deletions core/app/models/spree/promotion_handler/shipping.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,12 @@ def initialize(order)

def activate
connected_promotions.each do |order_promotion|
order_promotion.promotion.activate(
order: order,
promotion_code: order_promotion.promotion_code,
)
if order_promotion.promotion.eligible?(order)
order_promotion.promotion.activate(
order: order,
promotion_code: order_promotion.promotion_code,
)
end
end

not_connected_automatic_promotions.each do |promotion|
Expand Down
16 changes: 16 additions & 0 deletions core/spec/models/spree/promotion_handler/shipping_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,22 @@ module PromotionHandler
subject.activate
}.to change { shipment.adjustments.count }
end

context 'when currently ineligible' do
let(:promotion) do
create(:promotion, :with_item_total_rule, item_total_threshold_amount: 1_000, code: 'freeshipping', promotion_actions: [action])
end

before do
order.order_promotions.create!(promotion: promotion, promotion_code: promotion.codes.first)
end

it 'does not adjust the shipment' do
expect {
subject.activate
}.to_not change { shipment.adjustments.count }
end
end
end

context 'when not already applied' do
Expand Down

0 comments on commit 2c34832

Please sign in to comment.