Magento 2 Module Observer Sequence order and Sales Order EventWhat order the same event will fire if it is captured in several modules?Is there any specific order of invoking observer functions?Magento 2: Change Customer Group Once Order is Completed for ProductWhat Magento Event fires on 'Reorder'?Sales order observer event issueHow to create a event observer which trigger after a customer placed an orderMagento 2 Event sales_order_payment_pay not triggeringMagento 2: Get Payment Information in checkout_submit_all_after event observerMagento 2 - Sales Order Shipment Event/ObserverMagento 2 - Why does `sales_order_save_commit_after` not fire when user is not logged in?
Having to constantly redo everything because I don't know how to do it
What are the children of two Muggle-borns called?
How to count the number of bytes in a file, grouping the same bytes?
Apollo Mission Operations Control Room 2 display, what do these numbers indicate?
Why didn't Avengers simply jump 5 years back?
Smart contract transaction of 0 XTZ throwing error from TEZBOX
Why should I allow multiple IP addresses on a website for a single session?
Does Flashpoint ever indicate directly that it takes place in Toronto?
Where to connect the fuse and why?
English idiomatic equivalents of 能骗就骗 (if you can cheat, then cheat)
Could you fall off a planet if it was being accelerated by engines?
Is it OK to say "The situation is pregnant with a crisis"?
How does mmorpg store data?
What is this fluorinated organic substance?
Do electrons really perform instantaneous quantum leaps?
How does the 'five minute adventuring day' affect class balance?
Why was Pan Am Flight 103 flying over Lockerbie?
How do I debug a dependency package? If I have its source code
Odd PCB Layout for Voltage Regulator
How many transistors are there in a logic gate?
How useful would a hydroelectric power plant be in the post-apocalypse world?
Does "boire un jus" tend to mean "coffee" or "juice of fruit"?
Cat files in subfolders in order given by a list
iMac 2019: Can I mix the old modules with the new ones when upgrading RAM?
Magento 2 Module Observer Sequence order and Sales Order Event
What order the same event will fire if it is captured in several modules?Is there any specific order of invoking observer functions?Magento 2: Change Customer Group Once Order is Completed for ProductWhat Magento Event fires on 'Reorder'?Sales order observer event issueHow to create a event observer which trigger after a customer placed an orderMagento 2 Event sales_order_payment_pay not triggeringMagento 2: Get Payment Information in checkout_submit_all_after event observerMagento 2 - Sales Order Shipment Event/ObserverMagento 2 - Why does `sales_order_save_commit_after` not fire when user is not logged in?
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
magento2 event-observer dependency sequence
add a comment |
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
magento2 event-observer dependency sequence
add a comment |
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
magento2 event-observer dependency sequence
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
magento2 event-observer dependency sequence
magento2 event-observer dependency sequence
edited Jun 24 at 7:24
Amit Bera♦
61.7k16 gold badges84 silver badges183 bronze badges
61.7k16 gold badges84 silver badges183 bronze badges
asked Jun 23 at 6:27
PrasanthPrasanth
419 bronze badges
419 bronze badges
add a comment |
add a comment |
1 Answer
1
active
oldest
votes
At first, question, you want to trigger Module A module observer then fire observer of Module 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(MagentoFrameworkEventObserver $observer) of Observer of module A.
And on that around Plugin PluginClass::aroundExecute() execute original ModuleA_ObserverClass::execute(MagentoFrameworkEventObserver $observer) and
using $proceed(ModuleA_ObserverClass $subject,Callable ,$observer)
And after running of origina method , add new method to PluginClass.
And on this new method, copy all code of ModuleB: execute and run after $proceed($observer).
Step1: Disable Observer of Module B
<event name="checkout_submit_all_after">
<observer name="ModuleB_Observer_Classs" instance="observerClassNameOfModuleB" />
</event>
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 node disabled.
<?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="checkout_submit_all_after">
<!-- Note that observer name should be same of Module B observer -->
<observer name="ModuleB_Observer_Classs" disabled="true" />
</event>
</config>
Step2: Create around plugin on ModuleA_ObserverClass::execute()
Create di.xml and declare the around plugin for ModuleA_ObserverClass::execute(MagentoFrameworkEventObserver $observer).
<?xml version="1.0" ?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
<type name="ModuleA_ObserverClass">
<plugin name="ModuleA_ObserverClass_My_plugin" sortOrder="10" type="PluginClass"/>
</type>
</config>
And Plugin code:
<?php
namespace Namespace;
class PluginClass
public function aroundExecute(
ModuleA_Observer_Classs $subject,
callable $proceed,
MagentoFrameworkEventObserver $observer
)
//This code run original Merthod
$proceed($observer);
$this->replicatedMethodExecuteofObseverOfModuleB($observer);
public function replicatedMethodExecuteofObseverOfModuleB($observer)
// Copy all code of `ModuleA_ObserverClass::execute(MagentoFrameworkEventObserver $observer)`
// and paste here
add a comment |
Your Answer
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "479"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: false,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmagento.stackexchange.com%2fquestions%2f279286%2fmagento-2-module-observer-sequence-order-and-sales-order-event%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
At first, question, you want to trigger Module A module observer then fire observer of Module 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(MagentoFrameworkEventObserver $observer) of Observer of module A.
And on that around Plugin PluginClass::aroundExecute() execute original ModuleA_ObserverClass::execute(MagentoFrameworkEventObserver $observer) and
using $proceed(ModuleA_ObserverClass $subject,Callable ,$observer)
And after running of origina method , add new method to PluginClass.
And on this new method, copy all code of ModuleB: execute and run after $proceed($observer).
Step1: Disable Observer of Module B
<event name="checkout_submit_all_after">
<observer name="ModuleB_Observer_Classs" instance="observerClassNameOfModuleB" />
</event>
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 node disabled.
<?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="checkout_submit_all_after">
<!-- Note that observer name should be same of Module B observer -->
<observer name="ModuleB_Observer_Classs" disabled="true" />
</event>
</config>
Step2: Create around plugin on ModuleA_ObserverClass::execute()
Create di.xml and declare the around plugin for ModuleA_ObserverClass::execute(MagentoFrameworkEventObserver $observer).
<?xml version="1.0" ?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
<type name="ModuleA_ObserverClass">
<plugin name="ModuleA_ObserverClass_My_plugin" sortOrder="10" type="PluginClass"/>
</type>
</config>
And Plugin code:
<?php
namespace Namespace;
class PluginClass
public function aroundExecute(
ModuleA_Observer_Classs $subject,
callable $proceed,
MagentoFrameworkEventObserver $observer
)
//This code run original Merthod
$proceed($observer);
$this->replicatedMethodExecuteofObseverOfModuleB($observer);
public function replicatedMethodExecuteofObseverOfModuleB($observer)
// Copy all code of `ModuleA_ObserverClass::execute(MagentoFrameworkEventObserver $observer)`
// and paste here
add a comment |
At first, question, you want to trigger Module A module observer then fire observer of Module 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(MagentoFrameworkEventObserver $observer) of Observer of module A.
And on that around Plugin PluginClass::aroundExecute() execute original ModuleA_ObserverClass::execute(MagentoFrameworkEventObserver $observer) and
using $proceed(ModuleA_ObserverClass $subject,Callable ,$observer)
And after running of origina method , add new method to PluginClass.
And on this new method, copy all code of ModuleB: execute and run after $proceed($observer).
Step1: Disable Observer of Module B
<event name="checkout_submit_all_after">
<observer name="ModuleB_Observer_Classs" instance="observerClassNameOfModuleB" />
</event>
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 node disabled.
<?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="checkout_submit_all_after">
<!-- Note that observer name should be same of Module B observer -->
<observer name="ModuleB_Observer_Classs" disabled="true" />
</event>
</config>
Step2: Create around plugin on ModuleA_ObserverClass::execute()
Create di.xml and declare the around plugin for ModuleA_ObserverClass::execute(MagentoFrameworkEventObserver $observer).
<?xml version="1.0" ?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
<type name="ModuleA_ObserverClass">
<plugin name="ModuleA_ObserverClass_My_plugin" sortOrder="10" type="PluginClass"/>
</type>
</config>
And Plugin code:
<?php
namespace Namespace;
class PluginClass
public function aroundExecute(
ModuleA_Observer_Classs $subject,
callable $proceed,
MagentoFrameworkEventObserver $observer
)
//This code run original Merthod
$proceed($observer);
$this->replicatedMethodExecuteofObseverOfModuleB($observer);
public function replicatedMethodExecuteofObseverOfModuleB($observer)
// Copy all code of `ModuleA_ObserverClass::execute(MagentoFrameworkEventObserver $observer)`
// and paste here
add a comment |
At first, question, you want to trigger Module A module observer then fire observer of Module 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(MagentoFrameworkEventObserver $observer) of Observer of module A.
And on that around Plugin PluginClass::aroundExecute() execute original ModuleA_ObserverClass::execute(MagentoFrameworkEventObserver $observer) and
using $proceed(ModuleA_ObserverClass $subject,Callable ,$observer)
And after running of origina method , add new method to PluginClass.
And on this new method, copy all code of ModuleB: execute and run after $proceed($observer).
Step1: Disable Observer of Module B
<event name="checkout_submit_all_after">
<observer name="ModuleB_Observer_Classs" instance="observerClassNameOfModuleB" />
</event>
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 node disabled.
<?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="checkout_submit_all_after">
<!-- Note that observer name should be same of Module B observer -->
<observer name="ModuleB_Observer_Classs" disabled="true" />
</event>
</config>
Step2: Create around plugin on ModuleA_ObserverClass::execute()
Create di.xml and declare the around plugin for ModuleA_ObserverClass::execute(MagentoFrameworkEventObserver $observer).
<?xml version="1.0" ?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
<type name="ModuleA_ObserverClass">
<plugin name="ModuleA_ObserverClass_My_plugin" sortOrder="10" type="PluginClass"/>
</type>
</config>
And Plugin code:
<?php
namespace Namespace;
class PluginClass
public function aroundExecute(
ModuleA_Observer_Classs $subject,
callable $proceed,
MagentoFrameworkEventObserver $observer
)
//This code run original Merthod
$proceed($observer);
$this->replicatedMethodExecuteofObseverOfModuleB($observer);
public function replicatedMethodExecuteofObseverOfModuleB($observer)
// Copy all code of `ModuleA_ObserverClass::execute(MagentoFrameworkEventObserver $observer)`
// and paste here
At first, question, you want to trigger Module A module observer then fire observer of Module 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(MagentoFrameworkEventObserver $observer) of Observer of module A.
And on that around Plugin PluginClass::aroundExecute() execute original ModuleA_ObserverClass::execute(MagentoFrameworkEventObserver $observer) and
using $proceed(ModuleA_ObserverClass $subject,Callable ,$observer)
And after running of origina method , add new method to PluginClass.
And on this new method, copy all code of ModuleB: execute and run after $proceed($observer).
Step1: Disable Observer of Module B
<event name="checkout_submit_all_after">
<observer name="ModuleB_Observer_Classs" instance="observerClassNameOfModuleB" />
</event>
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 node disabled.
<?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="checkout_submit_all_after">
<!-- Note that observer name should be same of Module B observer -->
<observer name="ModuleB_Observer_Classs" disabled="true" />
</event>
</config>
Step2: Create around plugin on ModuleA_ObserverClass::execute()
Create di.xml and declare the around plugin for ModuleA_ObserverClass::execute(MagentoFrameworkEventObserver $observer).
<?xml version="1.0" ?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
<type name="ModuleA_ObserverClass">
<plugin name="ModuleA_ObserverClass_My_plugin" sortOrder="10" type="PluginClass"/>
</type>
</config>
And Plugin code:
<?php
namespace Namespace;
class PluginClass
public function aroundExecute(
ModuleA_Observer_Classs $subject,
callable $proceed,
MagentoFrameworkEventObserver $observer
)
//This code run original Merthod
$proceed($observer);
$this->replicatedMethodExecuteofObseverOfModuleB($observer);
public function replicatedMethodExecuteofObseverOfModuleB($observer)
// Copy all code of `ModuleA_ObserverClass::execute(MagentoFrameworkEventObserver $observer)`
// and paste here
edited Jun 24 at 15:17
answered Jun 24 at 7:51
Amit Bera♦Amit Bera
61.7k16 gold badges84 silver badges183 bronze badges
61.7k16 gold badges84 silver badges183 bronze badges
add a comment |
add a comment |
Thanks for contributing an answer to Magento Stack Exchange!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmagento.stackexchange.com%2fquestions%2f279286%2fmagento-2-module-observer-sequence-order-and-sales-order-event%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown