4

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.

2 Answers 2

8

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.

2
  • My favorite example of how extensible Magento is.
    – philwinkle
    Mar 19, 2014 at 18:21
  • Oh! I thought I had to declare the dependency for a module inside that module's XML. Being able to do it from my custom XML is a great solution!
    – Ryre
    Mar 20, 2014 at 17:34
2

As noted by programmer_rkt, dependencies are one way to handle observer processing order by affecting the order in which the configuration files are merged.

Another strategy would be to take the loaded product collection, reset it, and unshift your sort order onto it:

$coll->clear()->unshiftOrder(/*your params*/);
4
  • 1
    Who actually reads the body of the question? I only answer based on the title.
    – philwinkle
    Mar 19, 2014 at 20:15
  • how can we know order number of a modul then ? @benmarks Mar 20, 2014 at 0:48
  • 1
  • Thanks @benmarks. Your solutions always enlighten me. I was unaware you can "unload" collections with clear!
    – Ryre
    Mar 20, 2014 at 17:38

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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