Try our conversational search powered by Generative AI!

K Khan
May 15, 2015
  2731
(0 votes)

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.

May 15, 2015

Comments

valdis
valdis May 16, 2015 10:21 AM

I'm considering to expose Commerce events down to client-side through SignalR. Is that something useful? Would client be interested in catalog changes happening on the server?

May 17, 2015 07:10 PM

Bundle of thanks Champ for pointing out this extension point, I confess, I haven’t consider SignalR while writing this Blog. Anyway it isn’t in scope of work as they are not exposing their catalog/events to any client and these weren’t high frequency changes. We need to inform changes of few fields to an already working web service on a third party system only.

K Khan
K Khan May 17, 2015 07:13 PM

I have just noticed comments can be added as guest also :) , I own above comments.

Please login to comment.
Latest blogs
Optimizely and the never-ending story of the missing globe!

I've worked with Optimizely CMS for 14 years, and there are two things I'm obsessed with: Link validation and the globe that keeps disappearing on...

Tomas Hensrud Gulla | Apr 18, 2024 | Syndicated blog

Visitor Groups Usage Report For Optimizely CMS 12

This add-on offers detailed information on how visitor groups are used and how effective they are within Optimizely CMS. Editors can monitor and...

Adnan Zameer | Apr 18, 2024 | Syndicated blog

Azure AI Language – Abstractive Summarisation in Optimizely CMS

In this article, I show how the abstraction summarisation feature provided by the Azure AI Language platform, can be used within Optimizely CMS to...

Anil Patel | Apr 18, 2024 | Syndicated blog

Fix your Search & Navigation (Find) indexing job, please

Once upon a time, a colleague asked me to look into a customer database with weird spikes in database log usage. (You might start to wonder why I a...

Quan Mai | Apr 17, 2024 | Syndicated blog

The A/A Test: What You Need to Know

Sure, we all know what an A/B test can do. But what is an A/A test? How is it different? With an A/B test, we know that we can take a webpage (our...

Lindsey Rogers | Apr 15, 2024

.Net Core Timezone ID's Windows vs Linux

Hey all, First post here and I would like to talk about Timezone ID's and How Windows and Linux systems use different IDs. We currently run a .NET...

sheider | Apr 15, 2024