Auhona
Auhona

Reputation: 211

How to display line item quantity at checkout/finish page in Shopware 6?

I'm working on a Shopware 6 project and trying to display the quantity of line items in a twig template: <plugin root>/src/Resources/views/storefront/page/checkout/finish/index.html.twig.

However, when I try to access the quantity property in the index.html.twig, I am getting an empty string. However, this gives the correct value in base.html.twig.

Here's the code I'm using:

{% set count = 0 %} 
{% for item in page.order.lineItems %}
    {% set count = item.quantity + count %}
{% endfor %}

How can I access quantity of the final checkout in case of

2x Produkt A
1x Produkt B

so that the total quantity I get will be 3?

Upvotes: 1

Views: 187

Answers (1)

Yehor Samoilenko
Yehor Samoilenko

Reputation: 437

Below is a code fragment demonstrating counting the number of all order items whose type is equal to product:

{% set PRODUCT_LINE_ITEM_TYPE = constant('Shopware\\Core\\Checkout\\Cart\\LineItem\\LineItem::PRODUCT_LINE_ITEM_TYPE') %}

{% set totalQuantity = 0 %}
{% for lineItem in page.order.nestedLineItems %}
    {% if lineItem.type == PRODUCT_LINE_ITEM_TYPE %}
        {% set totalQuantity = totalQuantity + lineItem.quantity %}
    {% endif %}
{% endfor %}

Upvotes: 2

Related Questions