Skip to main content

PA Discovery OS Events

Discovery OS widgets dispatch DOM events on document so your theme or custom scripts can react without coupling to widget markup. Register listeners before shoppers interact with widgets (for example on page load).

Cart add (paDiscoveryOsApp:cart:add)​

Discovery OS widgets add products with Shopify’s /cart/add.js endpoint. The widget does not render the theme header, cart count, or minicart, so those stay unchanged until the theme handles the add.

After a successful add, the widget dispatches paDiscoveryOsApp:cart:add on document. The event bubbles. Listen for it in the theme and run the cart update there: refresh the minicart, update the header count, or open the cart drawer.

document.addEventListener('paDiscoveryOsApp:cart:add', (event) => {
const { items, cart, source, product } = event.detail;

// Theme customization: refresh the minicart, update the cart count, or open the cart drawer.
});

The listener must be registered before the shopper clicks add to cart. The event is not dispatched when /cart/add.js fails.

Event detail​

FieldDescription
itemsLines sent to /cart/add.js. Each line is { id, quantity }. id is the numeric variant id.
cartJSON returned by /cart/add.js. This is the added lines, not the full cart from /cart.js.
sourceWidget that added the product.
productAdded product for a single-product add: { id, title, variantId }. Omitted for a bundle add.

source is one of:

sourceWidget
productCardRecommendation product card
richMediaBannerRich media banner product
richMediaRecommendationRich media recommendation card
bundleBundle widget. Every checked product is in items.

Update the header count from the full cart​

cart does not include the updated item count for the whole cart. Fetch /cart.js when the theme needs that count.

document.addEventListener('paDiscoveryOsApp:cart:add', async () => {
const cart = await fetch('/cart.js').then((response) => response.json());
const count = document.querySelector('[data-cart-count]');
if (count) count.textContent = cart.item_count;
});

Replace the selector and the render step with the theme’s own cart markup and drawer API.