简体   繁体   中英

magento event before or after product load from search or home or catalog page

I need a magento event/observer which call before/after product loads. I want to change/append product name by that observer.

I used catalog_product_load_after event ,

but it does not work, when you load product from search, and also it does not call to products which are on home page like best selling product etc.

basically a function/observer/event which call every time when product load in magento frontend whether it loads on home page or search page.

The catalog_product_load_after event is valid and will fire every time a product loads. If it's not firing when you think it should a product isn't loading or the event has been altered by customisations to your store.

Importantly, note that the catalog_product_load_after event will not fire if you are loading a product collection (as in this case you are of course not loading a product but a collection containing products). Category and search results pages don't load each product individually but load a filtered product collection which is why you are not seeing the event fire. You may way to instead consider using the event catalog_product_collection_load_after which will allow you to pull the collection and iterate through it from inside the observer method.

<?php
class NameSpace_Module_Model_Observer
{
    public function observerMethod($observer)
    {
        foreach ($observer->getCollection() as $product):
            ...
        endforeach;
    }
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM