Difference between revisions of "Liquid Template Variables - variant"

From Spiffy Stores Knowledge Base

(New page: The liquid template variable ''variant'' has the following attributes: == <code>variant.id</code> == Returns the unique internal number of the variant. This is normally only for interna...)
 
Line 33: Line 33:
 
{% else %}
 
{% else %}
 
   Sold out!
 
   Sold out!
{% endif %}</prev>
+
{% endif %}</pre>
  
 
== <code>variant.inventory</code> ==
 
== <code>variant.inventory</code> ==

Revision as of 10:50, 13 September 2008

The liquid template variable variant has the following attributes:

variant.id

Returns the unique internal number of the variant.

This is normally only for internal usage.

variant.title

Returns the title of this variant. A variant title is usually a short value that distinguishes it from the other variants of the product. For example, it could be something like "S", "M" or "L" for clothes sizes or "red" or "green" for product colours.

variant.price

Returns the variant's price.

variant.compare_at_price

Returns the recommend retail price for this product variant. This may also be the price of the variant before being discounted or put on sale.

variant.available

Returns true if the variant is available and not sold out.

This value can be used to either hide variants that are not available for sale, or to mark them as "Sold Out".

Variants which are not available should not be placed in the shopping cart.

For example:

{% if variant.available == true %}
   We currently have {{ variant.inventory_quantity }} in stock.
{% else %}
   Sold out!
{% endif %}

variant.inventory

variant.inventory_quantity

Returns the number of this variant that are in stock. Note that this value will only be valid if variant.inventory is true.

variant.weight

Returns the weight of the variant. This will always be in grams. To display the value according to your store's weight system, use the weight_with_unit filter.

This product weights {{ product.variants.first.weight | weight_with_unit }}

variant.sku

Returns the variant's SKU.