Answers.Body: <p>I am a little confused with your twig code assigning so many variables.</p>
  
  <p>Put simply, only a <code>purchasableId</code> can be used to add something to the cart.</p>
  
  <p>If you know the product ID then it is as simple as:</p>
  
  <pre><code>{% set product = craft.commerce.products.id(6901}.first() %}
  
  {% if product %}
      &lt;form method="POST"&gt;
          &lt;input type="hidden" name="action" value="commerce/cart/updateCart"&gt;
          &lt;input type="hidden" name="redirect" value="commerce/cart"&gt;
          &lt;input type="hidden" name="qty" value="1"&gt;
          &lt;input type="hidden" name="purchasableId" value="{{ product.defaultVariant.purchasableId }}"&gt;
  
          &lt;button type="submit"&gt;BUY NOW {{ product.defaultPrice|commerceCurrency }}&lt;/button&gt;
      &lt;/form&gt;
  {% endif %}
  </code></pre>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2016-12-08T07:45:09.857Z
Answers.Text: Hi Luke and Brad, Thank you. That definitely helped.
Answers.UserDisplayName: Arren Vidal
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2016-12-08T02:34:28.780Z
Answers.LastActivityDate: 2016-12-08T04:11:34.997Z
Answers.LastEditDate: 2016-12-08T04:11:34.997Z
Answers.UserDisplayName: Luke Holder
Body: <p>I am trying to get the price and add to cart link for a product</p>
  
  <p>This is what I am testing at the moment, is it completely wrong?</p>
  
  <p>========== Setting Variables ===========</p>
  
  <pre><code>{% set giftDepositID = 6901 %}
  {% set giftDepositPrices = 0 %}
  
  {% if craft.commerce.products.id(giftDepositID)|length %}
      {% set giftDepositproduct = craft.commerce.products.id(giftDepositID).find() %}
      {% set giftDepositvariant = giftDepositproduct.defaultVariant %}
      {% set giftDepositpurchasableId = giftDepositvariant.purchasableId %}
      {% set giftDepositPrices = craft.childsown.getVariantPrice(giftDepositpurchasableId) %}
  {%endif%}
  </code></pre>
  
  <p>========== Example HTML ===========</p>
  
  <pre><code>            &lt;div class="col-xs-12 mobile-price-item"&gt;
                      &lt;div class="row"&gt;
                      &lt;div class="col-xs-12"&gt;
                          &lt;img src="{{baseUrl}}/assets/images/softie-robot.jpg" class="img-responsive"&gt;
                      &lt;/div&gt;
                  &lt;/div&gt;
                  &lt;div class="clearfix bg-gradient-yellow"&gt;
                      &lt;div class="col-xs-8"&gt;
                          &lt;h3 class="text-gloria"&gt;{{"Deposit"|t}}&lt;/h3&gt;
                      &lt;/div&gt;
                      &lt;div class="col-xs-4"&gt;
                          &lt;h1 class="text-white text-gloria"&gt;&lt;span class="initprice" data-usd="{{giftDepositPrices}}"&gt;${{giftDepositPrices}}&lt;/span&gt;&lt;/h1&gt;
                      &lt;/div&gt;
                  &lt;/div&gt;
                  &lt;div class="row"&gt;
                      &lt;div class="col-xs-12"&gt;
                          &lt;form method="POST"&gt;
                              &lt;input type="hidden" name="action" value="commerce/cart/updateCart"&gt;
                              &lt;input type="hidden" name="redirect" value="commerce/cart"&gt;
                              &lt;input type="hidden" name="qty" value="1"&gt;
                              &lt;input type="hidden" name="purchasableId" value="{{giftDepositpurchasableId}}"&gt;
                              &lt;button class="form-control btn btn-yellow text-white" type="submit" data-click=".softie-form .red .btn"&gt;{{"BUY NOW"|t}} &lt;i class="fa fa-play"&gt;&lt;/i&gt;&lt;/button&gt;
                          &lt;/form&gt;
                      &lt;/div&gt;
                  &lt;/div&gt;
              &lt;/div&gt;
  </code></pre>
  
  <p>Any help/guidance is appreciated.</p>
  
  <p>======= EDIT ========</p>
  
  <p>New Variable set, I have updated the following:</p>
  
  <pre><code>{% set giftDepositID = 6901 %}
  {% set giftDepositPrices = 0 %}
  {% set giftStandardID = 6899 %}
  {% set giftStandardPrices = 0 %}
  {% set giftLargeID = 6897 %}
  {% set giftLargePrices = 0 %}
  
  {% if craft.commerce.products.id(giftDepositID)|length %}
      {% set giftDepositproduct = craft.commerce.products.id(giftDepositID).find() %}
      {% set giftDepositvariant = giftDepositproduct.defaultVariant %}
      {% set giftDepositpurchasableId = giftDepositvariant.purchasableId %}
      {% set giftDepositPrices = giftDepositvariant.getVariantPrice(giftDepositpurchasableId) %}
  {%endif%}
  </code></pre>
  
  <p>This is the output of the HTML</p>
  
  <pre><code>&lt;div class="col-sm-4 pad-sm red"&gt;
  &lt;img src="https://childsown.com/assets/images/softie-alien.jpg" class="img-responsive"&gt;
  &lt;div class="block-container"&gt;
  &lt;h3 class="text-gloria"&gt;Deposit&lt;/h3&gt;
  &lt;div class="block"&gt;
  &lt;h1 class="text-white text-gloria"&gt;&lt;span class="initprice" data-usd=""&gt;$&lt;/span&gt;&lt;/h1&gt;
  &lt;/div&gt;
  &lt;/div&gt;
  &lt;form method="POST"&gt;
  &lt;input type="hidden" name="action" value="commerce/cart/updateCart"&gt;
  &lt;input type="hidden" name="redirect" value="commerce/cart"&gt;
  &lt;input type="hidden" name="qty" value="1"&gt;
  &lt;input type="hidden" name="purchasableId" value=""&gt;
  &lt;button class="form-control btn btn-red text-white" type="submit" data-click=".softie-form .red .btn"&gt;BUY NOW &lt;i class="fa fa-play"&gt;&lt;/i&gt;&lt;/button&gt;
  &lt;/form&gt;
  &lt;/div&gt;
  </code></pre>
  
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2016-12-06T07:04:30.153Z
Comments.Text: What is `craft.childsown.getVariantPrice`?
  
  Where are those hard coded IDs coming from? For example the `{% set giftDepositID = 6901 %}` Is that a product ID?
  
  Can you also post the HTML output after twig renders?
