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.
{% 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.