Variant Model
Variants are Craft Elements and also purchasables.
VariantModel objects have the following attributes and methods:
# Attributes
# title
The variants title as generated by the title formatter on the product type definition.
# id
The ID of the variant in the system.
# purchasableId
Returns this variant’s ID - as variants are purchasables.
# product
Returns this variant’s Product model
# price
The listing price of the variant.
# salePrice
The price of the variant after sales have been applied. Will be equal to price if no sales were applicable.
# sku
The SKU of the variant.
# isDefault
Returns true
or false
if this variant is the default variant of a product.
# hasStock
Returns true
or false
if the variant has unlimited stock or a stock count greater than zero.
# unlimitedStock
Returns true
or false
if this variant has unlimited stock
# stock
Returns the stock count on hand, or zero if unlimitedStock is true.
# maxQty
The maximum quantity that can be ordered at once for this variant (in a single cart/order)
# minQty
The minimum quantity that can be ordered at once for this variant (in a single cart/order)
# weight
The variants weight
# height
The variants height
# length
The variants length
# width
The variants width
# cpEditUrl
The URL to edit this variant’s edit page in the Control Panel.
# sortOrder
Returns the order number of the variant as defined on the Edit Product page.
# onSale
Returns true
or false
when any sales are applied to this variant. This is just a helper to test if there is a saleAmount
not equal to zero.
# salesApplied
Returns an array of sales that have been applied, allowing you to access the description of the sale with {{ variant.salesApplied[0].description }}
# description
The description of the purchasable which is the result of the product type’s “Order Description Format” option.