Comments.UserDisplayName: Luke Holder
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2016-12-06T07:32:02.440Z
Comments.Text: Yes, that is pulled in from what is already built into the site.
  I have updated the original post.
Comments.UserDisplayName: Arren Vidal
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2016-12-06T13:12:13.290Z
Comments.Text: I can see the purchasableId input in the html output has no value? my guess is you are getting a product/variant incorrectly, maybe the number is wrong?
Comments.UserDisplayName: Luke Holder
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2016-12-07T01:28:38.617Z
Comments.Text: Okay, thanks @LukeHolder.
  So, is this a way to get a product?
  
  `{% set giftDepositproduct = craft.commerce.products.id(giftDepositID).find() %}`
  Is this how to get a product variant for a product that does not have multiple variants?
  `{% set giftDepositvariant = giftDepositproduct.defaultVariant %}`
  
  Would this be how you get a purchasableID?
  `{% set giftDepositpurchasableId = giftDepositvariant.purchasableId %}`
  
  Then is this how you get the pricing of that variant?
  `{% set giftDepositPrices = giftDepositvariant.getVariantPrice(giftDepositpurchasableId) %}`
Comments.UserDisplayName: Arren Vidal
Tags: <plugin-craftcommerce>
Title: Getting Price and Add to Cart Button. Any thoughts on what I am doing wrong
ThreadText: # Getting Price and Add to Cart Button. Any thoughts on what I am doing wrong
  
  (Asked by: username_0 on 2016-12-06)
  
  I am trying to get the price and add to cart link for a product
  
  This is what I am testing at the moment, is it completely wrong?
  
  ========== Setting Variables ===========
  
  ```
  {% set giftDepositID = 6901 %}
  {% set giftDepositPrices = 0 %}
  
  {% if craft.commerce.products.id(giftDepositID)|length %}
      {% set giftDepositproduct = craft.commerce.products.id(giftDepositID).find() %}
      {% set giftDepositvariant = giftDepositproduct.defaultVariant %}
      {% set giftDepositpurchasableId = giftDepositvariant.purchasableId %}
      {% set giftDepositPrices = craft.childsown.getVariantPrice(giftDepositpurchasableId) %}
  {%endif%}
  
  ```
  
  ========== Example HTML ===========
  
  ```
              <div class="col-xs-12 mobile-price-item">
                      <div class="row">
                      <div class="col-xs-12">
                          <img src="{{baseUrl}}/assets/images/softie-robot.jpg" class="img-responsive">
                      </div>
                  </div>
                  <div class="clearfix bg-gradient-yellow">
                      <div class="col-xs-8">
                          <h3 class="text-gloria">{{"Deposit"|t}}</h3>
                      </div>
                      <div class="col-xs-4">
                          <h1 class="text-white text-gloria"><span class="initprice" data-usd="{{giftDepositPrices}}">${{giftDepositPrices}}</span></h1>
                      </div>
                  </div>
                  <div class="row">
                      <div class="col-xs-12">
                          <form method="POST">
                              <input type="hidden" name="action" value="commerce/cart/updateCart">
                              <input type="hidden" name="redirect" value="commerce/cart">
                              <input type="hidden" name="qty" value="1">
                              <input type="hidden" name="purchasableId" value="{{giftDepositpurchasableId}}">
                              <button class="form-control btn btn-yellow text-white" type="submit" data-click=".softie-form .red .btn">{{"BUY NOW"|t}} <i class="fa fa-play"></i></button>
                          </form>
                      </div>
                  </div>
              </div>
  
  ```
  
  Any help/guidance is appreciated.
  
  ======= EDIT ========
  
  New Variable set, I have updated the following:
  
  ```
  {% set giftDepositID = 6901 %}
  {% set giftDepositPrices = 0 %}
  {% set giftStandardID = 6899 %}
  {% set giftStandardPrices = 0 %}
  {% set giftLargeID = 6897 %}
  {% set giftLargePrices = 0 %}
  
  {% if craft.commerce.products.id(giftDepositID)|length %}
      {% set giftDepositproduct = craft.commerce.products.id(giftDepositID).find() %}
      {% set giftDepositvariant = giftDepositproduct.defaultVariant %}
      {% set giftDepositpurchasableId = giftDepositvariant.purchasableId %}
      {% set giftDepositPrices = giftDepositvariant.getVariantPrice(giftDepositpurchasableId) %}
  {%endif%}
  
  ```
  
  This is the output of the HTML
  
  ```
  <div class="col-sm-4 pad-sm red">
  <img src="https://childsown.com/assets/images/softie-alien.jpg" class="img-responsive">
  <div class="block-container">
  <h3 class="text-gloria">Deposit</h3>
  <div class="block">
  <h1 class="text-white text-gloria"><span class="initprice" data-usd="">$</span></h1>
  </div>
  </div>
  <form method="POST">
  <input type="hidden" name="action" value="commerce/cart/updateCart">
  <input type="hidden" name="redirect" value="commerce/cart">
  <input type="hidden" name="qty" value="1">
  <input type="hidden" name="purchasableId" value="">
  <button class="form-control btn btn-red text-white" type="submit" data-click=".softie-form .red .btn">BUY NOW <i class="fa fa-play"></i></button>
  </form>
  </div>
  
  ```
  
  **Tags:** plugin-craftcommerce
  
  > **Comments:**
  > **username_1**: What is `craft.childsown.getVariantPrice`?  Where are those hard coded IDs coming from? For example the `{% set giftDepositID = 6901 %}` Is that a product ID?  Can you also post the HTML output after twig renders?  
  > **username_0**: Yes, that is pulled in from what is already built into the site. I have updated the original post.  
  > **username_1**: I can see the purchasableId input in the html output has no value? my guess is you are getting a product/variant incorrectly, maybe the number is wrong?  
  > **username_0**: Okay, thanks @username_1. So, is this a way to get a product?  `{% set giftDepositproduct = craft.commerce.products.id(giftDepositID).find() %}` Is this how to get a product variant for a product that does not have multiple variants? `{% set giftDepositvariant = giftDepositproduct.defaultVariant %}`  Would this be how you get a purchasableID? `{% set giftDepositpurchasableId = giftDepositvariant.purchasableId %}`  Then is this how you get the pricing of that variant? `{% set giftDepositPrices = giftDepositvariant.getVariantPrice(giftDepositpurchasableId) %}`  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_1 on 2016-12-08. Score: 1 | Accepted answer
  
  I am a little confused with your twig code assigning so many variables.
  
  Put simply, only a `purchasableId` can be used to add something to the cart.
  
  If you know the product ID then it is as simple as:
  
  ```
  {% set product = craft.commerce.products.id(6901}.first() %}
  
  {% if product %}
      <form method="POST">
          <input type="hidden" name="action" value="commerce/cart/updateCart">
          <input type="hidden" name="redirect" value="commerce/cart">
          <input type="hidden" name="qty" value="1">
          <input type="hidden" name="purchasableId" value="{{ product.defaultVariant.purchasableId }}">
  
          <button type="submit">BUY NOW {{ product.defaultPrice|commerceCurrency }}</button>
      </form>
  {% endif %}
  
  ```
  
  > **Comments:**
  > **username_0**: Hi username_1 and Brad, Thank you. That definitely helped.  
  
  ---
  
  