Skip to content

availabilityNotifierEvents.subscribed

availabilityNotifierEvents.subscribed is an event on the Event Bus that occurs whenever a user signs up for notifications about availability of a given product.

Event body

Body of the availabilityNotifierEvents.subscribed event has a number type which represents the id of a product variant the user signed up for. It is optional so it might not exist.

Example

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

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

Example

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

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

    const pastSubscribedEvents = messageStorageApi.getChannelMessages('availabilityNotifierEvents.subscribed');

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

JS API reference