1

I'd like to hook into the save process of an order, so that I can execute my own code once the order is completed.

So far I've done similar things with the Customer and CustomerAdress Objects using the Plugin Pattern and a aroundSave method.

I'd like to do the same for the order object on checkout, but I can't seem to get an overview on how the mechanisms work. There are just too many new design patterns and methods stacked over each other (Knockout, Component, Rest, Zendframework).

I've tried making a Plugin for Magento\Sales\Model\ResourceModel\Order but it has no effect.

Does anybody have an idea how I can find the correct class to hook up with the plugin class?

2
  • What did you end up doing? I want to implement a call to an external API that purchases the order on my behalf (similar to dropshipping), and I face the same problem. I do not know if I should do a plugin after capture, place order or order save. – awavi Apr 12 '17 at 17:28
  • instead of the save method, I hooked into beforeSave() and afterSave(). – leedch Apr 27 '17 at 15:22
1

I had the same issue as you. I think in the case of placing an order it is better to stick with the Event/Observer pattern, as Magento2 has its own event for that. So what I have done in my code is to create an observer like this:

class PlaceOrderObserver implements ObserverInterface
{
   public function execute(Observer $observer) {
      // Do your stuff here
   }
}

And the events.xml something like this:

<?xml version="1.0"?>
   <config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Event/etc/events.xsd">
      <event name="sales_order_payment_place_end">
         <observer name="someObserver" instance="My\Space\Observer\PlaceOrderObserver" />
   </event>
</config>

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.