Restock notifications — example code ==================================== Feature page: https://dwalliance.com/restock.html Store overview: https://dwalliance.com/store.html In-app guide: https://app.dwalliance.com/store/ API module: POST/GET https://app.dwalliance.com/store/restock/ (call this on the store's own domain for public signup) The storefront script in this kit (store.js) already replaces a sold-out "Tell me when it's back" mailto link with the form below, then polls until the customer confirms. You can also paste the snippets yourself. 1. Storefront signup form ------------------------- Show this on a sold-out product page. The hidden "website" field is a honeypot; leave it empty. Post to /store/restock/ on the store's own domain. The response is JSON {ok:true, handle:"..."}. A honeypot submission also returns a handle, but that handle never validates.
2. Confirmation popup --------------------- After signup, show a message asking the visitor not to close the page, check their inbox, and click the confirmation link. Poll the unguessable handle every few seconds. GET /store/restock/?h=HANDLE returns {ok:true, validated:false} until they confirm, then {ok:true, validated:true}. Unknown handles look the same as not-yet-confirmed ones, so the poll cannot be used to see whether someone else is already on the list. function restockPopup(handle) { var pop = document.createElement("div"); pop.setAttribute("role", "dialog"); pop.setAttribute("aria-modal", "true"); pop.innerHTML = "

Check your email

Don't close this. Check your email and click the link, and this popup will close.

"; document.body.appendChild(pop); var stopped = false, ticks = 0; function tick() { if (stopped || ++ticks > 200) return; // ~10 minutes at 3s fetch("/store/restock/?h=" + encodeURIComponent(handle), {credentials: "same-origin", cache: "no-store"}) .then(function (r) { return r.json(); }) .then(function (j) { if (j && j.ok && j.validated) { stopped = true; pop.innerHTML = "

You are signed up

We will email you when this item is back in stock.

"; setTimeout(function () { if (pop.parentNode) pop.parentNode.removeChild(pop); }, 1800); } else { setTimeout(tick, 3000); } }) .catch(function () { setTimeout(tick, 3000); }); } setTimeout(tick, 1500); } 3. Per-variant email fields (staff) ----------------------------------- Staff use the same session they already use for the store. Set a store-wide default, then optionally override it on a single variant. Empty variant fields fall back to the store default, then to the built-in text. Placeholders: {{product_name}}, {{product_url}}, {{variant_name}}, {{store_name}}, {{unsubscribe_url}}. The visible From address may be a @dwalliance.com address; other addresses fall back to the store name plus support@dwalliance.com. The envelope is always support@dwalliance.com. POST /store/restock/ { "session": "YOUR_SESSION", "brand": "YOUR_BRAND", "action": "settings_read" } POST /store/restock/ { "session": "YOUR_SESSION", "brand": "YOUR_BRAND", "action": "settings_update", "restock_subject": "{{product_name}} is back", "restock_from": "Your Store ", "restock_body": "Good news — {{product_name}} is back in stock.\n\n{{product_url}}\n\nIf you no longer want these emails: {{unsubscribe_url}}" } POST /store/restock/ { "session": "YOUR_SESSION", "brand": "YOUR_BRAND", "action": "variant_email_read", "variant_id": "VARIANT_ID" } POST /store/restock/ { "session": "YOUR_SESSION", "brand": "YOUR_BRAND", "action": "variant_email_update", "variant_id": "VARIANT_ID", "restock_subject": "", "restock_from": "", "restock_body": "" } Staff can also list subscribers and history with actions "list" and "history". Confirm, unsubscribe and one-click unsubscribe are query-token links on the same /store/restock/ path. Send and bounce handling are cron jobs, not API actions. See the in-app store guide for the full directions.