Skip to content

addedToFavourites.added

addedToFavourites.added is an event on the Event Bus that occurs whenever the product is added to favourites.

Event body

The addedToFavourites.added body has a string type which represents the stock id of the added product. It is optional so it might not exist.

Example

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

useStorefront(async (storefront) => {
    storefront.eventBus.on('addedToFavourites.added', ({ body: stockId }) => {
        console.log('Product has has been added to favourites with this stockId:', stockId);
    });
});

Example

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

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

    const pastAddedEvents = messageStorageApi.getChannelMessages('addedToFavourites.added');

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

JS API reference