Skip to content

basket.itemAddedToBasket

basket.itemAddedToBasket is an event on the Event Bus that occurs whenever an item is added to the basket.

Event body

The basket.itemAddedToBasket body has a TItemAddedToBasketEvent type which represents the item that has been added to the basket. It is optional so it might not exist.

Example

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

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