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

Featured Image

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:

<a href="<?php echo $this->getLimitUrl('all')?>" title="< ?php echo $this->__('View All Products') ?>">
< ?php echo $this->__('View All') ?>
</a>

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.

16
Top

Enjoyed this post?

Subscribe to our RSS Feed, Follow us on Twitter and spread it to your friends!

Author

Mladen Lotar

Ex. Inchooer

Mladen worked at Inchoo from 2010 to 2011 in the role of Magento/Zend developer

Other posts from this author

Discussion 16 Comments

Add Comment
  1. 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.

  2. craig

    In which file does the code: $this->getLimitUrl(‘all’) go?

  3. Igor

    Yes, this works perfect! Thanks a lot for putting a tutorial on this!

  4. Darpan

    Which page I need to add below code?

    $defaultLimit = $this->getDefaultPerPageValue();
    Mage::getSingleton(‘catalog/session’)->setData(“limit_page”,$defaultLimit);

  5. Michael

    Unfortunately your code didn’t work :( I don’t understand why this isn’t a built in feature of Magento…

  6. Michael

    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.

  7. Hi,

    This is great post, it actually helped me. I had the same exact request from a client.

    Thanks

  8. Samuel

    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.

  9. shravan

    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.

  10. Thanks For saving my time

  11. Vladimir

    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)

  12. Hans Kuijpers

    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.

  13. hisham

    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

  14. Hans Kuijpers

    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.

  15. hisham

    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’) ?>

  16. Deepak

    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.

Add Your Comment

Please wrap all source codes with [code][/code] tags.
Top