Adding data to a specific field on base product updates

I’m trying to add some data to a base product when an update occurs.

I’m using the eventbroker to listen to updates like so:

_eventBroker.Subscribe<BaseProductUpdated>(async eventArgs => { await ProductUpdated(eventArgs.Item); });

This is an example for the implementation of ProductUpdated

private async Task ProductUpdated(BaseProduct eventArgsItem)
{
        var service = IoC.Resolve<BaseProductService>();
        var baseProductClone = eventArgsItem.MakeWritableClone();            
        baseProductClone.Fields.AddOrUpdateValue("some_field", "some value");            
        service.Update(baseProductClone);
        await Task.CompletedTask;
}

But this would actually trigger the BaseProductUpdated again which will result in a loop. How should I do this to avoid that additional trigger?

Litium version: [7.6.3]

Check first if the field has same value then don’t update.

Alright, so there is simply no way of not sending the event? I was thinking that it will send events unnecessarily but I guess it’s not a big issue.

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.