<p>You're close. Products themselves aren't <a href="https://docs.craftcms.com/commerce/v3/products.html#purchasables" rel="nofollow noreferrer">Purchasebles</a>. </p>

<p>However, <a href="https://docs.craftcms.com/commerce/v3/products.html#variants" rel="nofollow noreferrer">Variants</a> of products are. And you can have more than one Variant of a Product.</p>

<p>So, we need to get all Variants of a particular Product type and then feed your query:</p>

<pre><code>{# get products of a certain type #}
{% set productIds = craft.products.type('classes').ids() %}

{# get the variants from those product Ids #}
{% set theVariants = craft.variants.productId(productIds).all() %}

{# grab orders #}
{% set orders = craft.orders.completed(true).hasPurchasables(theVariants).limit(null).all() %}
</code></pre>

<p>You'll probably want to <code>limit</code> the orders returned at some point depending on how you're displaying or querying them.</p>

CC BY-SA 4.0
2020-05-26T12:17:21.670Z
It works. But I just noticed that if a customer has two items of `product.type` ordered. Then the order is shown twice.
KSPR
CC BY-SA 4.0
2020-05-26T12:18:40.180Z
I tried to query the thing with `.unique()`. No luck so far
KSPR
CC BY-SA 4.0
2020-05-15T00:08:56.537Z
2020-05-15T00:08:56.537Z
RitterKnight
<p>In want to print a list of orders:</p>

<pre><code>{% set orders = craft.orders.completed(true).limit(null).all() %}
</code></pre>

<p>Now I want to make a list of orders with only the <strong>product.type</strong> <code>XYZ</code>.</p>

<p>I tried to fabricate something out of this <a href="https://craftcms.stackexchange.com/questions/15284/list-only-orders-containing-specific-products">question</a>. But I'd like specific product types:</p>

<pre><code>{% set orders = craft.orders.completed(true).hasPurchasables([type.XYZ]).limit(null).all() %}
</code></pre>

<p>This returns:</p>

<blockquote>
  <p>Variable "type" does not exist.</p>
</blockquote>

<p>How do I have to write this?</p>

<templating><plugin-craftcommerce>
Get all orders which contains a certain product type
# Get all orders which contains a certain product type

(Asked by: username_0 on 2020-05-12)

In want to print a list of orders:
{% set orders = craft.orders.completed(true).limit(null).all() %}

Now I want to make a list of orders with only the product.type XYZ.
I tried to fabricate something out of this question. But I'd like specific product types:
{% set orders = craft.orders.completed(true).hasPurchasables([type.XYZ]).limit(null).all() %}

This returns:

Variable "type" does not exist.

How do I have to write this?

**Tags:** templating, plugin-craftcommerce

---

## 1 answers

### Answer by username_1 on 2020-05-15. Score: 1 | Accepted answer

You're close. Products themselves aren't Purchasebles. 
However, Variants of products are. And you can have more than one Variant of a Product.
So, we need to get all Variants of a particular Product type and then feed your query:
{# get products of a certain type #}
{% set productIds = craft.products.type('classes').ids() %}

{# get the variants from those product Ids #}
{% set theVariants = craft.variants.productId(productIds).all() %}

{# grab orders #}
{% set orders = craft.orders.completed(true).hasPurchasables(theVariants).limit(null).all() %}

You'll probably want to limit the orders returned at some point depending on how you're displaying or querying them.

> **Comments:**
> **username_0**: It works. But I just noticed that if a customer has two items of `product.type` ordered. Then the order is shown twice.  
> **username_0**: I tried to query the thing with `.unique()`. No luck so far  

---

