8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
|
# File 'app/models/solidus_promotions/order_adjuster/recalculate_promo_totals.rb', line 8
def call(order)
order.line_items.each do |line_item|
line_item.adjustments.select { _1.amount.zero? }.each(&:mark_for_destruction)
line_item.promo_total = calculate_promo_total_for_adjustable(line_item)
end
order.shipments.each do |shipment|
shipment.adjustments.select { _1.amount.zero? }.each(&:mark_for_destruction)
shipment.shipping_rates.each do |shipping_rate|
shipping_rate.discounts.select { _1.amount.zero? }.each(&:mark_for_destruction)
end
shipment.promo_total = calculate_promo_total_for_adjustable(shipment)
end
line_items = order.line_items.reject(&:marked_for_destruction?)
order.item_total = line_items.sum(&:amount)
order.item_count = line_items.sum(&:quantity)
order.promo_total = (line_items + order.shipments.reject(&:marked_for_destruction?)).sum(&:promo_total)
order.adjustment_total = order.promo_total
order
end
|