product.bundleStockChanged¶
product.bundleStockChanged is an event on the Event Bus that occurs whenever the stock of a product inside a bundle changes.
Event body¶
Body of product.bundleStockChanged event has a Record<number, BundleItemData> type where BundleItemData represents the BundleItemData model. This event body which represents the details of a current state of a bundle data. It is optional so it might not exist.
Example¶
In this example we listen to product.bundleStockChanged event and perform an action whenever it's emitted.
useStorefront(async (storefront) => {
storefront.eventBus.on('product.bundleStockChanged', ({ body: bundleStock }) => {
console.log('A stock of a product inside a bundle has changed', bundleStock);
});
});
Example¶
In this example we use a Message Storage API to retrieve an array of past product.bundleStockChanged events.
useStorefront((storefront) => {
const messageStorageApi = storefront.getApiSync('messageStorageSystemApi');
const pastBundleStockChangedEvents = messageStorageApi.getChannelMessages('product.bundleStockChanged');
if (pastBundleStockChangedEvents.length > 0) {
pastBundleStockChangedEvents.forEach(({ body: eventBody }) => {
console.log('perform action on every past event');
});
}
});