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>
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? – Luke Holder Dec 6 '16 at 7:04{% 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) %}
– Arren Vidal Dec 7 '16 at 1:28