2

This question already has an answer here:

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?

marked as duplicate by Fabian Schmengler, 7ochem, saravanavelu, Rajeev K Tomy, Adi Sep 18 '15 at 9:14

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

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'

  • it would be helpful to add which would fire first, A or B. – hownowbrowncow Nov 14 '14 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.