5

Using an observer how can i get the current pager block with its loaded product collection on a category page?

I want to check the total number of pages on a category page before it is loaded.

5

You could try listening to the event core_block_abstract_to_html_before and then checking if the block given is of instance Mage_Page_Block_Html_Pager.

This block has a function getCollection which would give you the current collection and the function getPages which will give you an array of all the page ids.

public function coreBlockAbstractToHtmlBefore(Varien_Event_Observer $observer) {
    $block = $observer->getBlock();
    if($block instanceof Mage_Page_Block_Html_Pager) {
        $collection = $block->getCollection();
        $pages = $block->getPages();
    }
}

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.