I'm adding a custom block that will reside on frontend pages which contain a Product List (catalog_category_view
, catalogsearch_result_index
, etc). The block needs to know which products are being displayed to the user.
I hoped to find an equivalent of the current_product
registry item that's used on a product page; however so far I haven't found where I can readily retrieve this.
At the moment I'm handling the core_block_abstract_to_html_after
event and then getting the collection from the Pager block:
public function coreBlockAbstractToHtmlAfter(Varien_Event_Observer $observer)
{
$block = $observer->getEvent()->getBlock();
if (!$block instanceof Mage_Page_Block_Html_Pager) {
return;
}
/** @var Mage_Page_Block_Html_Pager $list */
$list = $block;
$products = $list->getCollection();
Mage::register('current_products', $products);
}
Have I reinvented the wheel? Is there a built-in option, or a better approach?