Take the 2-minute tour ×
Magento Stack Exchange is a question and answer site for users of the Magento e-Commerce platform. It's 100% free, no registration required.

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.

share|improve this question

2 Answers 2

up vote 4 down vote accepted

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.

share|improve this answer
    
My favorite example of how extensible Magento is. –  philwinkle Mar 19 at 18:21
    
yes its my favorite too.. but I didnt get a chance to use this amzing utility in my work yet.:-( @philwinkle –  programmer_rkt Mar 20 at 0:50
    
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! –  Toast Mar 20 at 17:34

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*/);
share|improve this answer
1  
Who actually reads the body of the question? I only answer based on the title. –  philwinkle Mar 19 at 20:15
    
how can we know order number of a modul then ? @benmarks –  programmer_rkt Mar 20 at 0:48
1  
    
Thanks @benmarks. Your solutions always enlighten me. I was unaware you can "unload" collections with clear! –  Toast Mar 20 at 17:38

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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