product
The product
object has the following attributes:
In this article
- product.available
- product.collections
- product.compare_at_price_max
- product.compare_at_price_min
- product.compare_at_price_varies
- product.content
- product.description
- product.featured_image
- product.first_available_variant
- product.handle
- product.id
- product.images
- product.image
- product.options
- product.price
- product.price_max
- product.price_min
- product.price_varies
- product.selected_variant
- product.selected_or_first_available_variant
- product.tags
- product.template_suffix
- product.title
- product.type
- product.url
- product.variants
- product.vendor
product.available
Returns true
if a product is available for purchase. Returns false
if all of the products variants' inventory_quantity values are zero or less, and their inventory_policy is not set to "Allow users to purchase this item, even if it is no longer in stock."
product.collections
Returns an array of all of the collections a product belongs to.
Input
This product belongs in the following collections:
{% for collection in product.collections %}
{{ collection.title }}
{% endfor %}
Output
This product belongs in the following collections:
Sale
Shirts
Spring
product.compare_at_price_max
Returns the highest compare at price. Use one of the money filters to return the value in a monetary format.
product.compare_at_price_min
Returns the lowest compare at price. Use one of the money filters to return the value in a monetary format.
product.compare_at_price_varies
Returns true
if the compare_at_price_min
is different from the compare_at_price_max
. Returns false
if they are the same.
product.content
Returns the description of the product. Alias for product.description.
product.description
Returns the description of the product.
product.featured_image
Returns the relative URL of the product's featured image.
product.first_available_variant
Returns the variant object of the first product variant that is available for purchase. In order for a variant to be available, its variant.inventory_quantity
must be greater than zero or variant.inventory_policy
must be set to continue
. A variant with no inventory_policy is considered available.
product.handle
Returns the handle of a product.
product.id
Returns the id of the product.
product.images
Returns an array of the product's images. Use the product_img_url filter to link to the product image on Haravan's Hstatic.
Input
{% for image in product.images %}
<img src="{{ image.src | product_img_url: 'medium' }}">
{% endfor %}
Output
<img src="//hstatic.net/206/1000001206/1/2014/8-28/00102704-01__1__medium.jpg" />
//hstatic.net/206/1000001206/1/2014/8-28/00102704-01_medium.jpg
product.image
The product.image
object has the following attributes:
- product.image.alt
- product.image.attached_to_variant?
- product.image.id
- product.image.product_id
- product.image.position
- product.image.src
- product.image.variants
product.image.alt
Returns the alt tag of the image, set in the Products page of the Admin.
product.image.attached_to_variant?
Returns true
if the image has been associated with a variant. Returns false
otherwise. This can be used in cases where you want to create a gallery of images that are not associated with variants.
product.image.id
Returns the id of the image.
product.image.product_id
Returns the id of the image's product.
product.image.position
Returns the position of the image, starting at 1. This is the same as outputting forloop.index.
product.image.src
Returns the relative path of the product image. This is the same as outputting .
Input
{% for image in product.images %}
{{ image.src }}
{{ image }}
{% endfor %}
Output
products/my_image.jpg
products/my_image.jpg
To return the URL of the image on Haravan's Hstatic, use the appropriate URL filter.
To see a full list of available image sizes, see image size parameters.
Shown below is an example of loading a product image using the img_url
filter.
Input
{{ image | img_url: "medium" }}
Output
<img src="//hstatic.net/206/1000001206/1/2014/8-28/00102704-01__1__medium.jpg" />
product.image.variants
Returns the variant object(s) that the image is associated with.
Input
{% for image in product.images %}
{% for variant in image.variants %}
{{ image.src }} - used for the variant: {{ variant.title }}
{% endfor %}
{% endfor %}
Output
products/red-shirt.jpeg - used for the variant: Red
products/green-shirt.jpg - used for the variant: Green
products/yellow-shirt.jpg - used for the variant: Yellow
product.options
Returns an array of the product's options.
Input
{% for option in product.options %}
{{ option }}
{% endfor %}
Output
Tiêu đề Màu săc Kích thước
Use size if you need to determine how many options a product has.
Input
{{ product.options.size }}
Output
3
product.price
Returns the price of the product. Use one of the money filters to return the value in a monetary format.
product.price_max
Returns the highest price of the product. Use one of the money filters to return the value in a monetary format.
product.price_min
Returns the lowest price of the product. Use one of the money filters to return the value in a monetary format.
product.price_varies
Returns true
if the product's variants have varying prices. Returns false
if all of the product's variants have the same price.
product.selected_variant
Returns the variant object of the currently-selected variant if there is a valid ?variant=
parameter in the URL. Returns nil
if there is not.
Input
URL = myshop.myharavan.com/products/haravan-product?variant=124746062
{{ product.selected_variant.id }}
Output
124746062
product.selected_or_first_available_variant
Returns the variant object of the currently-selected variant if there is a valid ?variant=
query parameter in the URL. If there is no selected variant, the first available variant is returned. In order for a variant to be available, its variant.inventory_quantity
must be greater than zero or variant.inventory_policy
must be set to continue
. A variant with no inventory_management is considered available.
product.tags
Returns an array of all of the product's tags. The tags are returned in alphabetical order.
Input
{% for tag in product.tags %}
{{ tag }}
{% endfor %}
Output
new
hot
sale
special
product.template_suffix
Returns the name of the custom product template assigned to the product, without the product.
prefix nor the .liquid
suffix. Returns nil
if a custom template is not assigned to the product.
Input
on product.wholesale.liquid
{{ product.template_suffix }}
Output
wholesale
product.title
Returns the title of the product.
product.type
Returns the type of the product.
product.url
Returns the relative URL of the product.
Input
{{ product.url }}
Output
/products/haravan-product
product.variants
Returns an array the product's variants.
product.vendor
Returns the vendor of the product.