I need to get Product review summery in magento2 programtically how to get it ?
2 Answers
in list page you can use
if ($block->getMode() == 'grid') {
$viewMode = 'grid';
$image = 'category_page_grid';
$showDescription = false;
$templateType = \Magento\Catalog\Block\Product\ReviewRendererInterface::SHORT_VIEW;
} else {
$viewMode = 'list';
$image = 'category_page_list';
$showDescription = true;
$templateType = \Magento\Catalog\Block\Product\ReviewRendererInterface::FULL_VIEW;
}
<?php echo $block->getReviewsSummaryHtml($_product, $templateType); ?>
And Product Detail page You can use
echo $this->getLayout()->createBlock("Magento\Catalog\Block\Product\View")->setTemplate("Magento_Catalog::product/view/review.phtml")->toHtml();
use below code .
$productid=1226;
$product=$this->_objectManager->create("Magento\Catalog\Model\Product")->load($productid);
$RatingOb=$this->_objectManager->create("Magento\Review\Model\Review");
$RatingOb=$this->_objectManager->get("Magento\Review\Model\ReviewFactory");
$RatingOb->create()->getEntitySummary($product, 1);
print_r($product->getRatingSummary());
print_r($product->getRatingSummary()->getRatingSummary());