1

I've used the sales_order_save_before event scope is etc/events.xml - This is working fine but, etc/frontend/events.xml not working properly. sales_order_save_before event not support frontend scope?

2 Answers 2

1

The class which is reponsible for dispatching sales_order_save_before event is the model of order Magento\Sales\Model\Order. In order to get to the dispatch statement, you need to look for the beforeSave method into inheritance heirarchy of this model. If you do so, you will end up in Magento\Framework\Model\AbstractModel class which contains the save, beforeSave and afterSave methods.

public function beforeSave()
{
     if (!$this->getId()) {
         $this->isObjectNew(true);
     }
     $this->_eventManager->dispatch('model_save_before', ['object' => $this]);
     $this->_eventManager->dispatch($this->_eventPrefix . '_save_before', $this->_getEventData());
     return $this;
 }
1
  • This is a beautiful answer: informative, concise, and generalized enough to apply to many situations.
    – dotancohen
    Jul 5 at 6:12
0

And also In case you do not want to listen to the "sales_order_save_before" is global event , so it is use in etc/events.xml

2

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.