0

I trying to look for a solution to show Rating Star on the Product Page, like the Product List Page. I tried adding it by creating a new Block on catalog_product_view.xml but not working
Rating Star on Product List Page
Rating Star on Product List Page


Please help me with the solution for it, thank you!

1 Answer 1

0

Yep. I resolved my solution . This is my code .

  1. Create catalog_product_view.xml on your theme.
    Add Block

<block class="Magento\Catalog\Block\Product\View\Attributes" name="product.info.review.short"template="Magento_Catalog::product/view/review_short.phtml"/>


Create new file **review_short.phtml** on templates/view/review/ . Add code :
<?php
 /**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/

/** @var $block Magento\Catalog\Block\Product\View\Attributes */

$listBlock= $block->getLayout()- 
>createBlock(Magento\Catalog\Block\Product\ListProduct::class);
$templateType = 
\Magento\Catalog\Block\Product\ReviewRendererInterface::SHORT_VIEW;

$_product = $block->getProduct();
if (!$_product instanceof \Magento\Catalog\Model\Product) {
return;
}
?>
<?= $listBlock->getReviewsSummaryHtml($_product, $templateType) ?>


Done.
enter image description here

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.