1

I am trying to override summary.phtml file so I can change the functionality of the review button which is below product title, ex:'3 reviews' & 'add new review'.

File: summary.phtml

File Path:

Magento/module-review/view/frontend/templates/helper/summary.phtml

I already override form.phtml to customize my review form, so here is my xml.

File: default.xml

File Path:

SimpleMagento/ReviewCustomer/view/frontend/layout/default.xml

<referenceContainer name="content">
   <referenceBlock name="product.review.form">
      <action method="setTemplate">
        <argument name="template" xsi:type="string">SimpleMagento_ReviewCustomer::form.phtml</argument>
      </action>
   </referenceBlock>
   <referenceBlock name="product.info.review" >
      <arguments>
          <argument name="template" xsi:type="string">SimpleMagento_ReviewCustomer::helper/summary.phtml</argument>
      </arguments>
   </referenceBlock>
</referenceContainer>

override summary.phtml File Path:

SimpleMagento/ReviewCustomer/view/frontend/templates/helper/summary.phtml

after many try its still load core summary.phtml file, not mine. What I am doing wrong? Thanks

8
  • In which xml file you found product.info.review block ? you have mention this name reference block
    – user55548
    Commented Dec 11, 2019 at 11:17
  • @user55548 I am following answer: magento.stackexchange.com/questions/186431/… Commented Dec 11, 2019 at 11:18
  • In this answer, you can see in comment section problem is not solve. You can not use any name in reference block. This should be available. Try to use any existing block name.
    – user55548
    Commented Dec 11, 2019 at 11:23
  • @user55548 can I use product.review.form which I already use? Commented Dec 11, 2019 at 11:27
  • yes, check with that.
    – user55548
    Commented Dec 11, 2019 at 11:29

1 Answer 1

4

You can do this by plugin using this below way :

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

<?xml version="1.0"?>
<!--
/**
 * Copyright 2015 Magento. All rights reserved.
 * See COPYING.txt for license details.
 */
-->
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../../../../../lib/internal/Magento/Framework/ObjectManager/etc/config.xsd">
    <type  name="Magento\Review\Block\Product\ReviewRenderer">
       <plugin name="custom_review_template" sortOrder="20" disabled="false" type="Vendor\Module\Plugin\CustomReviewRender"/>
    </type>
</config>

app/code/Vendor/Module/Plugin/CustomReviewRender.php

<?php
/**
 * Copyright © Magento, Inc. All rights reserved.
 * See COPYING.txt for license details.
 */
namespace Vendor\Module\Plugin;

class CustomReviewRender {

    /**
     * @var \Magento\Framework\App\Request\Http
     */
    protected $request;

    /**
     * @param \Magento\Framework\App\Request\Http $request
     */
    public function __construct(
        \Magento\Framework\App\Request\Http $request
    ) {
        $this->request = $request;
    }

    public function beforeSetTemplate(
        \Magento\Review\Block\Product\ReviewRenderer $subject,
        $result
    ) {
        if ($this->request->getFullActionName() == 'catalog_product_view') {
            return 'Vendor_Module::custom_summary.phtml'; // For product view page => In core Magento_Review::helper/summary.phtml display
        }
        if ($this->request->getFullActionName() == 'catalog_category_view') {
            //return 'Vendor_Module::custom_short_summary.phtml';
            return $result; // For product listing page => In core Magento_Review::helper/summary_short.phtml display
        }
        return $result;
    }

}

Now, create phtml file based on your requirement.

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.