Magento 1.8 – Can a Core Module Depend on a Custom Module?

event-observermagento-1.8

I'm tying into the event catalog_block_product_list_collection to add additional sort options onto the collection. However, the class Mage_Review_Model_Observer is also listening to this event. The observed function, catalogBlockProductCollectionBeforeToHtml, loads the product collection and prevents me from making additional changes. Because this observer is inside core, it always fires first.

I would like to make my observer fire before the core observer, and I believe this can be accomplished by making the core module depend on my custom module. Is this possible?

I'm open to other approaches to solving this as well; there are no other relevant events that I've seen to tie into.

Best Answer

I think you can use dependancy concept for this .

Suppose your module be Yoursite_Yourmodule. Then use the following code in the location app/etc/Yoursite_Yourmodule.xml

<config>
    <modules>
        <Yoursite_Yourmodule>
            <active>true</active>
            <codePool>local</codePool>
        </Yoursite_Yourmodule>
        <Mage_Review>
            <depends>
                <Yoursite_Yourmodule />
            </depends>
        </Mage_Review>
     </modules>
</config>

What this code does is, it will make the module Mage_Review depends on your module and hence your module will load bofore the core module does. This will make your observer listen first .

I think this may solve your problem.

Related Topic