product.quantityChanged¶
product.quantityChanged
is an event on the Event Bus that occurs whenever the product quantity changes.
Event body¶
Body of product.quantityChanged
event has a TProductQuantityChangedEventBody type which represents the details of a changed quantity. It is optional so it might not exist.
Example¶
In this example we listen to product.quantityChanged
event and perform an action whenever it's emitted.
useStorefront(async (storefront) => {
storefront.eventBus.on('product.quantityChanged', ({ body: changedQuantity }) => {
console.log('A quantity has changed', changedQuantity);
});
});
Example¶
In this example we use a Message Storage API to retrieve an array of past product.quantityChanged
events.
useStorefront((storefront) => {
const messageStorageApi = storefront.getApiSync('messageStorageSystemApi');
const pastQuantityChangedEvents = messageStorageApi.getChannelMessages('product.quantityChanged');
if (pastQuantityChangedEvents.length > 0) {
pastQuantityChangedEvents.forEach(({ body: eventBody }) => {
console.log('perform action on every past event');
});
}
});