Skip to content

Commit 542cadc

Browse files
committed
Distributed amounts handler: Don't require IDs
In-memory line items don't have an ID, but we can just use the line item itself as the key.
1 parent f54d7ff commit 542cadc

File tree

1 file changed

+2
-6
lines changed

1 file changed

+2
-6
lines changed

promotions/app/models/solidus_promotions/distributed_amounts_handler.rb

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ def initialize(line_items, total_amount)
1212
# @param line_item [LineItem] one of the line_items distributed over
1313
# @return [BigDecimal] the weighted adjustment for this line_item
1414
def amount(line_item)
15-
distributed_amounts[line_item.id].to_d
15+
distributed_amounts[line_item].to_d
1616
end
1717

1818
private
@@ -21,11 +21,7 @@ def amount(line_item)
2121
# @return [Hash<Integer, BigDecimal>] a hash of line item IDs and their
2222
# corresponding weighted adjustments
2323
def distributed_amounts
24-
line_item_ids.zip(allocated_amounts).to_h
25-
end
26-
27-
def line_item_ids
28-
line_items.map(&:id)
24+
line_items.zip(allocated_amounts).to_h
2925
end
3026

3127
def elligible_amounts

0 commit comments

Comments
 (0)