Dot All Lisbon – the official Craft CMS conference – is happening September 23 - 25.
craft.commerce.variants
Usually you will only want to retrieve products, giving you access to their variants. Sometimes you might want to query for variants directly.
You can access your site’s variants from your templates via craft.commerce.variants
It returns an ElementCriteriaModel object.
{% set variants = craft.commerce.variants.id(8376).first() %}
{{ variant.sku }} - {{ variant.salePrice }}
Parameters
craft.commerce.variants
supports the following parameters:
id
The variant’s element ID.
productId
The product ID this variant belongs to.
sku
The variant’s SKU
default
Whether the variant is the product’s default variant
Accepts: boolean (true
or false
)
stock
The stock amount
Accepts: integer
hasStock
Whether the variant has unlimited stock or stock greater than zero.
Accepts: boolean (true
or false
)