<p>I haven't tried Commerce myself but I think something like this should work:</p>

<pre><code>{% set products = craft.commerce.products.type(yourType) %}

//make an empty array
{% set filteredProducts = [] %}

{% for entry in products %}
    //check for your conditions
    {% if (entry.checkboxFieldhandle) or (entry.hasStock) %}
        //add each entry to your products array
        {% set filteredProducts = filteredProducts|merge([entry]) %}
    {% endif %}
{% endfor %}
</code></pre>

CC BY-SA 3.0
2017-01-27T22:33:38.550Z
merge works on arrays: `filteredProducts|merge([entry])` might work.
Marion Newlevant
CC BY-SA 3.0
2017-01-27T23:24:22.360Z
@MarionNewlevant you're right, edited
Jan_dh
CC BY-SA 3.0
2017-01-30T08:11:31.567Z
awesome thanks!
Branko
CC BY-SA 3.0
2017-01-27T16:47:34.120Z
2017-01-27T23:24:42.790Z
2017-01-27T23:24:42.790Z
Jan_dh
<p>I have lots of products and I want to filter them a certain way.
I want to retrieve all products that have stock = 1 or where product.myField = checked.</p>

<p>I don't know how to do this exactly. This is what I have for now</p>

<pre><code>{% for prod in craft.commerce.products({
    search: 'myField:0 or hasVariant:{hasStock:true}'   
}).type(myType).order(sort ~ ' ' ~ order).limit(35) %}
</code></pre>

<p>Thanks in advance!</p>

<templating><plugin-craftcommerce>
Loading specific products
# Loading specific products

(Asked by: username_0 on 2017-01-27)

I have lots of products and I want to filter them a certain way.
I want to retrieve all products that have stock = 1 or where product.myField = checked.
I don't know how to do this exactly. This is what I have for now
{% for prod in craft.commerce.products({
    search: 'myField:0 or hasVariant:{hasStock:true}'   
}).type(myType).order(sort ~ ' ' ~ order).limit(35) %}

Thanks in advance!

**Tags:** templating, plugin-craftcommerce

---

## 1 answers

### Answer by username_1 on 2017-01-27. Score: 2 | Accepted answer

I haven't tried Commerce myself but I think something like this should work:
{% set products = craft.commerce.products.type(yourType) %}

//make an empty array
{% set filteredProducts = [] %}

{% for entry in products %}
    //check for your conditions
    {% if (entry.checkboxFieldhandle) or (entry.hasStock) %}
        //add each entry to your products array
        {% set filteredProducts = filteredProducts|merge([entry]) %}
    {% endif %}
{% endfor %}

> **Comments:**
> **username_2**: merge works on arrays: `filteredProducts|merge([entry])` might work.  
> **username_1**: @MarionNewlevant you're right, edited  
> **username_0**: awesome thanks!  

---

