How to list different product types separately in order summary? I have two product types, 1) Materials and 2) Services.

Is there a way on the order summary page to list out the "materials" line items first, followed by the "services" line items below? I can't seem to figure out how to access the product type from cart.lineItems.

Here is what I'm currently using but it seems a little clunky:

&lt;h2&gt;Products&lt;/h2&gt;

{% for item in cart.lineItems %}
    {% set variant = item.purchasable %}
    {% set product = variant.product %}
    {% if product.type == 'materials' %}
        &lt;li&gt;{{ product.title }} - {{ variant.sku }} ({{ item.qty }})&lt;/li&gt;
    {% endif %}
{% endfor %}

&lt;h2&gt;Services&lt;/h2&gt;

{% for item in cart.lineItems %}
    {% set variant = item.purchasable %}
    {% set product = variant.product %}
    {% if product.type == 'services' %}
        &lt;li&gt;{{ product.title }} - {{ variant.sku }} ({{ item.qty }})&lt;/li&gt;
    {% endif %}
{% endfor %}
You'll need to query the Purchasable in order to sort by Type.

Hope this helps. Let me know if you find a better way.

&lt;h2&gt;Products&lt;/h2&gt;
{% for item in order.lineItems %}
    {% if item.purchasable.product.getType().name == 'Products' %}
        {% set variant = item.purchasable %}
        {% set product = variant.product %}
        &lt;li&gt;{{ product.title }} - ({{ item.qty }})&lt;/li&gt;
    {% endif %}
{% endfor %}


&lt;h2&gt;Services&lt;/h2&gt;
{% for item in order.lineItems %}
    {% if item.purchasable.product.getType().name == 'Services' %}
        {% set variant = item.purchasable %}
        {% set product = variant.product %}
        &lt;li&gt;{{ product.title }} - ({{ item.qty }})&lt;/li&gt;
    {% endif %}
{% endfor %}


&lt;h2&gt;Others&lt;/h2&gt;
{% for item in order.lineItems %}
    {% if item.purchasable.product.getType().name not in ['Products','Services'] %}
        {% set variant = item.purchasable %}
        {% set product = variant.product %}
        &lt;li&gt;{{ product.title }} - ({{ item.qty }})&lt;/li&gt;
    {% endif %}
{% endfor %}