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

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

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

<p>Thanks Nathaniel</p>

CC BY-SA 4.0
2019-11-20T12:11:46.380Z
2019-11-20T12:11:46.380Z
outline4
<p>As of Commerce 2.2 line items are ordered by date created.</p>

<p>How can you order line items differently? </p>

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

<plugin-craftcommerce2><ecommerce>
Craft Commerce > 2.2: How can you order line items?
# Craft Commerce > 2.2: How can you order line items?

(Asked by: username_0 on 2019-11-20)

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…

**Tags:** plugin-craftcommerce2, ecommerce


---

## 1 answers

### Answer by username_0 on 2019-11-20. Score: 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)  %}

    {% for item in lineItems %}
        {{ item.description }} - [{{ item.sku }}]
    {% endfor %}


Thanks Nathaniel


---

