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

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.
3 anni tempo fa
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

        }
3 anni tempo fa
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)
3 anni tempo fa
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.
3 anni tempo fa
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.)
This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.