shopwareshopware6

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?


Solution

  • 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 %}