<p>You're always using variants. Just that if you have no 'other' variants commerce hides that stuff away. But your product has a defaultVariant behind the scenes.</p>

<p>Adding…</p>

<pre><code>.hasVariant({ hasStock: true })
</code></pre>

<p>…to your query <em>should</em> (I think) return your products that have ([hidden] variants in) stock.</p>

CC BY-SA 4.0
2020-04-07T21:30:15.737Z
2020-04-07T21:30:15.737Z
billythekid
<p>In Craft Commerce, how can I show only products that are in stock when <strong>not using variants</strong>?</p>

<p>For example, this query, but only show products with a stock with 1 or more:</p>

<pre><code>{% set productQuery = craft.products()
        .relatedTo(block.relation)
        .availableForPurchase()
        .order('postDate desc')
        .limit(4) %}

    {% set products = productQuery.all() %}

    {% for product in products %}
      {% include "_components/product-blurb.html" %}
    {% endfor %}
</code></pre>

<plugin-craftcommerce>
Show only products in stock - one variant only
# Show only products in stock - one variant only

(Asked by: username_0 on 2020-04-07)

In Craft Commerce, how can I show only products that are in stock when not using variants?
For example, this query, but only show products with a stock with 1 or more:
{% set productQuery = craft.products()
        .relatedTo(block.relation)
        .availableForPurchase()
        .order('postDate desc')
        .limit(4) %}

    {% set products = productQuery.all() %}

    {% for product in products %}
      {% include "_components/product-blurb.html" %}
    {% endfor %}

**Tags:** plugin-craftcommerce


---

## 1 answers

### Answer by username_1 on 2020-04-07. Score: 2 | Accepted answer

You're always using variants. Just that if you have no 'other' variants commerce hides that stuff away. But your product has a defaultVariant behind the scenes.
Adding…
.hasVariant({ hasStock: true })

…to your query should (I think) return your products that have ([hidden] variants in) stock.


---

