I am trying to get product reviews filtered by Product Id, but in the product which doesn't have any reviews added, the reviews count still shows 2 reviews.
This means review collection filter by Product Id isn't working.
Below is the code I am using to get Review collection.
<?php
$_product = $this->getProduct();
$productId = $_product->getId();
$reviews = Mage::getModel('review/review')->getResourceCollection()
->addStoreFilter(Mage::app()->getStore()->getId())
->addEntityFilter('product', $productId)
->addStatusFilter(Mage_Review_Model_Review::STATUS_APPROVED)
->setDateOrder()
->addRateVotes();
$avg = 0;
$ratings = array();
if (count($reviews) > 0){
foreach ($reviews as $_review): ?>
<?php foreach( $_review->getRatingVotes() as $_vote ): ?>
<?php $ratings[] = $_vote->getPercent(); ?>
<?php endforeach; ?>
<?php endforeach;
$avg = array_sum($ratings)/count($ratings); }
?>
Can somebody let me know what might be going wrong with this ?