How to change the template in a custom module.
Original path = vendor/magento/module-review/view/frontend/templates/helper/summary.phtml
I want to change this template to my own when my module is enabled ONLY
I have looked at a few tests that I could gather from Online and nothing worked.
the way Magento show this summary.phtml is by this way
protected $_availableTemplates = [
self::FULL_VIEW => 'Magento_Review::helper/summary.phtml',
self::SHORT_VIEW => 'Magento_Review::helper/summary_short.phtml',
];
Can anyone give me some guide or tips to change this template in a custom module.
The core file is coming from magento/module-review/Block/Product/ReviewRenderer.php
/**
* Get review summary html
*
* @param Product $product
* @param string $templateType
* @param bool $displayIfNoReviews
*
* @return string
* @throws \Magento\Framework\Exception\LocalizedException
* @throws \Magento\Framework\Exception\NoSuchEntityException
*/
public function getReviewsSummaryHtml(
\Magento\Catalog\Model\Product $product,
$templateType = self::DEFAULT_VIEW,
$displayIfNoReviews = false
) {
if ($product->getRatingSummary() === null) {
$this->reviewSummaryFactory->create()->appendSummaryDataToObject(
$product,
$this->_storeManager->getStore()->getId()
);
}
if (null === $product->getRatingSummary() && !$displayIfNoReviews) {
return '';
}
// pick template among available
if (empty($this->_availableTemplates[$templateType])) {
$templateType = self::DEFAULT_VIEW;
}
$this->setTemplate($this->_availableTemplates[$templateType]);
$this->setDisplayIfEmpty($displayIfNoReviews);
$this->setProduct($product);
return $this->toHtml();
}
$_availableTemplates
variable in your module via plugin(s).$_availableTemplates
variable is used, some method gets its value. So in that place you can try to use after plugin$_availableTemplates
variable in new class. All other methods will be used from parent, so not a big problem for upgradability.