Answers.Body: <p>You'll need to query the <a href="https://craftcommerce.com/docs/purchasables" rel="nofollow noreferrer">Purchasable</a> in order to sort by Type.</p>
  
  <p>Hope this helps. Let me know if you find a better way.</p>
  
  <pre><code>&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 %}
  </code></pre>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2017-04-18T20:30:16.777Z
Answers.Text: Is there any way to set the particular type of product from the start when querying line items? e.g.
  
          `{% set items = order.lineItems.type('services') %}`
  
  Obviously that doesn't work, but something along those lines so that I don't have to loop through everything to find what I need?
Answers.UserDisplayName: Matt Everson
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2017-04-18T23:51:17.007Z
Answers.Text: I think a better approach here might be to, at the top, loop through the order lineItems once and build arrays of each of the result types in one go.  Then below print out those arrays.  Would reduce the queries and thus exec time, anyway.
  
  (I don't believe you can query by lineItem type currently but I might be wrong)
Answers.UserDisplayName: Jeremy Daalder
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2017-04-18T17:14:26.893Z
Answers.LastActivityDate: 2017-04-18T17:14:26.893Z
Answers.UserDisplayName: casey
Answers.Body: <p>I actually needed to do this today for similar reasons.</p>
  
  <p>Here's a plugin that reduces it to a single loop.</p>
  
  <p><a href="https://github.com/simplethemes/sortcart" rel="nofollow noreferrer">https://github.com/simplethemes/sortcart</a></p>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2017-04-20T00:39:45.670Z
Answers.LastActivityDate: 2017-04-20T00:39:45.670Z
Answers.UserDisplayName: casey
Body: <p>I have two product types, 1) Materials and 2) Services.</p>
  
  <p>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 <code>cart.lineItems</code>.</p>
  
  <p>Here is what I'm currently using but it seems a little clunky:</p>
  
  <pre><code>&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 %}
  </code></pre>
  
Tags: <plugin-craftcommerce>
Title: How to list different product types separately in order summary?
ThreadText: # How to list different product types separately in order summary?
  
  (Asked by: username_0 on 2017-04-18)
  
  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:
  
  ```
  <h2>Products</h2>
  
  {% for item in cart.lineItems %}
      {% set variant = item.purchasable %}
      {% set product = variant.product %}
      {% if product.type == 'materials' %}
          <li>{{ product.title }} - {{ variant.sku }} ({{ item.qty }})</li>
      {% endif %}
  {% endfor %}
  
  <h2>Services</h2>
  
  {% for item in cart.lineItems %}
      {% set variant = item.purchasable %}
      {% set product = variant.product %}
      {% if product.type == 'services' %}
          <li>{{ product.title }} - {{ variant.sku }} ({{ item.qty }})</li>
      {% endif %}
  {% endfor %}
  
  ```
  
  **Tags:** plugin-craftcommerce
  
  
  ---
  
  ## 2 answers
  
  ### Answer by username_1 on 2017-04-18. Score: 4
  
  You'll need to query the [Purchasable](https://craftcommerce.com/docs/purchasables) in order to sort by Type.
  
  Hope this helps. Let me know if you find a better way.
  
  ```
  <h2>Products</h2>
  {% for item in order.lineItems %}
      {% if item.purchasable.product.getType().name == 'Products' %}
          {% set variant = item.purchasable %}
          {% set product = variant.product %}
          <li>{{ product.title }} - ({{ item.qty }})</li>
      {% endif %}
  {% endfor %}
  
  <h2>Services</h2>
  {% for item in order.lineItems %}
      {% if item.purchasable.product.getType().name == 'Services' %}
          {% set variant = item.purchasable %}
          {% set product = variant.product %}
          <li>{{ product.title }} - ({{ item.qty }})</li>
      {% endif %}
  {% endfor %}
  
  <h2>Others</h2>
  {% for item in order.lineItems %}
      {% if item.purchasable.product.getType().name not in ['Products','Services'] %}
          {% set variant = item.purchasable %}
          {% set product = variant.product %}
          <li>{{ product.title }} - ({{ item.qty }})</li>
      {% endif %}
  {% endfor %}
  
  ```
  
  > **Comments:**
  > **username_0**: Is there any way to set the particular type of product from the start when querying line items? e.g.          `{% set items = order.lineItems.type('services') %}`  Obviously that doesn't work, but something along those lines so that I don't have to loop through everything to find what I need?  
  > **username_2**: I think a better approach here might be to, at the top, loop through the order lineItems once and build arrays of each of the result types in one go.  Then below print out those arrays.  Would reduce the queries and thus exec time, anyway.  (I don't believe you can query by lineItem type currently but I might be wrong)  
  
  ---
  
  ### Answer by username_1 on 2017-04-20. Score: 2
  
  I actually needed to do this today for similar reasons.
  
  Here's a plugin that reduces it to a single loop.
  
  <https://github.com/simplethemes/sortcart>
  
  
  ---
  
  