Guide

How to add a 3D product configurator to Salesforce Commerce Cloud

, imagine.io ·

The imagine.io Configurator Platform integrates with Salesforce Commerce Cloud (B2C Commerce) through a sharing link. On an SFRA storefront, put one iframe tag on the product detail page, either through a small Page Designer component or in the product detail template, and add your storefront's domain to the link's allowed domains in the imagine.io dashboard. The configurator loads with its own customisation options and live price, or with the panel hidden and your own buttons driving it. A short controller in your cartridge puts the configured product in the basket. On a PWA Kit storefront, which is React, mount the SDK and add to the basket with SCAPI: the React guide.

1 THE LINKimagine.io dashboardScenes › Configurable Systems› Sharing Links: add your domain,then Copy embed code2 PASTE ITSalesforce Commerce CloudPage Designer componentor productDetails.ismlthe iframe, then publish3 LIVEYour product page3D view, customisation options,live priceadd to cart through the bridgethe link carries its own catalog and theme; the page only frames it 1 THE LINKimagine.io dashboardScenes › Configurable Systems› Sharing Links: add your domain,then Copy embed code2 PASTE ITSalesforce Commerce CloudPage Designer componentor productDetails.ismlthe iframe, then publish3 LIVEYour product page3D view, customisation options,live priceadd to cart through the bridgethe link carries its own catalog and theme;the page only frames it
Where the embed goes: the link is made in the dashboard, pasted into the Salesforce Commerce Cloud editor, and the configurator renders inside the page.
This guide uses the embed route. One iframe, a sharing link, and the bridge for the cart. Your own buttons are already covered: hide the configurator's panel and drive it from the page through the bridge (step 5 below). Want to change the configurator itself, the parts inside the frame? Build it with the SDK, host that page, and embed it with the same iframe: the bridge activates on any page that mounts the SDK inside an iframe, so everything below about the cart works unchanged. All three routes: which route fits which site.

The embed code

One element. The configurator boots, loads its catalog and renders itself, with its customisation options and live price. Replace lk_YOUR_LINK with your sharing link.

<iframe
  id="configurator"
  title="Product configurator"
  src="https://configurator.imagine.io/lk_YOUR_LINK"
  style="width:100%; height:640px; border:0; display:block"
  allow="xr-spatial-tracking; fullscreen; clipboard-write"
  referrerpolicy="strict-origin-when-cross-origin"
  loading="lazy"></iframe>

