0

I want to set pagination in product review tab. So if I have 30 reviews for particular product, then in reviews tab I want the pagination from 1 to 5 with next and previous buttons and in all pages I want to show only 5 review/page.

On this path vendor/magento/module-review/Block/Product/View I got block file ListView.php. File code is below.

protected function _prepareLayout()
{
    parent::_prepareLayout();

    $toolbar = $this->getLayout()->getBlock('product_review_list.toolbar');
    if ($toolbar) {
        $toolbar->setCollection($this->getReviewsCollection());
        $this->setChild('toolbar', $toolbar);
    }

    return $this;
}

Above is the review collection code so how to change this code so I can set pagination?

4 Answers 4

3
Magento 2 Default provide Pagination in Review Tab. If you want to Set Limit in review than change in below file.  
   vendor/magento/module-theme/Block/Html/Pager.php

find Below Code in Pager.php

 protected $_availableLimit = [10 => 10, 20 => 20, 50 => 50];

Replace With 

 protected $_availableLimit = [5 => 5, 10 => 10, 25 => 25];

It's Working to Set Limit in Review Tab.

0
1

All of the solutions above assume that you will never update, or reinstall your magento.

You shouldn't edit anything in vendor directory. Ever!

There are better solutions. In your specific case, you can use that in if statement provided above.

$toolbar->setAvailableLimit([5=>5,10=>10,15=>15]);

Assuming that your collection still haven't been loaded.

If it have been, I would recommend adding plugin overwritting your default layout.

0

You will need to override block file /vendor/magento/module-theme/Block/Html/Pager.php and find code like this:

protected $_availableLimit = [10 => 10, 20 => 20, 50 => 50];

Then you need to add extra limit value (which is 5 in your case) like this:

protected $_availableLimit = [5 => 5, 10 => 10, 20 => 20, 50 => 50];

Please let me know if you have any question.

7
  • this will change the pagination for everything.
    – Marius
    Jul 22, 2016 at 6:07
  • @Marius I only want to set pagination for product reviews tab. how can I do that?
    – Dhaval
    Jul 22, 2016 at 6:20
  • Have you tried it or not? Jul 22, 2016 at 6:25
  • I don't think it will change pagination for every thing because for products there is setting in admin panel and when limit parameter value is set from admin panel (for products), then it will not affect in other places. Jul 22, 2016 at 6:25
  • @MohitKumarArora if I want to add pagination in product reviews tab only then I need to change in above code that I added in my question on anywhere else?
    – Dhaval
    Jul 22, 2016 at 6:45
0

For example you want pagination of 5 per page. Make these changes.

in app/code/Vendor/Module/etc/di.xml

<preference for="Magento\Theme\Block\Html\Pager" type="Vendor\Module\Plugin\UpdatePagerClass" />

and in app/code/Vendor/Module/Plugin/UpdatePagerClass.php

<?php
namespace Vendor\Module\Plugin;

use Magento\Theme\Block\Html\Pager;

class UpdatePagerClass extends Pager
{
    /**
     * Retrieve pager limit
     *
     * @return array
     */
    public function getAvailableLimit()
    {
        $limits=[];
        for($i=4; $i<=100; $i+=5){
            $limits[$i]=$i;
        }
        return $limits;
    }
}

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.