Add To Cart
Add an Add to Cart button to product cards in a conversation. When a shopper clicks it, Neocom sends the SKU and title to window.neocomActionCallback. Your storefront calls its cart API and shows whether the variant was added. Style the button under Results › Add to Cart Button in the Theme reference.
Neocom enables the button for your assistant. Before connecting the callback, confirm how your cart resolves the sellable variant from the event’s SKU. See the ADD_TO_CART event for payload fields and keep any existing handlers in the same callback.
Wiring it to your cart
Section titled “Wiring it to your cart”On Shopify, the cart API takes a variant ID. Use the example when your feed SKU is that ID, or map the SKU to the variant first. Replace cart:refresh with the event your theme uses to refresh the cart.
<script> window.neocomActionCallback = function (event) { if (event.action !== "ADD_TO_CART") return; fetch(window.Shopify.routes.root + "cart/add.js", { method: "POST", headers: { "Content-Type": "application/json" }, body: JSON.stringify({ items: [{ id: event.data.sku, quantity: 1 }] }) }) .then((response) => { if (!response.ok) throw new Error("The cart rejected the item"); }) .then(() => document.dispatchEvent(new CustomEvent("cart:refresh"))) .catch((error) => console.error("Error:", error)); };</script>For another storefront, handle the same ADD_TO_CART event in your existing callback. Pass event.data.sku to the same add-to-cart function as the storefront’s own button. Let that function update the cart count and show any error.
Test with a known variant. Check that one click adds that variant and refreshes the storefront cart. Handle rejected requests in your storefront’s cart UI. The Shop Agent button responds to the click before your cart API confirms success.
Not the same as the Shopping Quiz’s Add to Cart
Section titled “Not the same as the Shopping Quiz’s Add to Cart”If you use both products, set up the Shop Agent callback and supply the Shopping Quiz cart link.
| Shop Agent | Shopping Quiz | |
|---|---|---|
| Mechanism | window.neocomActionCallback with action: "ADD_TO_CART" |
Opens the URL from the feed attribute add_to_cart_link |
| What you provide | A JavaScript callback that calls your cart API | A feed attribute, no code |
| Activation | By Neocom | By Neocom, after the attribute is in the feed |
For the quiz, see Add to Cart.