Refactor PerItem calculator to ease readability

This commit is contained in:
Pau Perez
2020-03-14 11:04:16 +01:00
parent 63a1d4145a
commit 71576fd7db

View File

@@ -13,14 +13,15 @@ module Spree
def compute(object = nil)
return 0 if object.nil?
preferred_amount * line_items_for(object).reduce(0) do |sum, value|
value_to_add = if matching_products.blank? || matching_products.include?(value.product)
value.quantity
number_of_line_items = line_items_for(object).reduce(0) do |sum, line_item|
value_to_add = if matching_products.blank? || matching_products.include?(line_item.product)
line_item.quantity
else
0
end
sum + value_to_add
end
preferred_amount * number_of_line_items
end
end
end