Skip to content

Commit c281497

Browse files
committed
Keep info about applied promotion
it will be easier to revert it if that's the case
1 parent b428ce2 commit c281497

File tree

3 files changed

+15
-10
lines changed

3 files changed

+15
-10
lines changed

ecommerce/pricing/lib/pricing/events.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ class PriceItemAdded < Infra::Event
4747
attribute :price, Infra::Types::Price
4848
attribute :base_total_value, Infra::Types::Price
4949
attribute :total_value, Infra::Types::Price
50+
attribute? :applied_promotion, Infra::Types::String
5051
end
5152

5253
class PriceItemRemoved < Infra::Event

ecommerce/pricing/lib/pricing/offer.rb

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -19,16 +19,18 @@ def add_item(product_id, base_price, promotion = nil)
1919
price = @discounts.inject(Discounts::NoPercentageDiscount.new, :add).apply(base_price)
2020
end
2121

22-
apply PriceItemAdded.new(
23-
data: {
24-
order_id: @id,
25-
product_id: product_id,
26-
base_price: base_price,
27-
price: price,
28-
base_total_value: @list.base_sum + base_price,
29-
total_value: @list.actual_sum + price
30-
}
31-
)
22+
data = {
23+
order_id: @id,
24+
product_id: product_id,
25+
base_price: base_price,
26+
price: price,
27+
base_total_value: @list.base_sum + base_price,
28+
total_value: @list.actual_sum + price,
29+
}
30+
31+
data[:applied_promotion] = promotion.class.name if promotion
32+
33+
apply PriceItemAdded.new(data:)
3234
end
3335

3436
def remove_item(product_id)

ecommerce/pricing/test/three_plus_one_test.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,7 @@ def test_given_three_items_are_added_when_forth_item_is_added_then_the_last__ite
109109
price: 0,
110110
base_total_value: 80,
111111
total_value: 60,
112+
applied_promotion: Pricing::Discounts::ThreePlusOneGratis.to_s
112113
}
113114
),
114115
OrderTotalValueCalculated.new(
@@ -235,6 +236,7 @@ def test_given_3_plus_one__when_10_percent_discount_for_offer__then_offer_price_
235236
price: 0,
236237
base_total_value: 80,
237238
total_value: 60,
239+
applied_promotion: Pricing::Discounts::ThreePlusOneGratis.to_s
238240
}
239241
),
240242
OrderTotalValueCalculated.new(

0 commit comments

Comments
 (0)