# Product context

Render product details, variant selection, prices, and quantity limits from resolved storefront data.

Declare product in the product section's ctx_needs. The product object contains the current product, its media and variants, resolved prices, availability, and quantity limits. These values already apply to the selected storefront and shopper.

## Variant selection

Use product.options to build option controls. product.selected_variant represents a completed selection; product.display_variant can support the display while selection is incomplete. For a variable product, require selection_complete before submitting the selected variant. Do not use the display variant as a completed shopper choice.

## Quantity and purchase state

quantity_max is the largest quantity currently accepted for a fresh cart line. Null means no finite limit; zero means the item cannot currently be added. max_order_quantity is the merchant's resolved per-order limit and can be null even when available stock imposes a quantity_max. Use available_for_sale and purchase_state to control purchasing.

```vascula
{% assign purchasable = product %}
{% if product.selected_variant %}
  {% assign purchasable = product.selected_variant %}
{% endif %}
{% assign can_submit = purchasable.available_for_sale %}
{% if product.type == 'variable' and product.selection_complete == false %}
  {% assign can_submit = false %}
{% endif %}
{% form 'cart_add' %}
  <input type="hidden" name="product_id" value="{{ product.id }}">
  {% if product.selected_variant %}
    <input type="hidden" name="variant_id" value="{{ product.selected_variant.id }}">
  {% endif %}
  <input type="number" name="quantity" min="1" value="1"{% if purchasable.quantity_max != nil %} max="{{ purchasable.quantity_max }}"{% endif %}>
  <button type="submit"{% unless can_submit %} disabled{% endunless %}>Add to cart</button>
{% endform %}
```

## Prices and related data

A price may be null when no price is available for the current storefront context. Do not turn that into a zero price. Format price.current with money; use the price's on_sale and regular values for sale presentation. Variants carry their own limits and prices. Product references, reviews, and session state are described in the [Catalog reference](https://dev-docs.tringify.com/ctx/reference-catalog).

On the product page, `product.shipping_price` and each variant's `shipping_price` are the per-item shipping price checkout adds for every unit, in the shopper's currency, resolved as checkout resolves it: a variant with shipping prices of its own uses those, otherwise the product's. Null when the item doesn't need shipping or has none. Show it as given (`formatted`), for example beside the price; it never changes free-shipping qualification.

## Available offers

On the product page only, `product.offers` lists the automatic discounts, discount codes and online payment discounts the store shows for this product in the visitor's market: at most 10, in display order, already worded in the visitor's language and the page's currency. Print each offer as given and never sort, filter or word offers yourself. Fields, ordering, freshness and an example are in [Discounts in themes](/themes/discounts); the field reference is [Product offer](/ctx/reference-shared#product-offer).

