Skip to content

basket.basketUpdated

basket.basketUpdated is an event on the Event Bus that occurs whenever a basket updates.

Event body

The basket.basketUpdated body has a Basket type which represents the updated basket. It is optional so it might not exist.

Example

In this example we listen to basket.basketUpdated event and perform an action whenever it's emitted.

useStorefront(async (storefront) => {
    storefront.eventBus.on('basket.basketUpdated', ({ body: basket }) => {
        console.log('Updated basket:', basket);
    });
});

Example

In this example we use a Message Storage API to retrieve an array of past basket.basketUpdated events.

useStorefront((storefront) => {
    const messageStorageApi = storefront.getApiSync('messageStorageSystemApi');

    const pastBasketUpdatedEvents = messageStorageApi.getChannelMessages('basket.basketUpdated');

    if (pastBasketUpdatedEvents.length > 0) {
        pastBasketUpdatedEvents.forEach(({ body: eventBody }) => {
            console.log('perform action on every past event');
        });
    }
});

JS API reference