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