0

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?

0

STw,i don't thought that using core_block_abstract_to_html_after event,using !$block instanceof Mage_Page_Block_Html_Pager ,you did not get any product collection,because of:

For every product collection ,pager block does not called like related product collection at product details page, crossell products at checkout page.

So suggestion to use different for example:

Search & category pages,you can use: catalog_block_product_list_collection

Also,you use catalog_product_collection_load_after event which is called at every product collection.But just be carefull that You need fire this event for only frontend Area. other

<config>
    <frontend>
        <events>
            <catalog_product_collection_load_after>
                <observers>
                    <namespace_module>
                        <class>namespace_module/observer</class>
                        <method>someMethod</method>
                    </namespace_module>
                </observers>
            </catalog_product_collection_load_after>
        </events>
    </frontend>
</config>

Note: that is my thought.

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.