2

How to set order of same observer in my three modules?

My each three modules declares same observer.

My first test1_module1 module use sales_convert_quote_item_to_order_item observer

My second test1_module2 module use samesales_convert_quote_item_to_order_item observer so I added <depends><Test1_Module1/></depends> this code in app/etc/modules/Test1_Module2.xml and I extends Test1_Module1_Model_Observer class in second module observer file

My third test1_module3 module use sales_convert_quote_item_to_order_item observer.

And My second module test1_module2 is optional so it may be present or not in test1 package

My last third module should run same observer in last(after first and second module) what I do ?

Note: My third module test1_module3 will dependent on first module test1_module1 and if second module not present third module same observer should run after first module and if second module present then third module observer should run after first and second module observer.

2

To understand the module loading order which defines the order of observer execution, have a look at: https://magento.stackexchange.com/a/74862/243

You have the special case that your third module should be loaded after the second one, but work without it, so you can not depend on it.

The following workaround should do the trick: Write the module definition file for the second module like this:

<config>
    <modules>
        <Test1_Module2>
            <active>true</active>
            <codePool>local</codePool>
        </Test1_Module2>
        <Test1_Module3>
            <depends>
                <Test1_Module2 />
            </depends>
        </Test1_Module3>
    </modules>
</config>

Since all XML files in app/etc/modules are merged before they are evaluated, this will add the dependency from module 3 to module 2, but only if module 2 is installed. If module 2 is installed, but module 3 not, it should not be a problem because the XML above itself does not activate module 3.


Simple and stupid alternative: Name the modules in alphabetical order.

  • It does not require depends code in XML file bcoz if module2 not present and installed module3 in test1 package it throws error so solution is magento already execute alphabetically order. – Niraj Patel Mar 16 '16 at 10:28
  • read carefully: the depends declaration goes into the XML file of module2 – Fabian Schmengler Mar 16 '16 at 10:31
  • Oh sry.it my mistake.your code in module2 XML. Yes exactly what I want. It solved thanks @fschmengler – Niraj Patel Mar 16 '16 at 10:38

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.