Skip to main content

Product cart

The product cart lets a story drive a shopping cart that lives in your app. Unlike the Goods widget (which only returns product info for display), the cart is interactive: the SDK asks your app to update the cart when the user adds or changes an offer, and to report the current cart state on demand.

Registering handlers​

Provide the cart handlers with setProductCartHandlers. Both handlers may return a value synchronously or as a Promise:

storyManager.setProductCartHandlers({
// Called when the user adds/changes an offer in a story.
// Update your cart and return its new state (or null).
onUpdate: async (offer) => {
await addToCart(offer);
return getCart(); // ProductCart | null
},
// Called when the SDK needs the current cart state.
getState: async () => getCart(), // ProductCart | null
});

If no handlers are set, or a handler throws, the SDK resolves the request with null (a thrown error is logged, not propagated).

Reacting to cart taps​

onProductCartClicked fires when the user taps the cart itself (e.g. to open the checkout screen):

storyManager.onProductCartClicked((payload) => {
// Navigate to your cart / checkout screen
});

Types​

ProductCartOffer​

FieldTypeDescription
offerIdstringOffer identifier (required)
groupIdstringGroup/variant identifier
namestringProduct name
descriptionstringProduct description
urlstringProduct page URL
coverUrlstringCover image URL
imageUrlsstring[]Additional image URLs
currencystringCurrency code
pricestringCurrent price
oldPricestringPrice before discount
adultbooleanAdult-content flag
availabilitynumberAvailable quantity
sizestringSize variant
colorstringColor variant
quantitynumberQuantity in cart

ProductCart​

FieldTypeDescription
offersProductCartOffer[]Items currently in cart
pricestringTotal price
oldPricestringTotal price before discount
priceCurrencystringCurrency code

ProductCartHandlers​

HandlerSignatureCalled when
onUpdate(offer: ProductCartOffer) => ProductCart | null | Promise<…>The user adds or changes an offer
getState() => ProductCart | null | Promise<…>The SDK needs the current cart state