We have two modules which fire the same event checkout_submit_all_after.But i need to give a preference for this , i tried giving sequence in module b but it won't work.For ex Module A and Module B triggers the same event, but module B triggers first, my requirement is to trigger Module A and after Module B , is there any way i can do this. And what are the events triggers when order is placed through cron jobs, I have used checkout_submit_all_after
, does this event fires if the order is placed through crons?.
Please give me any solution for to go forward.
Thank You
Best Answer
At first, question, you want to trigger
Module A
module observer then fire observer ofModule B
.Then below is my solution is of this case.
Disable
Module B
using xml code.Then Create around plugin the method
ModuleA_ObserverClass::execute(\Magento\Framework\Event\Observer $observer)
ofObserver of module A
.And on that around Plugin
PluginClass::aroundExecute()
execute originalModuleA_ObserverClass::execute(\Magento\Framework\Event\Observer $observer)
and using$proceed(\ModuleA_ObserverClass $subject,\Callable ,$observer)
And after running of origina method , add new method toPluginClass
.And on this new method, copy all code of
ModuleB: execute
and run after$proceed($observer)
.Step1: Disable Observer of
Module B
Assume above one is observer declaration of ModuleB. First, we have to disable this observer.
Let's create An
events.xml
at your custom module and disable this by XML nodedisabled
.Step2: Create around plugin on ModuleA_ObserverClass::execute()
Create di.xml and declare the around plugin for
ModuleA_ObserverClass::execute(\Magento\Framework\Event\Observer $observer)
.And Plugin code: