I am using an observer to handle some logic when a new order is created or updated. The observer listen to sales_order_save_commit_after event, but I noticed that when the user is not logged in this event does not fire. What is the reason that it does not trigger in this case? Can it be substituted with some other event?

P.s. I checked some other events, like sales_order_save_after but the items are still not saved when it triggers and checkout_onepage_controller_success_action does not work in case of creating the order from admin.

Cases when events are triggered

  • Did you try sales_quote_product_add_after event? – Arunprabakaran M Apr 23 '19 at 11:09
  • For Magento 2.3 frontend use event checkout_cart_product_add_before – Arunprabakaran M Apr 23 '19 at 14:43
  • Did you finally find a fix for this ? Thanks ! – magentodev Jun 12 '19 at 18:56

In the Temando_Shipping module there is the method Temando\Shipping\Plugin\Sales\OrderRepositoryPlugin::afterSave.
In the comment of this method there is this

 * Manifest order at Temando platform.
 * Observers don't work:
 * - `sales_order_save_commit_after` is no longer triggered in guest checkout
 * - `sales_order_save_after` does not have related entities (addresses) persisted yet
 * Other promising events like `sales_order_place_after`, `checkout_submit_all_after`,
 * `sales_model_service_quote_submit_success` are
 * - triggered before the order was saved or
 * - not triggered at all in multi address checkout or some payment providers'
 *   custom checkout implementations (paypal express, sagepay, …).
 * @param SalesOrderRepositoryInterface $subject
 * @param OrderInterface|\Magento\Sales\Model\Order $salesOrder
 * @return OrderInterface

I don't have a response to "why?" I'm just stating that it's by design.

As a bonus checkout_onepage_controller_success_action is not dispatched in admin because that's event is not triggered at all in the backend.

Maybe you can use a plugin similar to what the Temando module uses.
An afterSave plugin on the Order repository class.

  • Your answer looks very in depth. – Arunprabakaran M Apr 23 '19 at 14:35
  • hi @Marius, pls update the code of plugin along with di.xml, Thanks – jafar pinjar Sep 27 '19 at 12:37

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.