1

I have created review form as popup modal, And I have also removed reviews tab in product page. And I have created new section before footer which contains the collection of customer reviews which is shown in frontend, Now I need to Limit the reviews via xml, Please provide me a solution

Catalog_product_view.xml

<page layout="1column" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
    <body>
        <referenceBlock name="product.info.review">
            <action method="setTemplate">
                <argument name="template" xsi:type="string">XXX_YYY::review.phtml</argument>
            </action>
            <!--To display popup and form-->
            <block class="Magento\Review\Block\Form" name="custom.review.popup" template="XXX_YYY::popup.phtml">
                <block class="Magento\Review\Block\Form" name="custom.product.review.form" as="custom.review_form" template="XXX_YYY::form.phtml">
                    <container name="product.review.form.fields.before" as="form_fields_before" label="Review Form Fields Before"/>
                    <arguments>
                        <argument name="jsLayout" xsi:type="array">
                            <item name="components" xsi:type="array">
                                <item name="review-form" xsi:type="array">
                                    <item name="component" xsi:type="string">Magento_Review/js/view/review</item>
                                </item>
                            </item>
                        </argument>
                    </arguments>
                </block>
            </block>
        </referenceBlock>
        <!--Removes the review tab-->
        <referenceBlock name="product.info.details">
            <referenceBlock name="reviews.tab" remove="true" />
        </referenceBlock>
        <!--Display Customer reviews collection-->
        <referenceContainer name="product.info.additional">
            <block class="Magento\Review\Block\Product\View\ListView"  name="custom.product.section.info" template="XXX_YYY::customer-reviews.phtml"/> 
        </referenceContainer>
    </body>
</page>
1

Override Magento\Review\Block\Product\View\ListView file using di.xml with below code:

/**
 * Prepare product review list toolbar
 *
 * @return $this
 */
protected function _prepareLayout()
{
    parent::_prepareLayout();
    $toolbar = $this->getLayout()->getBlock('product_review_list.toolbar');
    if ($toolbar) {
        $toolbar->setLimit(1);
        $collection = $this->getReviewsCollection();

        $toolbar->setCollection($collection);
        $this->setChild('toolbar', $toolbar);
    }

    return $this;
}

Note: all protected methods should which rquired to use should be in your class. Remove toolbar code from xml which is in Magento_Review > module > view -> frontend > layout > catalog_product_view.xml

  • Can you explain the above code – Jaisa Dec 21 '17 at 5:30
  • I need to display only 10 reviews in product page – Jaisa Dec 21 '17 at 5:30
  • 10 limit is default , you can remove toolbar so it will so only 10 reviews – Ronak Chauhan Dec 21 '17 at 5:54
  • If I need to displaymore than 10 reviews means what would /i do – Jaisa Dec 21 '17 at 6:21
  • use $toolbar->setLimit(15); to set limit – Ronak Chauhan Dec 21 '17 at 6:47

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.