I listen to this event: catalog_product_load_after and I need to retrieve the products id, I know I can retrieve the products' id with:

$collection = Mage::registry('current_category')

But it doesn't look so convenient if the category has a lot of products, since this will run each time you change the page, so I wonder if there is a way to limit the products to be retrieved only to the current page.

Side question: $collection is just an array of numbers or I still need to loop through each element and run $product->getId()?

What I need to do is manipulate the "add to cart" button of category and product pages according to some information, as far as I know I can do this only after the html of the page has been created
The information can be retrieved witht the product id, so I wonder if there is a way to limit the number of id that will be checked.
Inside the function I have also this:

if ($block instanceof Mage_Catalog_Block_Product_View) {..}
else if ($block instanceof Mage_Catalog_Block_Category_View){..}

What I have tried:

$collection = Mage::registry('current_category')->getProductCollection()

Unfortunately $currentPage and $currentSize are empty

I have tried:

$collection =  $observer->getProduct();;
Mage::log($collection, null, 'mylogfile.log');

but the log file is empty:

2015-05-17T18:22:37+00:00 DEBUG (7): 

I have also tried:

$collection = $observer->getEvent()->getCollection()
$collection = $observer->getCollection()

First I tried:

Mage::log(var_dump($observer), null, 'mylogfile.log');

but it printed the object on the frontend and it was unreadable,then i tried:

Mage::log(var_export(array_keys( $observer->getData() ), TRUE),NULL,'mylogfile.log');

that returned:

array (
  0 => 'event',
  1 => 'block',
  2 => 'transport',


Mage::log(var_export($observer->debug(), TRUE), null, 'mylogfile.log');

and this is the result:

array (
  'event (Varien_Event)' => 
  array (
    'block (Mage_Catalog_Block_Category_View)' => 
    array (
      'type' => 'catalog/category_view',
      'current_category (Mage_Catalog_Model_Category)' => 
      array (
        'store_id' => '1',
        'entity_id' => '3',
        'entity_type_id' => '3',
        'attribute_set_id' => '3',
        'parent_id' => '2',
        'created_at' => '2014-08-12T08:47:07-04:00',
        'updated_at' => '2015-01-04 18:49:11',
        'path' => '1/2/3',
        'position' => '1',
        'level' => '2',
        'children_count' => '11',
        'name' => 'Dermocosmesi',
        'url_key' => 'test',
        'display_mode' => 'PRODUCTS',
        'url_path' => 'test.html',
        'is_active' => '1',
        'include_in_menu' => '1',
        'is_anchor' => '1',
        'custom_use_parent_settings' => '0',
        'custom_apply_to_products' => '0',
        'path_ids' => 
        array (
          0 => '1',
          1 => '2',
          2 => '3',
      'module_name' => 'Mage_Catalog',
    'transport (Varien_Object)' => 
    array (
      'html' => 'HTML',
    'name' => 'core_block_abstract_to_html_after',
  'block (Mage_Catalog_Block_Category_View)' => '*** RECURSION ***',
  'transport (Varien_Object)' => '*** RECURSION ***',

Products ids associated with this category: 1,2, but only one product per page is displayed and so only one of those two should be retrieved

  • You should describe the problem you're trying to solve. The event you're listening to and the action you're describing don't really make sense. The event will fire for every product that's loaded in any context but you're working with the current category in the registry. The return type of getProductCollection is Mage_Catalog_Model_Resource_Product_Collection which is traversable, one of its parent classes implements IteratorAggregate.
    – beeplogic
    Commented May 17, 2015 at 15:13
  • @beeplogic I have added some information
    – Razorphyn
    Commented May 17, 2015 at 15:21

1 Answer 1


In this example, we capitalize the product name after its get loaded in the front-end.


class Pixlpitch_ExampleObserver_Model_Observer
    public function catalogProductLoadAfter(Varien_Event_Observer $observer)
        return $_product->setName(strtoupper($_product->getName()));

catalog_product_load_after is the event fired when the product is loaded. So the observer needs to listen to that event and carry out it functions.

The event is fired on the front-end. So this would not affect the product load in the backend. If you need the observer to listen product_load_after event in the backend, change the “” to “”. To listen on both backend and front-end, change it to “”.

The method listening to the event is catalogProductLoadAfter(). In this method we get the product object, retrieve the name and capitalize it.

<?xml version="1.0"?>


<?xml version="1.0"?>


    <frontend>  <!-- global | adminhtml | frontend -->
            <catalog_product_load_after>   <!-- event name -->
                        <type>model</type>     <!-- model | singleton -->
  • I didn't know about catalog/layer, however I need the products id, but this return the category one
    – Razorphyn
    Commented May 17, 2015 at 15:53
  • oky. see this Magento Load Product event observer Commented May 17, 2015 at 16:53
  • I have tried $observer->getData('product'), but it looks like it is empty...
    – Razorphyn
    Commented May 17, 2015 at 17:22
  • use ` $observer->getProduct();` instated $observer->getData('product') Commented May 17, 2015 at 18:16
  • Still doesn't work, I have updated the asnwer with some tries
    – Razorphyn
    Commented May 17, 2015 at 18:23

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