Question

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

Was it helpful?

Solution

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with magento.stackexchange
scroll top