How to integrate the PrintWearAI configurator on your Shopify store: theme snippet, automatic add-to-cart via /cart/add.js, product sync and variant mapping.
embed.js injects the 3D configurator as an iframe on your product pages. On Shopify it auto-detects the current product from ShopifyAnalytics.meta.product (product id, first variant id, SKU) and resolves it to your linked 3D model.add_to_cart event to your page.PwaiEmbed.handlers.shopify() handler turns that event into a real Shopify cart line via POST /cart/add.js, with the customization attached as line item properties.Shopify admin โ Online Store โ Themes โ Edit code. In your product template (e.g. sections/main-product.liquid, or theme.liquid for all pages), add:
<div id="pwai-configurator"></div>
<script src="https://printwearai.com/embed.js"
data-key="fk_YOUR_KEY"
defer></script>
<script>
document.addEventListener('DOMContentLoaded', function () {
PwaiEmbed.handlers.shopify(); // automatic Shopify cart
});
</script>
data-key is your public embed key (fk_โฆ), found in your workspace โ Integration. It is required โ the widget only reads data-key.#pwai-configurator div is missing, the widget inserts itself before your product form (.product-form, [data-product-form], form[action*="cart"]โฆ). Add the div explicitly to control placement.data-height (default 700), data-locale (fr/en/es/de/it), data-product (force a catalog slug), data-autodetect="false" (disable auto-detection), data-no-consent="true" if you already handle cookie consent.Tenant workspace โ Integrations โ Shopify โ Connect:
https://my-shop.myshopify.comread_products scope. The connection is validated live against the Shopify Admin API before it is saved.Then click Sync (runs automatically after connecting). PrintWearAI imports your published products โ id, first variant id, variant SKU, title, price, image and handle โ into your external products catalog.
In Integrations โ Product mapping, link each imported Shopify product to one of your 3D products. Linking stores external_product_id / external_variant_id / external_sku on the 3D product, which enables:
/api/resolve matches the SKU or product id found on the page and opens the right 3D model.add_to_cart event carries the Shopify variant id, so the handler can add the correct variant.You can also set the external ids manually per product in Products โ edit โ External catalog link (external platform, product id, variant id, SKU).
PwaiEmbed.handlers.shopify(options) registers a handler that, for each add_to_cart event:
m.product.external_variant_id, falling back to m.product.external_product_id. If neither is set it logs a warning and does nothing โ the product must be mapped.POST /cart/add.js with { id: variantId, quantity: m.quantity, properties: โฆ }./cart (disable with { redirect: false }).Line item properties attached to the cart line:
| Property | Content |
|---|---|
_pwai_config_id | Saved configuration id โ the link to production on the PrintWearAI side |
_pwai_product | Product name |
_pwai_thumbnail | Preview image URL of the finished design |
_pwai_patron_url | options.patronEndpoint + config_id (empty prefix if not set) |
_pwai_sizes | JSON size breakdown, e.g. {"M":3,"L":2} |
Options:
| Option | Default | Role |
|---|---|---|
redirect | true | false to stay on the page after adding to cart |
patronEndpoint | '' | URL prefix for the _pwai_patron_url property |
Prefer full control? Register your own callback instead of the built-in handler:
PwaiEmbed.onAddToCart(function (m) {
// m.config_id, m.quantity, m.sizes,
// m.product.external_variant_id, m.customization.thumbnail โฆ
});
To update your imported catalog without manual re-syncs, create Shopify webhooks for products/create and products/update pointing to:
POST https://printwearai.com/api/webhooks/shopify/fk_YOUR_KEY
If you saved a webhook secret in Integrations, the X-Shopify-Hmac-Sha256 signature is verified and unsigned or invalid deliveries are rejected (401).
data-key missing โ you wrote data-embed-key; the widget only reads data-key.external_variant_id / external_product_id. Link it in Integrations โ Product mapping, or set the ids manually in Products.external_product_id. Map the product.PwaiEmbed.handlers.shopify() (or PwaiEmbed.onAddToCart(fn)).external_variant_id manually on the 3D product.data-product="your-slug" or disable with data-autodetect="false".See also: Embed widget ยท Webhooks ยท Custom site (API)