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…
Craft CMS Stack Exchange is a question and answer site for administrators, end users, developers and designers for Craft CMS. It only takes a minute to sign up.
Sign up to join this communityI 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