Skip to content

Commit c69bc43

Browse files
committed
Extend DiscountChanged event
1 parent 98adb88 commit c69bc43

File tree

3 files changed

+14
-4
lines changed

3 files changed

+14
-4
lines changed

ecommerce/pricing/lib/pricing/events.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,8 @@ class PercentageDiscountChanged < Infra::Event
7070
attribute :order_id, Infra::Types::UUID
7171
attribute :type, Infra::Types::String
7272
attribute :amount, Infra::Types::Price
73+
attribute :base_total_value, Infra::Types::Price
74+
attribute :total_value, Infra::Types::Price
7375
end
7476

7577
class ProductMadeFreeForOrder < Infra::Event

ecommerce/pricing/lib/pricing/offer.rb

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,9 @@ def change_discount(discount)
6868
data: {
6969
order_id: @id,
7070
type: discount.type,
71-
amount: discount.value
71+
amount: discount.value,
72+
base_total_value: @list.base_sum,
73+
total_value: @list.base_sum - @list.base_sum * (discount.value / 100)
7274
}
7375
)
7476
end

ecommerce/pricing/test/pricing_test.rb

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,9 @@ def test_calculates_total_value_with_discount
189189
data: {
190190
order_id: order_id,
191191
type: Pricing::Discounts::GENERAL_DISCOUNT,
192-
amount: 50
192+
amount: 50,
193+
base_total_value: 20,
194+
total_value: 10
193195
}
194196
),
195197
OrderTotalValueCalculated.new(
@@ -341,7 +343,9 @@ def test_changing_discount_possible_when_discount_is_set
341343
data: {
342344
order_id: order_id,
343345
type: Pricing::Discounts::GENERAL_DISCOUNT,
344-
amount: 100
346+
amount: 100,
347+
base_total_value: 20,
348+
total_value: 0
345349
}
346350
),
347351
OrderTotalValueCalculated.new(
@@ -377,7 +381,9 @@ def test_changing_discount_possible_more_than_once
377381
data: {
378382
order_id: order_id,
379383
type: Pricing::Discounts::GENERAL_DISCOUNT,
380-
amount: 100
384+
amount: 100,
385+
base_total_value: 20,
386+
total_value: 0
381387
}
382388
),
383389
OrderTotalValueCalculated.new(

0 commit comments

Comments
 (0)