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.