Answers.Body: <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>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2016-06-27T10:18:43.723Z
Answers.LastActivityDate: 2021-09-10T16:41:53.127Z
Answers.LastEditDate: 2021-09-10T16:41:53.127Z
Answers.UserDisplayName: Luke Pearce
Body: <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>
  
Tags: <plugin-craftcommerce>
Title: Craft Commerce: Variable "product" does not exist
ThreadText: # 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 %}
  
      <option {% if purchasable.stock <= 0 and purchasable.unlimitedStock == false %}disabled {% endif %} value="{{ purchasable.purchasableId }}">{{ purchasable.description }} {{ purchasable.price|currency(cart.currency) }}</option>
  
  {% 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:
  
  [![Craft Commerce Product Type edit screen](https://i.sstatic.net/W98hW.png)](https://i.sstatic.net/W98hW.png)
  
  If you want to display your product elsewhere on your site you will need to set it to a variable, using a [Product Query](https://craftcms.com/docs/commerce/3.x/products-variants.html#querying-products):
  
  ```
  {% 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 }}:
  
  <select name="purchasableIds[]">
      {% for purchasable in myProduct.getVariants() %}
          <option
              {% if not purchasable.getIsAvailable() %}disabled{% endif %}
              value="{{ purchasable.purchasableId }}">
              {{ purchasable.description }}
              {{ purchasable.price | currency(cart.paymentCurrency) }}
          </option>
      {% endfor %}
  </select>
  
  ```
  
  See the Commerce Documentation for more information about [adding products to the cart](https://craftcms.com/docs/commerce/3.x/orders-carts.html#adding-items-to-a-cart)!
  
  
  ---
  
  