Product Pages
A product page has to let the shopper pick a variant, see that variant's price and stock, choose a quantity and add exactly that to the cart, all without a script. The pattern: a CSS-only radio picker shows one of several pre-rendered buttons, and each button carries its own variant.
A complete buy box
Pick a variant in the preview: the price, the stock line and the button change with it. Click Add to cart to see which variant would be added. Switch the route to Homepage and the section renders nothing, because it is guarded.
Runs in your browser on sample data: the same engine and filters as the storefront. Widgets such as add to cart are simulated: clicking one shows what would happen on a store.
How it works
- One hidden radio per variant, before the buy box. A
:checked ~rule per variant shows the elements tagged-for-v1,-for-v2and so on. - Loop
product.variantseven for a single-variant product: there is always one, and itsidis what the checkout needs. Hide the picker withhas_variants, not by skipping the loop. - Each button carries its own
data-joomni-variant-idanddata-joomni-has-variants="false", so the click adds that exact variant instead of opening the quick-add picker. - The quantity is a plain
<select>. The button reads it by id when clicked (data-joomni-quantity-from). Cap it in the markup; the cart caps at 99 anyway.
Show stock only when it sells
tracks_inventory and a threshold.Options and custom fields
product.options gives the axes (Size, Colour) and their values, for when you want to render a matrix instead of a flat list of variant titles. product.custom_fields holds anything extra the merchant added, like material or care.
Only for some products
A size guide belongs on clothes, not on mugs. Merchants can show a section for some products only with visibility rules, and inside the template you can branch on tags or type. See Conditional sections.