Step by step

  1. Create the sharing link and allow your domain

    In the imagine.io dashboard open Scenes › Configurable Systems, pick the system, and on its Sharing Links tab create a link. Give it a name for where it will live, choose a theme or leave the default, and under Allowed domains add every domain the page will be served from. Leave the list empty while you test locally, and fill it in before you go live: a link embedded on a domain that is not listed shows a “not authorized” card instead of the configurator.

    Copy embed code on the row gives you the iframe below with the link filled in.

    The Sharing Links tab of a system, with one link showing its name, theme and allowed domains
    Scenes › Configurable Systems › Sharing Links. One link per place you use it; the allowed domains are set here.
  2. Option A: a Page Designer component

    Use this when merchandisers should place the configurator themselves. A developer adds three files to a cartridge on the site's cartridge path: the component type, its script, and its template. Merchandisers then drag 3D configurator onto a page in Merchant Tools › Content › Page Designer, paste the link id, and publish, with no code change per page. Salesforce's guide: Page Designer.

    // cartridge/experience/components/assets/imagineConfigurator.json: the component and the fields merchandisers fill in
    {
      "name": "3D configurator",
      "description": "An imagine.io configurator from a sharing link",
      "group": "assets",
      "attribute_definition_groups": [{
        "id": "settings",
        "name": "Settings",
        "attribute_definitions": [
          { "id": "linkId", "name": "Sharing link id (lk_...)", "type": "string", "required": true },
          { "id": "height", "name": "Height", "type": "string", "default_value": "640px" }
        ]
      }],
      "region_definitions": []
    }
    // cartridge/experience/components/assets/imagineConfigurator.js: pass the fields to the template
    'use strict';
    var Template = require('dw/util/Template');
    var HashMap = require('dw/util/HashMap');
    
    module.exports.render = function (context) {
        var model = new HashMap();
        model.linkId = context.content.linkId;
        model.height = context.content.height || '640px';
        return new Template('experience/components/assets/imagineConfigurator').render(model).text;
    };
    <!-- cartridge/templates/default/experience/components/assets/imagineConfigurator.isml: the iframe the component renders -->
    <iframe id="configurator" title="Product configurator"
      src="https://configurator.imagine.io/${pdict.linkId}"
      style="width:100%; height:${pdict.height}; border:0; display:block"
      allow="xr-spatial-tracking; fullscreen; clipboard-write"
      referrerpolicy="strict-origin-when-cross-origin" loading="lazy"></iframe>
  3. Option B: the product detail template

    Use this to give every product of a line its own configurator without touching pages. Add a custom product attribute named imagineLink (Administration › Site Development › System Object Types › Product, type String), add it to an attribute group so it shows in the product editor, and fill in each product's link id. Then copy product/productDetails.isml from app_storefront_base to the same path in your cartridge and print the iframe where it should appear:

    <!-- product/productDetails.isml: the iframe, for products with a link in imagineLink -->
    <isset name="imagineLink" value="${dw.catalog.ProductMgr.getProduct(product.id).custom.imagineLink}" scope="page" />
    <isif condition="${imagineLink}">
      <iframe id="configurator" title="Product configurator"
        src="https://configurator.imagine.io/${imagineLink}"
        style="width:100%; height:640px; border:0; display:block"
        allow="xr-spatial-tracking; fullscreen; clipboard-write"
        referrerpolicy="strict-origin-when-cross-origin" loading="lazy"></iframe>
    </isif>
  4. Size it for the page

    The iframe takes the width of its container. Give it a height that fits the product layout, 640px is a good start, or 80vh for a full-page experience. On phones the configurator lays itself out for the narrow width.

  5. Decide who owns the customisation options

    Keep the configurator's panel, or hide it with ?hide=sidebar on the link and drive the scene from your own swatches through the postMessage bridge. The 3D view stays.

    https://configurator.imagine.io/lk_YOUR_LINK?hide=sidebar

    With the panel hidden, your page sends the choices in. Wait for the frame to say it is ready, read the option sets to build your own swatches from, then select by name or by id. The ten-line callConfigurator helper is the one from the cart section below.

    const iframe = document.getElementById('configurator');
    
    window.addEventListener('message', (e) => {
      if (e.data?.type === 'configurator:ready') start();          // the frame is listening
    });
    
    async function start() {
      // Every option set and option, to build your own swatches from
      const sets = await callConfigurator(iframe, 'getOptionSets');
    
      // Your swatch -> the configurator. By name, or by id when your CMS stores ids
      await callConfigurator(iframe, 'selectOption', { optionSet: 'Fabric', option: 'Cognac' });
      await callConfigurator(iframe, 'selectOption', { optionSetId: 41, optionId: 118 });
    
      // Hide or show parts of the configurator's interface after boot
      await callConfigurator(iframe, 'hideUI', { regions: ['sidebar'] });
    }

    What you can pass and what comes back: the URL parameters (hide, gui, theme, project, config), the full protocol, every command with its payload and its real reply (select options, read the quote and the state, camera, interface regions, undo and redo), the events the frame sends out, and the helper. One thing to know: a command the frame accepts can still be refused by a rule a moment later, which arrives as an evaluate.rejected event, so roll a cart line back on that event, not on the command's reply.

  6. Add every domain you serve from

    Add the storefront's live domain and each sandbox, development and staging host you test on to the link's allowed domains. The check reads the referrer, so keep the iframe's referrerpolicy at strict-origin-when-cross-origin or looser.

  7. Test on a sandbox

    Upload the cartridge, add it to the site's cartridge path, open the product on the sandbox, change a few options and watch the price. Then wire the basket below.

Hand the configuration to your cart

The bridge gives the page the itemised quote, a thumbnail and a snapshot of the build. On SFRA, the script below posts them with a CSRF token to a controller in your cartridge, which adds the product to the basket and keeps the configuration on the line in a custom attribute. Create the attribute first: Administration › Site Development › System Object Types › ProductLineItem, a Text attribute named imagineConfiguration. Then, in productDetails.isml under the iframe, add the button and give the script the values it needs; the script itself goes in the same template.

<!-- product/productDetails.isml, under the iframe: the button and the values the script needs -->
<button id="add-to-cart" disabled>Add to cart</button>
<script>
  var SFCC_PRODUCT_ID = "${product.id}";
  var CSRF_URL = "${URLUtils.url('CSRF-Generate')}";
  var CONFIGURED_ADD_URL = "${URLUtils.url('Configurator-AddToBasket')}";
  var CART_URL = "${URLUtils.url('Cart-Show')}";
</script>
// Ten lines you write once: posts a command into the iframe and resolves with its reply.
function callConfigurator(iframe, action, payload) {
  return new Promise((resolve, reject) => {
    const requestId = 'req-' + Math.random().toString(36).slice(2);
    const onReply = (e) => {
      const m = e.data;
      if (m?.type !== 'configurator:response' || m.requestId !== requestId) return;
      window.removeEventListener('message', onReply);
      m.success ? resolve(m.data) : reject(new Error(m.error));
    };
    window.addEventListener('message', onReply);
    iframe.contentWindow.postMessage({ action, payload, requestId }, '*');
  });
}
const iframe = document.getElementById('configurator');
const add = document.getElementById('add-to-cart');

window.addEventListener('message', (e) => {
  const m = e.data;
  if (m?.type === 'configurator:ready') add.disabled = false;
  // The price follows every change the shopper makes. No polling.
  if (m?.type === 'configurator:event' && m.event === 'price.changed') {
    add.textContent = `Add to cart: ${m.data.currency} ${m.data.grandTotal}`;
  }
});

