Skip to content

Commit 536b0ce

Browse files
committed
DiscountedAmount: Exclude discounts marked for destruction
If we mark any discounts for destruction, they should not be part of the total.
1 parent c682f62 commit 536b0ce

File tree

5 files changed

+28
-2
lines changed

5 files changed

+28
-2
lines changed

promotions/app/models/concerns/solidus_promotions/adjustment_discounts.rb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@ module SolidusPromotions
44
module AdjustmentDiscounts
55
def discounts_by_lanes(lanes)
66
adjustments.select do |adjustment|
7-
adjustment.source_type == "SolidusPromotions::Benefit" &&
7+
!adjustment.marked_for_destruction? &&
8+
adjustment.source_type == "SolidusPromotions::Benefit" &&
89
adjustment.source.promotion.lane.to_sym.in?(lanes.map(&:to_sym))
910
end
1011
end

promotions/app/patches/models/solidus_promotions/shipping_rate_patch.rb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,8 @@ def promo_total
2525

2626
def discounts_by_lanes(lanes)
2727
discounts.select do |discount|
28-
discount.benefit.promotion.lane.to_sym.in?(lanes.map(&:to_sym))
28+
!discount.marked_for_destruction? &&
29+
discount.benefit.promotion.lane.to_sym.in?(lanes.map(&:to_sym))
2930
end
3031
end
3132

promotions/spec/models/spree/line_item_spec.rb

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,14 @@
9090
expect(subject).to contain_exactly(pre_lane_adjustment, post_lane_adjustment)
9191
end
9292

93+
context "if adjustment is marked for destruction" do
94+
before do
95+
pre_lane_adjustment.mark_for_destruction
96+
end
97+
98+
it { is_expected.to contain_exactly(post_lane_adjustment) }
99+
end
100+
93101
context "while calculating promotions" do
94102
around do |example|
95103
SolidusPromotions::Promotion.within_lane(lane) do

promotions/spec/models/spree/shipment_spec.rb

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,14 @@
9090
expect(subject).to contain_exactly(pre_lane_adjustment, post_lane_adjustment)
9191
end
9292

93+
context "if adjustment is marked for destruction" do
94+
before do
95+
pre_lane_adjustment.mark_for_destruction
96+
end
97+
98+
it { is_expected.to contain_exactly(post_lane_adjustment) }
99+
end
100+
93101
context "while calculating promotions" do
94102
around do |example|
95103
SolidusPromotions::Promotion.within_lane(lane) do

promotions/spec/models/spree/shipping_rate_spec.rb

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,14 @@
9393
expect(subject).to contain_exactly(pre_lane_discount, post_lane_discount)
9494
end
9595

96+
context "if discount is marked for destruction" do
97+
before do
98+
pre_lane_discount.mark_for_destruction
99+
end
100+
101+
it { is_expected.to contain_exactly(post_lane_discount) }
102+
end
103+
96104
context "while calculating promotions" do
97105
around do |example|
98106
SolidusPromotions::Promotion.within_lane(lane) do

0 commit comments

Comments
 (0)