开发者

Product list event for prices?

I'm trying to discover how to configure an Observer to check when magento calls the prices when listing the products under categories/search results, but I can't find any clue about at the m开发者_StackOverflowoment.

Anyone had this need before and can give me some pointers?

I'm using Magento 1.6.0.0.


One way you can do this is by observing the collection_load_after event for catalog products:

        <catalog_product_collection_load_after>
            <observers>
                <Your_Module_Observer>
                    <type>model</type>
                    <class>your_module/Observer/class>
                    <method>modifyPrices</method>
                </Your_Module_Observer>
            </observers>
        </catalog_product_collection_load_after>

You can then loop through the collection and get the prices for each product and make changes if you want:

$products = $observer->getCollection();

foreach( $products as $product )
{
    $product->setPrice( $myCustomPrice );
}

Not sure if that's exactly what you are looking for, but hopefully it points you in the right direction.


a general mean is to set an observer for any specific event

see https://magento.stackexchange.com/questions/314/how-to-know-the-magento-event-that-we-want-to-hook

in the module Logevent, the config.xml

 <?xml version="1.0" encoding="UTF-8"?>

 <modules>
<Maticode_Logevent>
    <version>0.1</version>
</Maticode_Logevent>
 </modules>


 <global>
<models>
    <Logevent>
        <class>Maticode_Logevent_Model</class>
    </Logevent>
</models>

<events>


    <controller_action_predispatch>
        <observers>
            <Logevent>
                <type>singleton</type>
                <class>Logevent/observer</class>
                <method>controller_action_predispatch</method>
            </Logevent>
        </observers>
    </controller_action_predispatch>

</events>
</global>

and the Model/observer.php

        <?php

class Maticode_Logevent_Model_Observer {
 public function controller_action_predispatch($observer) {
Mage::log ( $observer->getEvent ()->getControllerAction ()->getFullActionName (),null, 'eventlog.log' );
}

}

This way , in the

    var/log/eventlog.log file  

u can visualize a possible hook on any tested actions

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