1

By using line total: {{ cart.lineItems|length }} it returns the number of 'products' in the current sessions cart. However, this doesn't seem to take into account the qty of each variant.

So if I add 3 of variant A and 2 of variant B, the lineItems|length would equal 2. But I want to cart to show there are 5 items added.

How can I get the total of all the items in the cart including qty of each variant?

5

You can get the total quantity of items with:

cart.totalQty

Docs: https://craftcommerce.com/docs/order-model#totalqty

1

After working on this for a while and the help of a fellow developer. The following solution seems to work. Unless anyone can improve on it?

{% set cartQty = 0 %}
{% for item in cart.lineItems %}
    {% set cartQty = cartQty + item.qty %}
{% endfor %}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.