Variant

From Shopify Wiki

Jump to: navigation, search

Variants represent the variants of a product. You can usually access a variant using code like product.variants.

Following attributes are available:

Contents

variant.id

Returns the id of this variant

variant.title

Returns the title of this variant. A variant title is usually a short value that distincts it from the other variants of its original product. For example, it can be anything like "S", "M", "L" for clothes or "158cm", "160cm" for snowboards.

variant.price

Returns the variant's price, that this store is selling this for.

variant.compare_at_price

Returns the recommend retail price for this product variant.

variant.available

Can either be 'true' or 'false' and determines whether this variant is available or not (=sold out). Depending on your preferences you should either hide variants that are not for sale anymore OR mark them as sold out. If the value is "false" this item mustn't be placed in the shopping cart.

Example:

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

variant.inventory_quantity

Returns how many of this variants are in stock for this shop. Note, that this value will only be accurate if variant.inventory is true.

variant.weight

Returns the weight of the variant. This will always be in metric gram. For displaying it according to your weight system (metric/imperial) please run the variable through the weight_with_unit filter.

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

variant.sku

Returns the varian't sku.

Personal tools