How to add “View All” button in Magento’s pagination

Hi, I had a bit of unusual request from a client and I had to create “View All” button and put it into Magento’s pagination on category listings, so I decided to share the trick. 😉

So, since this is a very specific task, I believe that no further explanation is needed. And now, lets begin.

First of all, we need to trace the “pager.phtml” file in our working template directory. When you do, all that needs to be added is the following code somewhere to fit your needs:

< ?php echo $this->__('View All') ?>

Now we’ve added our link to pagination. And only thing important here is the following segment of code:

$this->getLimitUrl('all')

This small segment of code generates our link with “limit” parameter set to “all”. Now when we click on it, it will give us a full category listing. The problem with that is that our value of “limit” set to “all” becomes stored permanently (for as long the session lasts). So we need to write just a couple lines of code more to fix it. Now the easiest way is to trace your “Toolbar.php” file in Magento, and to find the _construct() method. By default last line of that method is:

$this->setTemplate('catalog/product/list/toolbar.phtml');

which sets our (edited) template to this model. Just after that line, add the following code:

//ADDED FOR "VIEW ALL" PAGINATION BUTTON
$defaultLimit = $this->getDefaultPerPageValue();
Mage::getSingleton('catalog/session')->setData("limit_page",$defaultLimit);

These two lines of code do the following for us:

1. Takes the default limit from Magento for pagination (set it up through Magento Admin panel)

2. Sets our limit to default value, because if we don’t reset it, it will list all products in all of our categories, when we open them (at least while the session lasts).

So, this is it. I hope it will be helpful for someone. If you find some bumps on the road, we’re here to help with our Magento development services. Feel free to contact us!