<p><code>product</code> will only be available by default if you're viewing the template set in the CP under that Product Type’s settings, and it's set up with a URL format:</p>
<p><a href="https://i.sstatic.net/W98hW.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/W98hW.png" alt="Craft Commerce Product Type edit screen" /></a></p>
<p>If you want to display your product elsewhere on your site you will need to set it to a variable, using a <a href="https://craftcms.com/docs/commerce/3.x/products-variants.html#querying-products" rel="nofollow noreferrer">Product Query</a>:</p>
<pre><code>{% set myProduct = craft.products.one() %}
</code></pre>
<p>…you can then loop through this Product's Variants (or just use <code>myProduct.getDefaultVariant()</code> if it only has one):</p>
<pre><code>{# This example is part of an &quot;add-to-cart&quot; form! #}

Configure your {{ myProduct.title }}:

&lt;select name=&quot;purchasableIds[]&quot;&gt;
    {% for purchasable in myProduct.getVariants() %}
        &lt;option
            {% if not purchasable.getIsAvailable() %}disabled{% endif %}
            value=&quot;{{ purchasable.purchasableId }}&quot;&gt;
            {{ purchasable.description }}
            {{ purchasable.price | currency(cart.paymentCurrency) }}
        &lt;/option&gt;
    {% endfor %}
&lt;/select&gt;
</code></pre>
<p>See the Commerce Documentation for more information about <a href="https://craftcms.com/docs/commerce/3.x/orders-carts.html#adding-items-to-a-cart" rel="nofollow noreferrer">adding products to the cart</a>!</p>

CC BY-SA 4.0
2016-06-27T10:18:43.723Z
2021-09-10T16:41:53.127Z
2021-09-10T16:41:53.127Z
Luke Pearce
<p>My shop has one product. As such there isn't much point in me having a page displaying all products.</p>

<p>When I paste in my template code for my single product into Cart Commerce's main index template I get the error <strong><em>Variable "product" does not exist</em></strong> on the following code:</p>

<pre><code>{% for purchasable in product.variants %}

    &lt;option {% if purchasable.stock &lt;= 0 and purchasable.unlimitedStock == false %}disabled {% endif %} value="{{ purchasable.purchasableId }}"&gt;{{ purchasable.description }} {{ purchasable.price|currency(cart.currency) }}&lt;/option&gt;

{% endfor %}
</code></pre>

<p>Why is this being thrown up and how do I remedy this?</p>

<plugin-craftcommerce>
Craft Commerce: Variable "product" does not exist
# Craft Commerce: Variable "product" does not exist

(Asked by: username_0 on 2016-06-27)

My shop has one product. As such there isn't much point in me having a page displaying all products.
When I paste in my template code for my single product into Cart Commerce's main index template I get the error Variable "product" does not exist on the following code:
{% for purchasable in product.variants %}

    {{ purchasable.description }} {{ purchasable.price|currency(cart.currency) }}

{% endfor %}

Why is this being thrown up and how do I remedy this?

**Tags:** plugin-craftcommerce

---

## 1 answers

### Answer by username_1 on 2016-06-27. Score: 1 | Accepted answer

product will only be available by default if you're viewing the template set in the CP under that Product Type’s settings, and it's set up with a URL format:

If you want to display your product elsewhere on your site you will need to set it to a variable, using a Product Query:
{% set myProduct = craft.products.one() %}

…you can then loop through this Product's Variants (or just use myProduct.getDefaultVariant() if it only has one):
{# This example is part of an "add-to-cart" form! #}

Configure your {{ myProduct.title }}:


    {% for purchasable in myProduct.getVariants() %}
        
            {{ purchasable.description }}
            {{ purchasable.price | currency(cart.paymentCurrency) }}
        
    {% endfor %}


See the Commerce Documentation for more information about adding products to the cart!


---

