Help with Creating a new plugin

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.
11 years ago
Not tested but shouldn't the signature of HandleEvent look like

public void HandleEvent(EntityInserted<OrderProductVariant eventMessage )
11 years ago
Hey keesjan, first i want to say thank you for your help!!!,

I just tried it the way you suggested, and the event is still not firing.  Initially, i was trying to extend
IConsumer<OrderPlacedEvent>
instead of
IConsumer<EntityInserted<OrderProductVariant>> 
in the class on my plugin, and i was using
 public void HandleEvent(OrderPlacedEvent eventMessage)
and that didnt fire either.....


I changed the function signature as you suggested,
public void HandleEvent(EntityInserted<OrderProductVariant> eventMessage)
and whenever i place an order (which is when an OrderProductVariant Gets inserted) the event doesnt get fired.  


From the article that i saw on https://www.nopcommerce.com/boards/t/18287/how-can-i-execute-plugin-method-when-order-placed.aspx and looking at their sourcecode at http://nopcommerce.codeplex.com/SourceControl/changeset/view/e64ec069d646#src%2fPlugins%2fNop.Plugin.SMS.Clickatell%2fOrderPlacedEventConsumer.cs .  All i saw that they needed to do was to

+Create a class off the root of given plugin that:
      -Implement the IConsumer Interface (
IConsumer<EntityInserted<OrderProductVariant>>
)
      -Add a public void HandleEvent method. (
public void HandleEvent(EntityInserted<OrderProductVariant> eventMessage
))

is there any other step you think im missing or need to add in order for this event to get fired on my plugin when i make a purchase through the shopping cart? Doesnt this class need to be called from somewhere for the event handler to work? or does Nop.Core.Events handle that automatically?

Thanks again for your input!
11 years ago
Carlos.Valentin wrote:
I changed the function signature as you suggested,
public void HandleEvent(EntityInserted<OrderProductVariant> eventMessage)
and whenever i place an order (which is when an OrderProductVariant Gets inserted) the event doesnt get fired.  


Looking at the code for OrderService.InsertOrder(..) all I see is a call to _eventPublisher.EntityInserted(order);
Looking at the code for OrderProcessingService.PlaceOrder(..) this is where a new OrderProductVariant is created and added to the order all i see is _orderService.UpdateOrder(order)

So it looks like the event EntityInserted<OrderProductVariant> is never published and therefore you can't catch it.

What does work is:

implement somewhere IConsumer<OrderPlacedEvent>

public void HandleEvent( OrderPlacedEvent eventMessage )
{
  //DO STUFF
}


the OrderPlacedEvent contains the Order with a list of OrderProductVariants
11 years ago
Keesjan,


Thats a very good suggestion, however I tried that initially, and the type OrderPlacedEvent doesnt exists on nopCommerce 2.30, i've looked EVERYWHERE.  Do you think that maybe OrderPlacedEvent is something for a more up to date version of nopCommerce?

from what i saw this post the OrderPlacedEvent is located in Nop.Core.Domain.Orders namespace which ive looked at and cant find it.  Ive also done a string search on the entire nopCommerce SourceCode.
11 years ago
nc 2.30??? oops I am using 2.60 ;-)

looking at the code for 2.30 (OrderProcessingService.PlaceOrder) there is code commented


//TODO raise event        
//if (order.PaymentStatus == PaymentStatus.Paid)
//    EventContext.Current.OnOrderPaid(null, new OrderEventArgs() { Order = order });


no event is raised.
11 years ago
I see.. I was reading about event publisher.  So in that same function you were talking about in OrderProcessingService.PlaceOrder, in the part does a  
_orderService.UpdateOrder(order);
(right after each OrderProductVariant is updated) if you look at the UpdateOrder method


public virtual void UpdateOrder(Order order)
        {
            if (order == null)
                throw new ArgumentNullException("order");

            _orderRepository.Update(order);

            //event notification
            _eventPublisher.EntityUpdated(order);
        }


it does a call to the _eventPublisher.EntityUpdated, shouldnt that allow me to implement
IConsumer<EntityUpdated<Order>>
?? and catch the event that way?
11 years ago
yes, at least I saw this in 2.60 when I handled the OrderUpdate event, in 2.60 it fired for every OrderProductVariant added to the order. Maybe your best bet is to just fire and catch the OrderPlacedEvent (backport it from 2.60)
11 years ago
Keesjan,

Upgrading nopCommerce to version 2.3 is not an easy feat for me at this time.  Im simply doing some logic with IConsumer<EntityUpdated<Order>> which works like a charm!, and iterating through the order product variants from that :), thanks for your input, it helped me get to where i wanted to be!!
This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.