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;
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With