add.onclick = async () => {
  const quote      = await callConfigurator(iframe, 'getQuote');          // itemised, priced by the engine
  const { dataUrl } = await callConfigurator(iframe, 'getScreenshot');    // thumbnail for the cart
  const snapshot   = await callConfigurator(iframe, 'getConfiguration');  // reopen the exact build later
  // Product pages are cached, so ask for a fresh CSRF token at click time
  const { csrf } = await (await fetch(CSRF_URL, { method: 'POST' })).json();
  const body = new URLSearchParams();
  body.append('pid', SFCC_PRODUCT_ID);       // the product that carries the configured item
  body.append(csrf.tokenName, csrf.token);
  body.append('configuration', JSON.stringify({ quote, snapshot }));
  await fetch(CONFIGURED_ADD_URL, { method: 'POST', body });
  window.location.href = CART_URL;           // dataUrl: show it on your page, or upload it to your media storage
};
// cartridge/controllers/Configurator.js: add the product to the basket with the configuration on its line
'use strict';
var server = require('server');
var csrfProtection = require('*/cartridge/scripts/middleware/csrf');
var BasketMgr = require('dw/order/BasketMgr');
var Transaction = require('dw/system/Transaction');
var basketCalculationHelpers = require('*/cartridge/scripts/helpers/basketCalculationHelpers');

server.post('AddToBasket', csrfProtection.validateAjaxRequest, function (req, res, next) {
    var basket = BasketMgr.getCurrentOrNewBasket();
    var form = req.form;
    Transaction.wrap(function () {
        var line = basket.createProductLineItem(form.pid, basket.defaultShipment);
        line.custom.imagineConfiguration = form.configuration;   // the quote and the snapshot, on the line
        basketCalculationHelpers.calculateTotals(basket);
    });
    res.json({ success: true });
    next();
});

module.exports = server.exports();

What arrives in the basket: one line with the SKU you posted as pid, at its price-book price, and the quote and snapshot in the line's imagineConfiguration attribute. The attribute travels from the basket line to the order line, so the order carries the exact build. On a PWA Kit or other headless storefront, add the line with the SCAPI Shopper Baskets API instead: POST …/baskets/{basketId}/items with [{ productId, quantity: 1, c_imagineConfiguration }], where the c_ prefix sets the same custom attribute.

The price comes from your price books: the basket charges the product's own price. To charge the engine's price from quote.totals.grandTotal, set it in your dw.order.calculate hook, and check the quote on the server before you trust it, since it came from the browser. These steps follow Salesforce's documented SFRA and SCAPI interfaces; we have not run them on a Commerce Cloud sandbox of our own, so test them on yours before going live. The bridge chapter documents every field of the quote.

Frequently asked questions

Which 3D configurator integrates with Salesforce Commerce Cloud?

The imagine.io Configurator Platform. On an SFRA storefront it is embedded on the product detail page with one iframe, through a Page Designer component or the product detail template, and a short controller in your cartridge adds the configured product to the basket. PWA Kit storefronts mount the SDK and add to the basket through SCAPI. Rules, constraints and pricing run on imagine.io's servers.

Do I need an AppExchange app?

No. The embed is one iframe in a Page Designer component or an ISML template, and the basket hand-off is a short controller in your own cartridge. Nothing is installed from AppExchange.

Does it work with Salesforce B2B Commerce or CPQ?

This guide covers B2C Commerce, the storefront product known as Salesforce Commerce Cloud. On other Salesforce products the embed is the same iframe, and the quote from the bridge is plain JSON your integration can hand to a cart, an opportunity or a quote record.

My site has a Content-Security-Policy. What does it need?

Allow the configurator origin in frame-src, for example frame-src https://configurator.imagine.io. The configurator host permits framing by the domains in the link's allowed domains, so add your site there too.

Can I use my own swatches instead of the configurator's customisation options on Salesforce Commerce Cloud?

Yes. Add ?hide=sidebar to the link so the panel disappears, then call selectOption from your page through the postMessage bridge. getOptionSets returns every option set and option to build your buttons from. The SDK docs cover each command.

Troubleshooting

The page shows a “not authorized” card instead of the configurator.

The page's domain is not in the link's Allowed domains. Add it in Scenes › Configurable Systems › Sharing Links, including any preview or staging domain you test on. The check reads the referrer, so the iframe must not set referrerpolicy to no-referrer.

The configurator is blank, or the events arrive but every command times out.

Two usual causes. The page is opened from the file system rather than a web server: a file:// page has no origin the browser will deliver replies to. Or the iframe has a sandbox attribute that strips allow-scripts or allow-same-origin. Remove the sandbox attribute and serve the page over http.

Fullscreen or the Copy button does not work inside the embed.

The iframe needs allow="xr-spatial-tracking; fullscreen; clipboard-write". Without fullscreen the browser blocks the fullscreen toggle. Without clipboard-write in the iframe’s allow attribute, the browser blocks copying inside the configurator.

A licence notice appears on the real site but not in testing.

The free plan is for non-commercial evaluation with the imagine.io watermark. Running on your own domain and storefront is part of a paid plan; the plans are in the dashboard under Settings › Billing.

Other platforms

SDK documentation · Admin guide