Understant Event system(EntityInsertedEvent, EntityDeletedEvent ) on nopcommerce 4.2 and listen in plugin

1 month ago
Hello I am trying to listen to EntityInsertedEvent, EntityDeletedEvent from my plugin but nothing. Is it possible that system events are not listened to in plugins ?

This my code in plugin i write.

    public class OrderEventConsumer :
                                        //specification attributes
                                      IConsumer<EntityInsertedEvent<OrderItem>>,
                                      IConsumer<EntityDeletedEvent<OrderItem>>
    {

        private ILogger _logger;


        public OrderEventConsumer( ILogger logger)
        {
            _logger = logger;

         }
        
        #region methods
        public void HandleEvent(EntityInsertedEvent<OrderItem> eventMessage)
            {
                    
                    _logger.Information("add order item");
            }

        public void HandleEvent(EntityDeletedEvent<OrderItem> eventMessage)
            {

                _logger.Information("delete order item");
            }
        #endregion

        }
1 month ago
It should work fine in a plugin.  Note that OrderItems won't get created until the order is 'Placed'.  (I.e. it's not the same as ShoppingCartItem)

You can debug and set a breakpoint in this method which publishes the event:
C:\nopC\nopC430\Libraries\Nop.Services\Orders\OrderService.cs
public virtual void InsertOrderItem(OrderItem orderItem)
1 month ago
Tell me when adding a product to an existing order is what ordeItem does not create? I can see in the database a row created in this table.
1 month ago
I don't understand your question.
When an order is 'placed', the shopping cart items get 'converted' into order items.

(If your event handler is not being called, then I suggest setting the breakpoint as I mention above.)