SaaS CMS has officially launched! Learn more now.

Content Events (Commerce 10) and Service API (3)


Hi all

I have created a small initialization module, that reacts to the PublishedContent event and does some stuff.
It works perfectly when manually updating content in the catalog, but when the data is updated via Service API, it seems like the PublishedContent is not raised, is that correct?

Edited, Dec 02, 2021 9:16

Yes, thats correct from my experience also.

Publishing products through Service API does not raise the Content Publishing Event.

Creating Entry's through the IContentRepository API will trigger ContentEvents however. You may need to create a custom API to save products if you need the Content Event triggered. 

Edited, Dec 02, 2021 12:05

It depends on your version. If you are using the latest (or rather 5.2 or later IIRC), then ServiceAPI will fire content events.

Dec 02, 2021 12:39
Johnny Mullaney - Dec 02, 2021 12:46
Didn't know this feature is now included. Thank you

We are using v3.0.1 due to the commerce version - what is the alternative then? It's simply not possible to detect a publish via Service API then?

Dec 02, 2021 13:13

You can listen to the low level event. EventContext.EntryUpdated. the CatalogEntryDto is only updated if an entry is created or "published", so it's safe to assume. However it only works locally. If you have a separate ServiceAPI instance, it will be tricky 

Dec 02, 2021 13:25

Great, I will give it a try, and let you know if it works. I also need to delete an entry in a Solr index, when a Variation is deleted in the catalog. If I use "EntryDeleted", the Variation has already been deleted, and I cannot retrieve the Code. Is there an "EntryDeleting"?

Dec 02, 2021 20:38

I can confirm, that it works with EventContext.EntryUpdated - Thanks a lot!

Now I need to figure out, how I retrieve the code from a deleted variation, can you help?

Dec 03, 2021 9:13

Unfortunately there is no EntryDeleting event. I'm not sure why, probably just an overlook. A workaround is to listen to EntryUpdating event, then look into the sender (CatalogEntryDto). You can see if there is any deleted row in there, and use DataRowVersion to get the deleted code.

Dec 03, 2021 9:30

Could you give an example of how to do this?

Dec 03, 2021 10:05
Dec 07, 2021 14:35

Quan Mai, thanks a lot for the help! I can confirm that it works.
Here is the code I ended up with, I'm only acting on "Variation". Also I extended the CatalogEventListenerBase.

public override void EntryUpdating(object source, EntryEventArgs args)
    base.EntryUpdating(source, args);

    var entry = source as CatalogEntryDto;
    if (entry != null)
        var rows = entry.CatalogEntry.Where(x => x.RowState == DataRowState.Deleted);
        var deletingVariationCodes = rows.Where(x => (string)x["ClassTypeId", DataRowVersion.Original] == "Variation").Select(x => (string)x["Code", DataRowVersion.Original]);
        foreach(var code in deletingVariationCodes)
            // Update the variants in the index
Dec 08, 2021 8:11
This topic was created over six months ago and has been resolved. If you have a similar question, please create a new topic and refer to this one.
* You are NOT allowed to include any hyperlinks in the post because your account hasn't associated to your company. User profile should be updated.