Hook into commerce catalog events
"The possibilities for integrating EPiServer with other systems are virtually unlimited". A customer requires all the changes of EPiServer Commerce Products done by CMS Editors in Online Centre’s catalog UI, back into their fulfilment system. EPiServer provides a number of features to facilitate Integration with outer systems. I will use .NET API’s catalog events to react changes to catalog items. This can be achieved by adding handlers for IContentEvents, CatalogEventHandler, CatalogEventBroadcaster or can create own implementation of CatalogEventListenerBase and hook the events such as EntryUpdating or EntryUpdated.
IContentEvents: Events will not be raised when a catalog item is updated through Commerce Manager or in Integration Application using ICatalogSystem.
CatalogEventHandler: Events will not be raised when changes done directly through ICatalogSystem only.
CatalogEventBroadcaster: Events will be raised when changes are done through ICatalogSystem, including changes made through the Content API's.
(IContentEvents are in my scope)
We can register events in our Commerce Initialization module, e.g.
[InitializableModule, ModuleDependency(typeof(EPiServer.Commerce.Initialization.InitializationModule))]
public class CommerceInitialization : IConfigurableModule
{
///
public void Initialize(InitializationEngine context)
{
var contenEventHandler = EPiServer.ServiceLocation.ServiceLocator.Current.GetInstance<EPiServer.Core.IContentEvents>();
contenEventHandler.PublishedContent += this.ContenEventPublishedContent;
}
///
}
I am using ValueInjector (convention based mapper) to map Product meta class with OdooProduct.
private void ContenEventPublishedContent(object sender, ContentEventArgs e)
{
var product = e.Content as XYZ.BusinessModel.Models.MetaData.FashionProduct;
if (product != null)
{
log4net.LogManager.GetLogger("EntryUpdate").Error(product.AgeFromInYears);
//used value injector
var odooProduct =
Mapper.AddMap<XYZ.BusinessModel.Models.MetaData.FashionProduct, OdooProduct>(src =>
{
var res = new OdooProduct();
res.InjectFrom(src); // maps properties with same name and type
res.Name = src.DisplayName;
res.AgeFrom = src.AgeFromInYears;
return res;
});
// Update product details on fulfillment center
fulfilmentService.UpdateProduct(odooProduct);
}
}
and That's It.
Comments