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
| Field | Type | Description |
|---|---|---|
offerId | string | Offer identifier (required) |
groupId | string | Group/variant identifier |
name | string | Product name |
description | string | Product description |
url | string | Product page URL |
coverUrl | string | Cover image URL |
imageUrls | string[] | Additional image URLs |
currency | string | Currency code |
price | string | Current price |
oldPrice | string | Price before discount |
adult | boolean | Adult-content flag |
availability | number | Available quantity |
size | string | Size variant |
color | string | Color variant |
quantity | number | Quantity in cart |
ProductCart
| Field | Type | Description |
|---|---|---|
offers | ProductCartOffer[] | Items currently in cart |
price | string | Total price |
oldPrice | string | Total price before discount |
priceCurrency | string | Currency code |
ProductCartHandlers
| Handler | Signature | Called 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 |