2

I've tried to push orders data to 3rdParty webservice. I created observer for event sales_order_place_after - order Id is missing there. I believe it's not a bug - order is not saved in database.

Next try.

I've tried sales_order_save_after - it gives empty array of items, no payment method information. Tried to reload it again with ordermodel->load(id_of_order) but it gives empty data again. I'm pretty sure, order save event is raised before address, payment and other order stuff is saved in database or object in event is order prepared for save, so all additional informations are filtered out.

Any idea how to get correct order data on order place event.

3 Answers 3

4

Here is a list of events http://cyrillschumacher.com/magento2-list-of-all-dispatched-events/

I'm doing the same thing and ended up using 'checkout_onepage_controller_success_action'

<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"   xsi:noNamespaceSchemaLocation="urn:magento:framework:Event/etc/events.xsd">
<event name="checkout_onepage_controller_success_action">
    <observer name="mymodule_controller_success_action" instance="My\Module\Observer\MyObserver"  />
</event>

1
  • 1
    This would work for success payments such as Paypal payment for example? I see there are different events for Payal. Wha event would you use if you want to trigger an event after any success payment?
    – Eduardo
    Commented Feb 1, 2017 at 18:19
2

Try this one sales_model_service_quote_submit_success from Magento\Quote\Model::submitQuote it's right after order is placed and before email send. You will get order ID also:

try {
            $order = $this->orderManagement->place($order);
            $quote->setIsActive(false);
            $this->eventManager->dispatch(
                'sales_model_service_quote_submit_success',
                [
                    'order' => $order,
                    'quote' => $quote
                ]
            );
            $this->quoteRepository->save($quote);
        } catch (\Exception $e) {
            $this->eventManager->dispatch(
                'sales_model_service_quote_submit_failure',
                [
                    'order'     => $order,
                    'quote'     => $quote,
                    'exception' => $e
                ]
            );
            throw $e;
        }
1

"after" plugin for \Magento\Sales\Api\OrderManagementInterface::place should help in this case.

2

Your Answer

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

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