I want to add “Show More” link in Review Tab in product detail page in Magento 2. Only want to show 5 reviews at a time
-
15-04-2021 - |
Question
Add "Show More" link in review on product detail page. Only want to show 5 reviews at a time.
Solution
You can achieve by overriding below file.
Step 1: In your module please create file di.xml under path PackageName/Vendor/etc/frontend
<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
<preference for="Magento\Review\Block\Product\View\ListView" type="PackageName\Vendor\Block\Rewrite\Product\View\ListView" />
</config>
Step 2: Please create file ListView.php file under path PackageName/Vendor/Block/Rewrite/Product/View/
<?php
namespace PackageName\Vendor\Block\Rewrite\Product\View;
class ListView extends \Magento\Review\Block\Product\View\ListView
{
protected function _prepareLayout()
{
$toolbar = $this->getLayout()->getBlock('product_review_list.toolbar');
if ($toolbar) {
$toolbar->setAvailableLimit(array(2=>2,4=>4,6=>6))->setShowPerPage(true);
$toolbar->setCollection($this->getReviewsCollection());
$this->setChild('toolbar', $toolbar);
}
return $this;
}
}
You can change setAvailableLimit(array(2=>2,4=>4,6=>6)) according to your need.
Please check and let me know if you have any query.
Licensed under: CC-BY-SA with attribution
Not affiliated with magento.stackexchange