The variant object has the following attributes:
variant.available
Returns true if the variant is available for purchase, false if not.
A variant is available if variant.inventory_quantity is greater than zero or variant.inventory_policy is set to continue. A variant without variant.inventory_management also counts as available.
variant.barcode
Returns the barcode of the variant.
variant.compareatprice
Returns the variant's compare-at price.
Use a money filter to return the value in a money format.
variant.featured_media
Returns the first media item attached to the variant.
variant.id
Returns the unique ID of the variant.
variant.image
Returns the image object attached to the variant.
{{ variant.image.src }}
/products/red-shirt.jpeg
variant.incoming
Returns true if the variant has incoming stock.
variant.inventory_management
Returns the inventory tracking service of the variant.
variant.inventory_policy
Returns whether the variant can be sold when it is out of stock. Possible values:
continue: keep selling when the variant is out of stock.deny: stop selling when the variant is out of stock.
variant.inventory_quantity
Returns the inventory quantity of the variant.
variant.matched
Returns whether the variant was matched by a storefront filter: true if it matches, false if not.
variant.nextincomingdate
Returns the date when the next incoming stock arrives.
variant.options
Returns an array of the variant's product option values.
{% for option in variant.options %}
- {{ option }}
{% endfor %}
- Red
- Small
- Wool
variant.option1
Returns the value of the variant's first product option.
variant.option2
Returns the value of the variant's second product option.
variant.option3
Returns the value of the variant's third product option.
variant.price
Returns the price of the variant. Use a money filter to return the value in a money format.
variant.product
Returns the parent product object.
variant.requires_shipping
Returns true if the variant requires shipping.
variant.requiressellingplan
Returns true if the variant requires a selling plan when it is added to the cart. VersaCommerce currently has no selling plans, so this is false.
variant.selected
Returns true if the variant is currently selected. The selected variant is based on the variant URL parameter.
variant.selectedsellingplan_allocation
Returns a selling_plan_allocation object based on the selling_plan URL parameter. VersaCommerce currently has no selling plans, so this returns nil.
variant.sellingplanallocations
An array of selling_plan_allocation objects available for the variant. VersaCommerce currently has no selling plans, so this array is empty.
variant.sku
Returns the SKU of the variant.
variant.store_availabilities
Returns an array of store_availability objects in these cases:
- variant.selected is
true - The variant is the product's first available variant, for example
product.first_available_variantorproduct.selected_or_first_available_variant.
variant.taxable
Returns true if taxes are charged for the variant, false if not.
variant.title
Returns all product option values of the variant, joined by /.
<!-- If the variant's option1, option2 and option3 are "Red", "Small", "Wool" -->
{{ variant.title }}
Red / Small / Wool
variant.unit_price
Returns the unit price of the product variant. The price reflects any discounts applied to the line item.
variant.unitpricemeasurement
Returns a unitpricemeasurement object for the product variant.
variant.url
Returns a URL that is unique to a single product variant. The variant ID is used as the unique identifier.
{{ variant.url }}
/products/t-shirt?variant=12345678
variant.weight
Returns the weight of the variant in grams. Use the weightwithunit filter to convert it to your shop's weight format or the weight unit configured for the variant.
variant.weight_unit
Returns the weight unit configured for the variant. Works well with the weight_in_unit attribute and the weightwithunit filter.
variant.weightinunit
Returns the product weight converted to the unit configured for the variant. Works well with the weight_unit attribute and the weightwithunit filter.
More properties
VersaCommerce also provides these properties on the variant object:
| Properties | Returns |
|---|---|
quantity_rule, selected_option_value_ids |
Quantity rules and resolved option value IDs |