# Product

The Liquid `product` object and its properties, with examples.

Money attributes such as prices and totals are returned in the customer's local (presentment) currency. Use a money filter to show the result as a money amount.

The `product` object has the following attributes:

## product.available

Returns `true` if a product is available for purchase. Returns `false` if the [inventory_quantity](https://developer.versacommerce.de/articles/liquid-objects-variant#variant-inventoryquantity) of all product variants is zero or less and their [inventory_policy](https://developer.versacommerce.de/articles/liquid-objects-variant#variant-inventorypolicy) does not allow customers to buy the item when it is out of stock.

## product.collections

Returns an array of all [collections](https://developer.versacommerce.de/articles/liquid-objects-collection) a product belongs to, except collections that are not available on the sales channel in use.

```liquid
This product belongs to the following collections:
{% for collection in product.collections %}
  {{ collection.title }}
{% endfor %}
```

```text
This product belongs to the following collections:
Sale
Shirts
Spring
```

## product.compare_at_price

Returns the lowest compare-at price of all product variants entered in the shop admin. Same as `product.compare_at_price_min`.

If none of the product variants has a compare-at price, `product.compare_at_price` returns `nil`.

## product.compare_at_price_max

Returns the highest compare-at price of all product variants entered in the shop admin.

If none of the product variants has a compare-at price, `product.compare_at_price_max` returns `0`.

## product.compare_at_price_min

Returns the lowest compare-at price of all product variants entered in the shop admin.

If none of the product variants has a compare-at price, `product.compare_at_price_min` returns `0`.

## product.compare_at_price_varies

Returns `true` if `compare_at_price_min` differs from `compare_at_price_max`, `false` if they are the same.

## product.content

Returns the description of the product. Alias of [product.description](#product-description).

## product.created_at

Returns a timestamp of when a product was created in the admin.

```liquid
{{ product.created_at }}
```

```text
2019-11-01 05:56:37 -0400
```

## product.description

Returns the description of the product.

## product.featured_image

Returns an [image object](https://developer.versacommerce.de/articles/liquid-objects-image) of the product's featured image, which is the first image of the product.

Referencing only `product.featured_image` returns the relative URL of the image.

```liquid
Aspect ratio: {{ product.featured_image.aspect_ratio }}
```

```text
Aspect ratio: 1.0
```

## product.featured_media

Returns the first media attached to the product.

## product.first_available_variant

Returns the [variant object](https://developer.versacommerce.de/articles/liquid-objects-variant) of the first product variant that is available for purchase. A variant is available if its `variant.inventory_quantity` is greater than zero or `variant.inventory_policy` is set to `continue`. A variant without [inventory management](https://developer.versacommerce.de/articles/liquid-objects-variant#variant-inventorymanagement) counts as available.

## product.gift_card?

Returns `true` if the product is a gift card.

## product.handle

Returns the [handle](https://developer.versacommerce.de/articles/liquid-basics-handle) of a product.

## product.has_only_default_variant

Returns `true` if the product only has the default variant. Use it to decide whether to show a variant picker in your product forms.

Products without custom [variants](https://developer.versacommerce.de/articles/liquid-objects-variant) have a single default variant whose "Title" [option](https://developer.versacommerce.de/articles/liquid-objects-productoption) is set to "Default Title".

```liquid
{% if product.has_only_default_variant %}
  <input name="id" value="{{ variant.id }}" type="hidden">
{% else %}
  <select name="id">
    {% for variant in product.variants %}
      <option value="{{ variant.id }}">{{ variant.title }}</option>
    {% endfor%}
  </select>
{% endif %}
```

## product.id

Returns the ID of the product.

## product.images

Returns an array of the product's [images](https://developer.versacommerce.de/articles/liquid-objects-image). Use the [image_url](https://developer.versacommerce.de/articles/liquid-filters-url-filters) filter to link to the product image on the VersaCommerce content delivery network (CDN).

Use a for loop to return all images of a product:

```liquid
{% for image in product.images %}
  {{ image | image_url: width: 300 }}
{% endfor %}
```

```text
https://cdn.versacommerce.de/s/files/1/1183/1048/products/boat-shoes.jpeg?v=1459175177&width=300
https://cdn.versacommerce.de/s/files/1/1183/1048/products/boat-shoes-back.jpeg?v=1425177&width=300
https://cdn.versacommerce.de/s/files/1/1183/1048/products/boat-shoes-bottom.jpeg?v=134351&width=300
```

Alternatively, apply an `image_url` filter to the product object to return the product's image:

```liquid
{{ product | image_url: width: 300 }}
```

```text
https://cdn.versacommerce.de/s/files/1/1183/1048/products/boat-shoes.jpeg?v=1459175177&width=300
```

Product images can also be returned through `product.media`.

## product.media

Returns an array of the product's [media](https://developer.versacommerce.de/articles/liquid-objects-media), sorted by the date they were added. Use [media filters](https://developer.versacommerce.de/articles/liquid-filters-media-filters) to create URLs and model viewer tags that render the media on the product page.

For example, use a for loop over every media item of a product:

```liquid
{% for media in product.media %}
  {{ media | media_tag }}
{% endfor %}
```

## product.options

Returns an array of the product's option names.

```liquid
{% for option in product.options %}
    {{ option }}
{% endfor %}
```

```text
Color Size Material
```

Use the [size](https://developer.versacommerce.de/articles/liquid-filters-array-filters#size) filter to find out how many options a product has.

```liquid
{{ product.options.size }}
```

```text
3
```

## product.options_by_name

Gives direct access to a product's [options](https://developer.versacommerce.de/articles/liquid-objects-productoption) by name. The object keys of `options_by_name` are case-insensitive.

```liquid
<label>
  Color
  <select>
    {% for color_option in product.options_by_name['Color'].values %}
      <option>{{ color_option }}</option>
    {% endfor %}
  </select>
</label>
```

```html
<label>
  Color
  <select>
    <option>Red</option>
    <option>Green</option>
  </select>
</label>
```

## product.options_with_values

Returns an array of the product's [options](https://developer.versacommerce.de/articles/liquid-objects-productoption).

```liquid
{% for product_option in product.options_with_values %}
  <label>
    {{ product_option.name }}
    <select>
      {% for value in product_option.values %}
        <option {% if product_option.selected_value == value %}selected{% endif %}>{{ value }}</option>
      {% endfor %}
    </select>
  </label>
{% endfor %}
```

```html
<label>
  Color
  <select>
    <option selected>Red</option>
    <option>Green</option>
  </select>
</label>
```

## product.price

Returns the lowest price of all variants of the product. Same as `product.price_min`.

## product.price_max

Returns the highest price of all variants of the product.

## product.price_min

Returns the lowest price of all variants of the product.

## product.price_varies

Returns `true` if the product's variants have different prices, `false` if all variants have the same price.

## product.published_at

Returns a timestamp of when a product was published in a shop.

```liquid
{{ product.published_at }}
```

```text
2019-11-01 05:56:37 -0400
```

## product.requires_selling_plan

Returns `true` if `variant.requires_selling_plan` is `true` for all variants of the product. VersaCommerce currently has no selling plans.

## product.selected_variant

Returns the [variant object](https://developer.versacommerce.de/articles/liquid-objects-variant) of the selected variant. The selected variant is based on the `variant` URL parameter.

If no variant is selected, this property returns `nil`.

```liquid
<!-- URL = https://example-shop.versacommerce.de/products/shirt?variant=124746062 -->
{{ product.selected_variant.id }}
```

```text
124746062
```

## product.selected_or_first_available_variant

Returns the [variant object](https://developer.versacommerce.de/articles/liquid-objects-variant) of the selected variant. The selected variant is based on the `variant` URL parameter.

If no variant is selected, the first available variant is returned. A variant is available if `variant.inventory_quantity` is greater than zero or `variant.inventory_policy` is set to `continue`. A variant without [inventory management](https://developer.versacommerce.de/articles/liquid-objects-variant#variant-inventorymanagement) also counts as available.

## product.selected_or_first_available_selling_plan_allocation

Returns a `selling_plan_allocation` object. If the product has no selling plans, this property returns `nil`. VersaCommerce currently has no selling plans.

## product.selected_selling_plan

Returns the `selling_plan` object based on the `selling_plan` URL parameter. VersaCommerce currently has no selling plans.

## product.selected_selling_plan_allocation

Returns the `selling_plan_allocation` object based on URL parameters that identify a selling plan and a variant. VersaCommerce currently has no selling plans.

## product.selling_plan_groups

An array of `selling_plan_group` objects that contain the product's variants. VersaCommerce currently has no selling plans.

## product.tags

Returns an array of all tags of the product. The tags are returned in alphabetical order.

```liquid
{% for tag in product.tags %}
  {{ tag }}
{% endfor %}
```

```text
leather
new
sale
special
```

## product.template_suffix

Returns the name of the custom product template assigned to the product, without the `product.` prefix and the `.liquid` extension. Returns `nil` if no custom template is assigned.

```liquid
<!-- on product.wholesale.liquid -->
{{ product.template_suffix }}
```

```text
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.

```liquid
{{ product.url }}
```

```text
/products/awesome-shoes
```

## product.variants

Returns an array of the product's [variants](https://developer.versacommerce.de/articles/liquid-objects-variant).

## product.vendor

Returns the vendor of the product.


## More properties

VersaCommerce also provides these properties on the `product` object:

| Properties | Returns |
|---|---|
| `subtitle`, `original_title`, `timestamp`, `full_url`, `url_including_shop`, `position`, `category`, `code`, `gtin`, `isbn_code`, `mpn_code`, `asin_code`, `ebay_code`, `currency` | Catalog identifiers, placement and display metadata |
| `base_quantity`, `base_quantity_package`, `base_quantity_sold`, `base_perform_calculation`, `calculates_base`, `base_price`, `base_unit`, `unit_price`, `unit_price_measurement`, `price_decimal`, `price_extra_included`, `extra_price`, `purchase_price` | Grundpreis and price breakdown |
| `metafields`, `properties`, `properties_count`, `single_properties`, `single_properties_count`, `multiple_properties`, `multiple_properties_count`, `hidden_properties`, `hidden_properties_count`, `tags_count`, `tag_list`, `content_title_tag`, `content_meta_description`, `content_meta_keywords` | Catalog properties, tags and SEO fields |
| `bulk_discounts_active`, `bulk_discounts`, `lowest_bulk_discount_price`, `single_product_reviews`, `single_product_review_rating`, `aggregate_product_reviews`, `aggregate_product_review_rating`, `recommendations`, `recommendations_count`, `is_recommendation` | Volume pricing, reviews and cross-sell data |
| `variants_count`, `is_variant`, `main`, `parent`, `collection`, `options`, `option_01`, `option_02`, `option_03`, `option_01_label`, `option_02_label`, `option_03_label`, `custom_option_01`, `custom_option_02`, `custom_option_03`, `matched_variant_by_option_values`, `variant_from_option_values`, `selected_option_value_ids` | Variant, hierarchy and option selection data |
| `width`, `height`, `length`, `considers_stock`, `minimum_stock`, `shows_stock_amount`, `stock`, `amount_available`, `visible`, `shipping_types`, `shipping_types_count`, `minimum_shipping_cost`, `calculates_shipping_cost?`, `requires_shipping`, `physical`, `tax_rate`, `tax_amount`, `taxable`, `reservation_enabled`, `reservations` | Dimensions, stock, fulfillment and tax data |
| `images_count`, `featured_image_url`, `new?`, `featured?`, `new_and_featured?`, `similar_products`, `similar_products_price_min`, `similar_products_price_max`, `similar_products_price_varies` | Image metadata, merchandising flags and mall product comparisons |
