Magento – Get product review stars

magento-1.9product-review

On the homepage I have a section where I load some products of a certain category. I want to display the review stars of a product below the title if the product has review. Normally I do this with the following code:

<?php if($_product->getRatingSummary()): ?>
    <?php echo $this->getReviewsSummaryHtml($_product, 'short') ?>
<?php endif; ?>

But that doesn't display the stars, when I delete the IF statement around it, it will display the stars but also for the products that doesn't have reviews…

Did I do something wrong? Maybe a setting somewhere I don't know about?

Magento version: 1.9.3.4

Best Answer

Hope below will helps to you for rating

$_reviews = Mage::getModel('review/review')
            ->getResourceCollection()
            ->addStoreFilter(Mage::app()->getStore()->getId())
            ->addStatusFilter(Mage_Review_Model_Review::STATUS_APPROVED)
            ->setDateOrder()
            ->addRateVotes();
foreach($_reviews as $review){
    $product = Mage::getModel('catalog/product')->load($review->getData('entity_pk_value'));
$j=0;
$cumulative = 0;
foreach( $review->getRatingVotes() as $vote ) {
    $cumulative +=$vote->getPercent();
    $j++;
}

$finalPercentage = 0;
if ($cumulative != 0){
    $finalPercentage = ($cumulative/$j);
}
}
Related Topic