0

To add pagination to a custom product or category collection in my magento store I've created a custom module. I then configure the toolbar, pager etc in my _prepareLayout() function in NameSpace_Module_Block_Collection. The URL of the page the module will be used on is then defined in etc/config.xml like so:

<?xml version="1.0"?>
<config>
    <modules>
        <NameSpace_Module>
            <version>0.1.0</version>
        </NameSpace_Module>
    </modules>
    <frontend>
        <routers>
            <collection>
                <use>standard</use>
                <args>
                    <module>NameSpace_Module</module>
                    <frontName>page-url-goes-here</frontName>
                </args>
            </collection>
        </routers>

My problem though is what if I want to do the above, but on an existing category page - Category X

On my category page: www.website.com/category-x/

I have the display mode set to static block only. The block content is:

{{block type="catalog/navigation" template="xxx/xxxx.phtml"}}

With this page calling a custom category collection

Is it possible to apply pagination to my custom collection but keep my category url page. Ideally I need to do so without using a redirect

2 Answers 2

1

This is how you can set custom toolbar and pager for your custom collection, below is an example shared, I am using this snippet currently.

Set Toolbar and Pager inside your phtml (your file that is to be called inside static block):

/*  Set Toolbar Pagination for Custom Loaded Collection */                              
$toolbar = Mage::getBlockSingleton('catalog/product_list')->getToolbarBlock();
$toolbar->setCollection($_productCollection);

/*  Set Pager   */
$pager = $this->getLayout()->createBlock('page/html_pager', 'custom.pager');
$pager->setAvailableLimit(array($itemsLimit=>$itemsLimit));
$pager->setCollection($_productCollection);
$toolbar->addPagerLimit('grid', 50, 50);
$toolbar->addPagerLimit('grid', 75, 75);
$toolbar->addPagerLimit('grid', 100, 100);
$toolbar->setChild('product_list_toolbar_pager', $pager);
$toolbar->setData('_current_limit', $itemsLimit);

//Set order, define $sortBy and $orderBy
$toolbar->setData('_current_grid_order', $sortBy);
$toolbar->setData('_current_grid_direction', $orderBy);

To display toolbar on top of list, use :

<?php echo $toolbar->toHtml(); ?>

And to display pager on bottom, use :

   <!-- Show Bottom Pagination Toolbar -- PAGER -->
    <div class="toolbar-bottom">
          <div class="toolbar">
            <?php echo $pager->toHtml();?>
          </div>
    </div>  
  • Now you can call static block on a category page
  • Then you can define your file path inside that static block
  • Call your custom collection inside that file and use steps above
  • And That's it :) Enjoy
0

You can't. The Mage_Catalog_Block_Product_List_Toolbar has one parameter name for page, one for direction, etc.

The problem is, the toolbar doesn't have any setters, so there is no way to change this in this class.

But the properties are all protected, so you can extend it and implement your own.

1
  • - Toolbar can be configured for a custom collection. Commented Jul 20, 2017 at 11:01

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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