Skip to content

Commit 2d3aea3

Browse files
Removed sub_amounts_total and simplified quantities method
1 parent ef1d613 commit 2d3aea3

File tree

1 file changed

+5
-13
lines changed

1 file changed

+5
-13
lines changed

ecommerce/pricing/lib/pricing/offer.rb

Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -133,8 +133,6 @@ def expire
133133
@list.remove_item(event.data.fetch(:product_id), event.data.fetch(:price))
134134
end
135135

136-
137-
138136
on PercentageDiscountSet do |event|
139137
@discounts << Discounts::PercentageDiscount.new(event.data.fetch(:type), event.data.fetch(:amount))
140138
@list.apply_discounts(@discounts)
@@ -206,15 +204,6 @@ def contains_free_products?
206204
end
207205

208206

209-
def sub_amounts_total
210-
@items.each_with_object({}) do |item, memo|
211-
memo[item.product_id] ||= { base_amount: 0, amount: 0, quantity: 0 }
212-
memo[item.product_id][:base_amount] += item.base_price * item.quantity
213-
memo[item.product_id][:amount] += item.price * item.quantity
214-
memo[item.product_id][:quantity] += item.quantity
215-
end
216-
end
217-
218207
def set_free(product_id)
219208
idx = @items.index { |item| item.product_id == product_id && item.price != 0 }
220209
old_item = @items.delete_at(idx)
@@ -236,8 +225,11 @@ def lowest_price_item(product_id)
236225
end
237226

238227
def quantities
239-
sub_amounts_total.map do |product_id, h|
240-
{ product_id:, quantity: h.fetch(:quantity) }
228+
@items.each_with_object({}) do |item, memo|
229+
memo[item.product_id] ||= 0
230+
memo[item.product_id] += item.quantity
231+
end.map do |product_id, quantity|
232+
{ product_id:, quantity: }
241233
end
242234
end
243235

0 commit comments

Comments
 (0)