2

As of Commerce 2.2 line items are ordered by date created.

How can you order line items differently?

{% for item in cart.lineItems.orderBy(’sku desc') %} does not work…

1 Answer 1

3

I am posting the answer of Craft Commerce Support in case somebody stumbles over the same thing:

It is possible to order them differently if required. The code example below shows how to order them alphabetically by SKU.

{% set lineItems = cart.lineItems|sort((a,  b) => a.sku <=> b.sku)  %}
<ul>
    {% for item in lineItems %}
        <li>{{ item.description }} - [{{ item.sku }}]</li>
    {% endfor %}
</ul>

Thanks Nathaniel

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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