-
-
Save yevgenko/e6dc49530334dd54332e to your computer and use it in GitHub Desktop.
The function that extracts allocated products variants with quantities
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def variants_quantities | |
line_items.each_with_object({}) do |line_item, variants| | |
if line_item.sellable.variant? | |
variants[line_item.sellable] ||= 0 | |
variants[line_item.sellable] += line_item.quantity | |
elsif line_item.sellable.kit? | |
line_item.sellable.contents.each do |content| | |
variants[content.variant] ||= 0 | |
variants[content.variant] += content.quantity * line_item.quantity | |
end | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment