basket.purchased¶
basket.purchased
is an event on the Event Bus that occurs whenever items are purchased.
Event body¶
The basket.purchased
body has a Basket type which represents the basket of purchased items. It is optional so it might not exist.
Example¶
In this example we listen to basket.purchased
event and perform an action whenever it's emitted.
useStorefront(async (storefront) => {
storefront.eventBus.on('basket.purchased', ({ body: basket }) => {
console.log('Purchased items:', basket);
});
});
Example¶
In this example we use a Message Storage API to retrieve an array of past basket.purchased
events.
useStorefront((storefront) => {
const messageStorageApi = storefront.getApiSync('messageStorageSystemApi');
const pastPurchasedEvents = messageStorageApi.getChannelMessages('basket.purchased');
if (pastPurchasedEvents.length > 0) {
pastPurchasedEvents.forEach(({ body: eventBody }) => {
console.log('perform action on every past event');
});
}
});