2

I need to get Product review summery in magento2 programtically how to get it ?

2 Answers 2

3

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();
0

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());

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.