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!
20 comments
Well I can see, the tip is great but for sure this won’t work with custom models like automated new products list page.
Any hint how to tackle this over custom models?
Worked for me, version 1.7 CE.
Thank you!
@Max
If you’re not a developer then it might be wise leave the code alone. 😉
If you want to learn more about Magento coding it might be wise start reading the book “Mastering Magento” by Packt Pub.
to find out where toolbar.php is located you can use the command “find” on CLI. (google can help)
I’m not a developer so I dont really know what to do here, im on 1.7 and have access to templates etc and can do code edits no worries but I dont know where to find the toolbar.php file. can you help out on this?
Yes it works
copy page/html/pager.phtml and put anchor there
Copy/rewrite catalog/block/product/list/toolbar.php and add following line at the end of constructor
$defaultLimit = $this->getDefaultPerPageValue();
Mage::getSingleton(‘catalog/session’)->setData(“limit_page”,$defaultLimit);
Third, enable view all option from backend config->catalog.
That’s all. Thanks Mladen.
Thanks Hans for the tip . I manage to solve the problem
Here’s what I did
isLimitCurrent(“all”)):?>
<a href="getLimitUrl($this->getDefaultPerPageValue());?>”>
Show 9 Per Page
getLastPageNum()>1): ?>
<a href="getLimitUrl(‘all’)?>” title=”__(‘ShowAll Products’) ?>”>
__(‘Show All’) ?>
the website you show me is not a Magento website.
your wish – a link to show # amount – is not default Magento, but it is possible.
Learn how to create theme overrides first. After that dig into the toolbar (the place where pagination is placed) and create your override… take a good look at the links created when you alter the amount of items to be shown.
And follow the instructions from this tutorial.
Hi This is great stuff
but how do I add a link to show ‘ View 9 per page’ once I’m on View All just like this example on asos.com
http://www.asos.com/Men/Bags/Cat/pgecategory.aspx?cid=9265#parentID=-1&pge=0&pgeSize=200&sort=-1
at the time of writing this blogpost the option was not available in Magento. I can confirm for Magento 1.6.2.0 this option is available in now.
System >> Configuration >> Catalog >> Catalog >> Frontend >> “Allow All Products per Page” Set to Yes.
Hello!
Excellent work!
How to make that choice would be after the pagination did not disappear. And you can select the map again, wc standard paging (1 2 … 3 4)
Thanks For saving my time
I need add the link view all in top navigation menu, when we made a click on view all link it should display all products list.
Instead of modifying core files we can just put the limit reset code at the top of our pager.html or where ever you put a View All link.
Hi,
This is great post, it actually helped me. I had the same exact request from a client.
Thanks
OK – managed to get it working…what you forgot to mention is that you need to go into the Configuration for the Catalog and make sure that “Allow All Products Per Page” is set to ‘yes’ otherwise the system won’t allow you to show them, regardless of what you write in the query string.
Unfortunately your code didn’t work 🙁 I don’t understand why this isn’t a built in feature of Magento…
Which page I need to add below code?
$defaultLimit = $this->getDefaultPerPageValue();
Mage::getSingleton(‘catalog/session’)->setData(“limit_page”,$defaultLimit);
Yes, this works perfect! Thanks a lot for putting a tutorial on this!
In which file does the code: $this->getLimitUrl(‘all’) go?
Great tip! Your post saved me a lot of time in implementing a similar client request. One clarification that may help others… the pager.phtml file you need to edit is under the template/page/html directory. I initially tried to edit the one under template/catalog/product/list/toolbar.