Liquid Template Variables - product
From Spiffy Stores Knowledge Base
The Liquid template variable product has the following attributes:
Contents
- 1 product.id
- 2 product.handle
- 3 product.title
- 4 product.created_at
- 5 product.published
- 6 product.published_at
- 7 product.type
- 8 product.category
- 9 product.vendor
- 10 product.price
- 11 product.price_min
- 12 product.price_max
- 13 product.price_varies
- 14 product.compare_at_price
- 15 product.compare_at_price_min
- 16 product.compare_at_price_max
- 17 product.compare_at_price_varies
- 18 product.featured
- 19 product.featured_image
- 20 product.images
- 21 product.images_count
- 22 product.image_type
- 23 product.description
- 24 product.content
- 25 product.variants
- 26 product.variants_count
- 27 product.base_variants
- 28 product.base_variants_count
- 29 product.available
- 30 product.bundle
- 31 product.bundled_products
- 32 product.bundle_products
- 33 product.collections
- 34 product.collection_handles
- 35 product.all_collections
- 36 product.all_collection_handles
- 37 product.standard_collections
- 38 product.standard_collection_handles
- 39 product.all_standard_collections
- 40 product.all_standard_collection_handles
- 41 product.super_collections
- 42 product.super_collection_handles
- 43 product.all_super_collections
- 44 product.all_super_collection_handles
- 45 product.discount_collections
- 46 product.discount_collection_handles
- 47 product.tags
- 48 product.url
- 49 product.sku
- 50 product.barcode
- 51 product.options
- 52 product.option_values
- 53 product.option_values_available
- 54 product.metafields
- 55 product.first_available_variant
- 56 product.selected_variant
- 57 product.selected_or_first_available_variant
- 58 product.option_set_fields
- 59 Further Reference
product.id
Returns the unique internal number of the product.
This is normally only for internal usage.
product.handle
This is the product handle. The handle uniquely identifies the product in the URL address.
The handle is usually the product's title in lower case with all blanks replaced by a dash. "Red Hat" would have the handle "red-hat".
product.title
Returns the title of this product.
product.created_at
Returns the timestamp for when the product was created.
product.published
Returns true if the product is published.
product.published_at
Returns the timestamp for when the product was published.
product.type
Returns the type of this product, for example, "T-Shirt" or "Garden Gnome".
product.category
Returns the standardized category for this product, if it has been assigned. For example, "Home & Garden > Decor > Lawn Ornaments & Garden Sculptures > Garden Gnome".
product.vendor
Returns the vendor of this product, such as "Spiffy Stores" or "Acme Tools".
product.price
Returns the price for this product. By default this is the minimum price.
product.price_min
Returns the minimum price for this product.
product.price_max
Returns the minimum price for this product.
product.price_varies
Returns true if the price_min is different from price_max.
product.compare_at_price
Returns the "compare at" price, that is, the recommended retail price for this product. By default this is the minimum "compare at" price.
product.compare_at_price_min
Returns the "compare at" price, that is, the recommended retail price for the least expensive variant of this product.
product.compare_at_price_max
Returns the "compare at" price, that is, the recommended retail price for the most expensive variant of this product
product.compare_at_price_varies
Returns true if the compare_at_price_min is different from compare_at_price_max.
product.featured
Return true if the product is featured.
product.featured_image
Returns the featured_image as an image template variable.
When used directly, such as product.featured_image, it returns the relative URL path of the featured image. This is equivalent to using product.featured_image.src.
For example,
<div> <img src="{{ product.featured_image | product_img_url: 'medium' }}" alt="{{ product.featured_image.alt | escape }}" /> </div>
product.images
Returns an array of all the image template variables for this product.
For example,
{% for image in product.images %} {{ image | product_img_url: 'medium' }} {% endfor %}
When used directly, such as image, it returns the relative URL path of the image. This is equivalent to using image.src.
product.images_count
Returns the number of images for this product.
product.image_type
Returns the type of images, in this case 'Product'
.
product.description
Returns the description of this product.
product.content
This is an alias of description.
product.variants
Returns a collection of all of this product's variants. This collection includes all "virtual" variants that are created by custom options, and should be used to generate the selection drop down list.
product.variants_count
Returns the number of variants for this product, including all "virtual" variants created by custom options.
product.base_variants
Returns a collection of all of this product's base variants.
product.base_variants_count
Returns the number of base variants for this product.
product.available
Returns false if all variants' quantities are zero and their policies are set to "stop selling when sold out".
product.bundle
Returns true if this product is a Product Bundle.
product.bundled_products
Returns an array of all the products that are included in this Product Bundle.
For example,
{% for bundled_product in product.bundled_products %} <h2>{{ bundled_product.title }}</h2> {% endfor %}
product.bundle_products
Returns an array of all the Product Bundles that this product belongs to.
For example,
{% for bundle_product in product.bundle_products %} <h2>{{ bundle_product.title }}</h2> {% endfor %}
product.collections
Returns an array of all published collections that this product belongs to.
<h1>Published collections</h1> <ul> {% for collection in product.collections %} <li>{{ collection.title }}</li> {% endfor %} </ul>
product.collection_handles
Returns an array of handles for all published collections that this product belongs to.
<h1>Published collection handles</h1> <ul> {% for collection_handle in product.collection_handles %} <li>{{ collection_handle }}</li> {% endfor %} </ul>
product.all_collections
Returns an array of all collections that this product belongs to, and includes unpublished collections as well as published collections.
The attribute collection.published can be used to test if a collection has been published.
<h1>Hidden collections</h1> <ul> {% for collection in product.all_collections %} {% unless collection.published %> <li>{{ collection.title }}</li> {% endunless %} {% endfor %} </ul>
product.all_collection_handles
Returns an array of handles for all collections that this product belongs to, and includes unpublished collections as well as published collections.
<h1>Collection handles</h1> <ul> {% for collection_handle in product.all_collection_handles %} <li>{{ collection_handle }}</li> {% endfor %} </ul>
product.standard_collections
Returns an array of all published Standard collections that this product belongs to.
<h1>Published standard collections</h1> <ul> {% for collection in product.standard_collections %} <li>{{ collection.title }}</li> {% endfor %} </ul>
product.standard_collection_handles
Returns an array of handles for all published Standard collections that this product belongs to.
<h1>Published standard collection handles</h1> <ul> {% for collection_handle in product.standard_collection_handles %} <li>{{ collection_handle }}</li> {% endfor %} </ul>
product.all_standard_collections
Returns an array of all Standard collections that this product belongs to, and includes unpublished collections as well as published collections.
The attribute collection.published can be used to test if a collection has been published.
<h1>Hidden standard collections</h1> <ul> {% for collection in product.all_standard_collections %} {% unless collection.published %> <li>{{ collection.title }}</li> {% endunless %} {% endfor %} </ul>
product.all_standard_collection_handles
Returns an array of handles for all Standard collections that this product belongs to, and includes unpublished collections as well as published collections.
<h1>Standard collection handles</h1> <ul> {% for collection_handle in product.all_standard_collection_handles %} <li>{{ collection_handle }}</li> {% endfor %} </ul>
product.super_collections
Returns an array of all published Super collections that this product belongs to.
<h1>Published super collections</h1> <ul> {% for collection in product.super_collections %} <li>{{ collection.title }}</li> {% endfor %} </ul>
product.super_collection_handles
Returns an array of handles for all published Super collections that this product belongs to.
<h1>Published super collection handles</h1> <ul> {% for collection_handle in product.super_collection_handles %} <li>{{ collection_handle }}</li> {% endfor %} </ul>
product.all_super_collections
Returns an array of all Super collections that this product belongs to, and includes unpublished collections as well as published collections.
The attribute collection.published can be used to test if a collection has been published.
<h1>Hidden super collections</h1> <ul> {% for collection in product.all_super_collections %} {% unless collection.published %> <li>{{ collection.title }}</li> {% endunless %} {% endfor %} </ul>
product.all_super_collection_handles
Returns an array of handles for all Super collections that this product belongs to, and includes unpublished collections as well as published collections.
<h1>Super collection handles</h1> <ul> {% for collection_handle in product.all_super_collection_handles %} <li>{{ collection_handle }}</li> {% endfor %} </ul>
product.discount_collections
Returns an array of all Discount collections that this product belongs to.
A Discount collection is one that is part of an eligible shopping cart discount. For example, if a Shopping Cart discount offers a free gift from the "Free Gift" collection if the customer purchases items worth $150 or more, then when items to the value of $150 are in the cart, all products that belong to the "Free Gift" collection will return the "Free Gift" collection when the discount_collections method is called.
<h1>Discount collections</h1> <ul> {% for collection in product.discount_collections %} <li>{{ collection.title }}</li> {% endfor %} </ul>
product.discount_collection_handles
Returns an array of handles for all Discount collections that this product belongs to.
A Discount collection is one that is part of an eligible shopping cart discount. For example, if a Shopping Cart discount offers a free gift from the "Free Gift" collection if the customer purchases items worth $150 or more, then when items to the value of $150 are in the cart, all products that belong to the "Free Gift" collection will return the "Free Gift" collection when the discount_collections method is called.
<h1>Discount collection handles</h1> <ul> {% for collection_handle in product.discount_collection_handles %} <li>{{ collection_handle }}</li> {% endfor %} </ul>
product.tags
Returns a list of the product's tags (represented by simple strings).
product.url
The is the relative URL address of the product.
<a href="{{ product.url }}"> <img src="{{ product.featured_image | product_img_url: 'small' }}" /> </a>
product.sku
Returns the product's SKU from the list of available variant SKUs.
product.barcode
Returns the product's barcode from the list of available variant barcodes.
product.options
Returns an array of the product's option titles. This will always be an array of option names, and there is always at least one option. By default, if no options have been defined, the first option will be called 'Title' and this is the name of the product variation.
The number of options can be used to select whether to use multiple option drop-downs in a product page.
{% if product.options.size > 1 %} <!-- The product has more than one option … Display using drop-downs --> {% else %} <!-- The product has only one option … Display using radio buttons --> {% endif %}
product.option_values
Returns an array of all unique option values for each of the product's options.
The result is an array of arrays.
<ul> {% for option in product.option_values %} <ul> {% for option_value in option %} <li>{{ option_value }}</li> {% endfor %} </ul> {% endfor %} </ul>
product.option_values_available
Returns an array of all unique option values for each of the product's options, but only includes the options if the variation is available for sale. This means that only variations are included if they don't have any inventory tracking, or they have inventory tracking and allow backorders or have items in stock.
The result is an array of arrays.
<ul> {% for option in product.option_values_available %} <ul> {% for option_value in option %} <li>{{ option_value }}</li> {% endfor %} </ul> {% endfor %} </ul>
product.metafields
Return the metafields for the product.
Metafields can only be managed using the Spiffy Stores API.
product.first_available_variant
Return the first variant of the product that is available for purchase. In order for a variant to be available, its inventory quantity must be greater than zero or the inventory policy must be set to continue. A variant without inventory management is always considered available.
product.selected_variant
Return the currently selected variant of the product. A variant is considered selected if there is a valid ?variant=... parameter in the product URL. Return nil if no variant is selected.
<!-- URL = mystore.spiffystores.com/products/cute-dog?variant=987654321 --> {{ product.selected_variant.id }} => 987654321
product.selected_or_first_available_variant
Return the currently selected variant of the product. A variant is considered selected if there is a valid ?variant=... parameter in the product URL.
If a variant is not currently selected, then return the first available variant. In order for a variant to be available, its inventory quantity must be greater than zero or the inventory policy must be set to continue. A variant without inventory management is always considered available.
product.option_set_fields
Returns an array of option set fields that are currently available for the product.
The result is an array of OptionSetField drops.
<ul> {% for option_set_field in product.option_set_fields %} <ul> <li>Field Label: {{ option_set_field.product_label }}</li> <li>Field Type: {{ option_set_field.field_type }}</li> <li>Option Set Name: {{ option_set_field.option_set }}</li> </ul> {% endfor %} </ul>