Skip to content

Instantly share code, notes, and snippets.

@yevgenko
Last active December 31, 2015 13:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save yevgenko/e6dc49530334dd54332e to your computer and use it in GitHub Desktop.
Save yevgenko/e6dc49530334dd54332e to your computer and use it in GitHub Desktop.
The function that extracts allocated products variants with quantities
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