Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 672
mahesh kajale Avatar asked Jan 14 '23 14:01

mahesh kajale


1 Answers

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;
    }
}
like image 131
Jonathan Hussey Avatar answered Jan 25 '23 23:01

Jonathan Hussey