2

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

1 Answer 1

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

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

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.