1

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…

2

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

| improve this answer | |

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.