Skip to content

availabilityNotifierEvents.unsubscribed

availabilityNotifierEvents.unsubscribed is an event on the Event Bus that occurs whenever a user unsubscribes from notifications about availability of a given product.

Event body

Body of availabilityNotifierEvents.unsubscribed event has a number type which represents the id of a product variant the user unsubscribes from. It is optional so it might not exist.

Example

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

useStorefront(async (storefront) => {
    storefront.eventBus.on('availabilityNotifierEvents.unsubscribed', ({ body: productVariantId }) => {
        console.log('A user has unsubscribed from the product with the id:', productVariantId);
    });
});

Example

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

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

    const pastUnsubscribedEvents = messageStorageApi.getChannelMessages('availabilityNotifierEvents.unsubscribed');

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

JS API reference