Building an AI chatbot embedded in Shopify storefronts via Shadow DOM, and running into a fundamental cart sync problem. Would love input from anyone whoโs solved this.
๐ง๐ต๐ฒ ๐ฃ๐ฟ๐ผ๐ฏ๐น๐ฒ๐บ
We are building a conversational commerce chatbot that helps users discover products and add to cart. Our Agent backend uses the Storefront API to handle cart operations. But weโre hitting a wall: the Storefront API cart and Shopifyโs native theme cart (AJAX Cart / session cookie-based) are two completely isolated systems.
Items added via the chatbot donโt show up on the /cart page.
๐ช๐ต๐ฎ๐ ๐ช๐ฒโ๐๐ฒ ๐ฅ๐๐น๐ฒ๐ฑ ๐ข๐๐
-> Multipass (requires Shopify Plus. Not an option for our merchants)
โ Calling /cart/add.js from backend (server has no session cookie)
What is working but feels like a hack
โ Relying on Shopifyโs session cart
๐ง๐ต๐ฟ๐ฒ๐ฒ ๐๐ฝ๐ฝ๐ฟ๐ผ๐ฎ๐ฐ๐ต๐ฒ๐ ๐ช๐ฒโ๐ฟ๐ฒ ๐๐ผ๐ป๐๐ถ๐ฑ๐ฒ๐ฟ๐ถ๐ป๐ด
AJAX Cart API + postMessage bridge
Chatbot sends cart intent to parent Shopify page via postMessage. Parent page calls /cart/add.js with session cookie intact.
Custom Cart UI (Storefront API as source of truth)
Build a custom cart drawer injected via App Embed Block. Agent returns only a cartId. Custom cart UI fetches cart state directly from Storefront API using that cartId. cartId persists in localStorage per user. No session cookies, no shared state. Fully isolated per user.
๐ค๐๐ฒ๐๐๐ถ๐ผ๐ป๐ ๐ณ๐ผ๐ฟ ๐๐ต๐ฒ ๐ฐ๐ผ๐บ๐บ๐๐ป๐ถ๐๐
-> For those whoโve built chatbot or AI agent integrations on Shopify: Is the custom cart (Storefront API + localStorage) genuinely the cleaner long-term architecture, or does the AJAX Cart approach hold up well enough at scale?
-> Any gotchas with the custom cart approach we should anticipate beyond the obvious (cartId expiry, native ATC button interception, suppressing the theme cart UI)?
-> On Shopifyโs Universal Cart (part of Shopify for Agents, currently in early access): it enables a single persistent cart across AI agent surfaces and multiple merchants. For a chatbot like ours thatโs embedded directly in a merchantโs Shopify storefront, does Universal Cart change this architecture entirely? Or is it solving a different problem (cross-merchant aggregation for external AI surfaces like Google/Gemini) rather than the storefront-embedded chatbot sync problem weโre dealing with?
The documentation doesnโt always surface these nuances. Would love to hear from anyone navigating the same space.