A complete product page
Branch between in-stock, preorder, and notify-me — and keep it in sync as the shopper switches variants.
BetaThe SDK is in public beta: endpoints, fields and behaviour can change before general availability. See the changelog
Last updated
The real job: for the selected variant, show add-to-cart (in stock), preorder (sold out but on a plan), or notify-me (sold out, no plan) — and update when the shopper picks another variant. Uses the Storefront SDK.
Decide what to show
Section titled “Decide what to show”const variant = { id, availableForSale, currentlyNotInStock } // from your product queryconst state = await Stoq.client.getVariantState(variant)
if (state.isPreorder) { // sold out, but a preorder plan applies → preorder widget} else if (!variant.availableForSale && Stoq.client.signupsEnabled) { // sold out, no plan → notify-me} else { // in stock → your normal add-to-cart}Vanilla: one widget that follows the variant <select>
Section titled “Vanilla: one widget that follows the variant <select>”The drop-in widget handles all three states and re-binds to the size selector with watch — no JS:
<select name="id"> <option value="43900910010503">43 / Blue</option> <option value="43900910043271">44 / Blue</option></select>
<stoq-preorder-widget product-id="7813090115847" watch="select[name=id]" notify-me-fallback></stoq-preorder-widget>
<script> document.addEventListener('stoq:add-to-cart', (e) => addToCart(e.detail.line))</script>Changing the <select> copies its value into variant-id, and the widget re-renders itself for the new variant — preorder, notify-me, or nothing, automatically.
React / Hydrogen
Section titled “React / Hydrogen”In a loader, read the variant (with availableForSale / currentlyNotInStock) from the Storefront API, then:
function BuyBox({ variant, product }) { const state = useStoqVariant(variant) // null while loading if (!state) return null
if (state.isPreorder) return <StoqPreorderButton variant={variant} /> if (!variant.availableForSale) return <StoqNotifyMeButton variantId={variant.id} productId={product.id} /> return <AddToCartButton variant={variant} />}
// Wrap your app once with the public token:// <StoqProvider shop="my-store.myshopify.com" storefrontToken={PUBLIC_STOREFRONT_API_TOKEN}>…</StoqProvider>useStoqVariant re-derives on the ready event, on variant change, and after refresh(), so the buy box stays correct as the shopper switches options.
Thanks for letting us know.
Still stuck? Ask Quinn or chat with support