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.


20 comments

  1. 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?

  2. @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)

  3. 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?

  4. 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.

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

  6. 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.

  7. 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.

  8. 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)

  9. 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. 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.

  11. 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.

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

  13. Which page I need to add below code?

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

  14. 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.

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <blockquote cite=""> <code> <del datetime=""> <em> <s> <strike> <strong>. You may use following syntax for source code: <pre><code>$current = "Inchoo";</code></pre>.