I have a view helper that totals the items inside line items. Each order can have many line items. Each line item has different sizes inside it (the fields). For this below I’m curious how to sum up a certain field for multiple line items.
def total_items(order)
xxs = order.lineitems.xxs.sum
return xxs
end
This is what I have but doesn’t work when there are multiple line items for an order, how can I properly write it?
It is not very obvious what you are asking, but I think what you want is something like this:
What this method does, is similar to this:
By the way, in Ruby the
returnkeyword is optional.