This topic explains how to react to changes to catalog items by handling events in Optimizely Commerce.
Implement handlers for IContentEvents events
IContentEvents (namespace EPiServer.Core) defines events that apply to catalog items that are updated through the Content API. For example, when the Catalog view is used, or when the Content API is used from code.
Note: These events are not raised when a catalog item is updated through the Commerce Admin view (Commerce Manager admin view in version 13 and lower), nor in code using ICatalogSystem.
Implement handlers for CatalogEventHandler events
CatalogEventHandler (namespace EPiServer.Commerce.Catalog.Provider), like IContentEvents, defines events using the Content model. The events are raised for changes done through ICatalogSystem, including changes done through the Content API. When compared with IContentEvents, these events carry fewer details. The ContentUpdated event is also raised for changes to catalog Meta Objects.
Implement handlers for CatalogEventBroadcaster events
CatalogEventBroadcaster (namespace Mediachase.Commerce.Catalog.Events) defines events raised when changes are done through ICatalogSystem, including changes made through the Content APIs. The events reflect the low level DTO and MetaObject APIs, carrying the IDs of the affected catalog entities in the event arguments.
[New in Commerce 12]
The events on CatalogEventBroadcaster have been superseded by events on ICatalogEvents (namespace Mediachase.Commerce.Catalog.Events).
CatalogEventBroadcaster also defines the CommerceProductUpdated event identifier, which can be used to listen to remote events via the Event API. This is an advanced topic, and the other methods described above should be preferred. But remote events are an option if you need to react to changes made through the Catalog view, where you usually have no custom code deployed in the same application. Remote events carry a serialized CatalogContentUpdateEventArgs instance that contains the IDs of the affected catalog entities.
Note: If you listen to remote events, be aware that they are distributed to all instances of your application (including the one raising the event). You may need to take extra action to avoid processing the events multiple times. One solution is to have an appSetting flag to indicate if you should process the events, and only set it to true in one instance.
Last updated: Sep 28, 2021