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?

Siarhey Uchukhlebau
16.2k11 gold badges57 silver badges89 bronze badges
asked Aug 22, 2016 at 16:29
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. Commented Apr 12, 2017 at 17:28
  • instead of the save method, I hooked into beforeSave() and afterSave(). Commented Apr 27, 2017 at 15:22

1 Answer 1

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>
answered Apr 27, 2017 at 19:30

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.