๐Ÿ›๏ธ Shopify integration

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.

How it works

  1. 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.
  2. When the customer clicks add-to-cart inside the configurator, the widget emits an add_to_cart event to your page.
  3. The built-in 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.

Step 1 โ€” Install the snippet in your theme

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>
The embedded widget requires a Pro plan or higher. On Free/Essentiel plans the widget shows an upgrade notice and your customers use your hosted configurator page instead.

Step 2 โ€” Connect your store (product sync)

Tenant workspace โ†’ Integrations โ†’ Shopify โ†’ Connect:

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.

Step 3 โ€” Map Shopify products to 3D products

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:

You can also set the external ids manually per product in Products โ†’ edit โ†’ External catalog link (external platform, product id, variant id, SKU).

Automatic add-to-cart

PwaiEmbed.handlers.shopify(options) registers a handler that, for each add_to_cart event:

  1. Picks the variant: 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.
  2. Calls POST /cart/add.js with { id: variantId, quantity: m.quantity, properties: โ€ฆ }.
  3. Redirects to /cart (disable with { redirect: false }).

Line item properties attached to the cart line:

PropertyContent
_pwai_config_idSaved configuration id โ€” the link to production on the PrintWearAI side
_pwai_productProduct name
_pwai_thumbnailPreview image URL of the finished design
_pwai_patron_urloptions.patronEndpoint + config_id (empty prefix if not set)
_pwai_sizesJSON size breakdown, e.g. {"M":3,"L":2}

Options:

OptionDefaultRole
redirecttruefalse 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 โ€ฆ
});

Keep products in sync (Shopify โ†’ PrintWearAI webhook)

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).

FAQ & common pitfalls

See also: Embed widget ยท Webhooks ยท Custom site (API)