Skip to content

basket.itemRemovedFromBasket

basket.itemRemovedFromBasket is an event on the Event Bus that occurs whenever an item is removed from the basket.

Event body

The basket.itemRemovedFromBasket body has a ProductBasket type which represents the item that has been removed to the basket. It is optional so it might not exist.

Example

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

useStorefront(async (storefront) => {
    storefront.eventBus.on('basket.itemRemovedFromBasket', ({ body: itemRemovedFromBasket }) => {
        console.log('An item has been removed from basket:', itemRemovedFromBasket);
    });
});

Example

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

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

    const pastItemRemovedFromBasketEvents = messageStorageApi.getChannelMessages('basket.itemRemovedFromBasket');

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

JS API reference