2

I'll explain my question through an example.

Assume I have written two custom modules as A and B. And both the modules are having observer functions which fires once click on the 'Place Order button in checkout flow. (Assume both observer functions fires at same event)

Assume each module's observer functions are 'a' and 'b'

So my question is how can I know which observer function will get invoked first ('a' or 'b')?

Is there any specific order? Or is there any possibility to inform Magento that we want to invoke method 'b' first and method 'a' next likewise?

0

2 Answers 2

3

Try Use <depends>

Eg

File: app/etc/modules/Company_A.xml

<config>
    <modules>
        <Company_A>
            <active>true</active>
            <codePool>core</codePool>
            <depends>
                <Mage_Core />
            </depends>
        </Company_A>
    </modules>
</config>

File: app/etc/modules/Company_B.xml

<config>
    <modules>
        <Company_B>
            <active>true</active>
            <codePool>core</codePool>
            <depends>
                <Company_A />
            </depends>
        </Company_B>
    </modules>
</config>

Update

According to How do you set the sort order for event observers in Magento?

There is not way to explicitly set an observer sort order. Magento will run through the events in the order they've been merged into the global configuration. So, while you can't control the order of event specifically, you can control the order Magento loads and merges modules in by using the <depends/> tag in your app/etc/modules XML declaration file

Therefore the order above should be 'core', 'A' then 'B'

1
  • it would be helpful to add which would fire first, A or B. Nov 14, 2014 at 19:28
0

Although I have not tested it I would guess that the observers are fired in the order the modules are actually loaded - so either alphabetically if one does not depend on the other, or according any relevant <depends> entry in the relevant app/etc/modules/ config.

Not the answer you're looking for? Browse other questions tagged or ask your own question.