1

I would like to get the product(Id)'s on a searchresult page in an observer which runs after the initial page render. But I can't seem to get it. The results are fetched by: \Mage_Catalog_Block_Product_List::_getProductCollection

But I don't know how to get that in an observer.
Does anybody know how to do that.

2

The current loaded product collection on category and searchresult pages can be accessed via

Mage::getSingleton('catalog/layer')->getProductCollection();

or, optionally

Mage::registry('current_layer')->getProductCollection();

[EDIT] Preferred to use the registry.

That will return the appropriate model depending on the page you're on. Mage_Catalog_Model_Layer for catalog and Mage_CatalogSearch_Model_Layer for search

(Thanks for @janw for clearing that up)

| improve this answer | |
  • Hi @sander, thanks for the quick reply. It doesn't work entirely. If I do Mage::getSingleton('catalog/layer')->getProductCollection()->getAllIds() It appears to return all id's almost all available products on the store. – janw Sep 7 '15 at 12:08
  • What event are you using? – Sander Mangel Sep 7 '15 at 12:10
  • No wait, the Mage::registry('current_layer')->getProductCollection()->getAllIds() does work. Both return different models. Mage_Catalog_Model_Layer vs Mage_CatalogSearch_Model_Layer – janw Sep 7 '15 at 12:23
  • ah right. makes sense :) so it works? – Sander Mangel Sep 7 '15 at 12:24
  • Yes it works. What also works is: Mage::getSingleton('catalogsearch/layer') If you could update your answer I'll accept – janw Sep 7 '15 at 12:25

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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