<p>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?</p>

<pre><code>{% set cartQty = 0 %}
{% for item in cart.lineItems %}
    {% set cartQty = cartQty + item.qty %}
{% endfor %}
</code></pre>

CC BY-SA 3.0
2016-07-21T19:52:52.210Z
2016-07-21T19:52:52.210Z
Terry Upton
<p>You can get the total quantity of items with:</p>

<p><code>cart.totalQty</code></p>

<p>Docs: <a href="https://craftcommerce.com/docs/order-model#totalqty" rel="noreferrer">https://craftcommerce.com/docs/order-model#totalqty</a></p>

CC BY-SA 3.0
2016-07-21T20:39:32.623Z
2016-07-21T20:39:32.623Z
Luke Holder
<p>By using <code>line total: {{ cart.lineItems|length }}</code> 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. </p>

<p>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.</p>

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

<plugin-craftcommerce><ecommerce>
Cart Items Total to include qty of variants
# Cart Items Total to include qty of variants

(Asked by: username_0 on 2016-07-21)

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?

**Tags:** plugin-craftcommerce, ecommerce

---

## 2 answers

### Answer by username_1 on 2016-07-21. Score: 6 | Accepted answer

You can get the total quantity of items with:

`cart.totalQty`

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


---

### Answer by username_0 on 2016-07-21. Score: 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 %}


---

