Skip to content

Latest commit

 

History

History
96 lines (48 loc) · 1.9 KB

variant-model.md

File metadata and controls

96 lines (48 loc) · 1.9 KB

Variant Model

Variants are Craft Elements and also Purchasables.

VariantModel's 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.

hasUnlimitedStock

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 quanity orderable for this variant (in a single cart/order)

minQty

The minimum quanity orderable 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 in the CP product edit screen.

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.