Reputation: 2553
I'd like to get hold of a product's Rating Score (e.g. 4 out of 5) and number of reviews the product has. I can get hold of the number of reviews, but not the rating score.
I'm doing this from my event observer class:
$storeId = Mage::app()->getStore()->getId(); // returns 1
$productId = $product->getId(); // returns 135
$summaryData = Mage::getModel('review/review_summary')->setStoreId($storeId)->load($productId); // returns
$reviewsCount = $summaryData->getReviewsCount(); // this works
$ratingSummary = $summaryData->getRatingSummary(); // this does not return the rating score I had hoped it would. It just returns a blank string.
Thanks for any help.
Upvotes: 1
Views: 5807
Reputation: 14182
Your code tested on Magento 1.4.2, 1.5.1 and 1.6.1 works as expected. The only difference to your code is that I hardcode the store ID and the product id. A loop over all products with a review works as well, too:
<?php
$products = Mage::getResourceModel('catalog/product_collection');
foreach ($products as $product)
{
$summary = Mage::getModel('review/review_summary')
->setStoreId(Mage::app()->getStore('default')->getId())
->load($product->getId());
if ($summary->getId())
{
echo $summary->getRatingSummary() . "\n";
}
}
Have you checked the expected results in the review_entity_summary
table for the entity 135?
Upvotes: 3
Reputation: 1650
Are you calling reviews code in a loop? If so take a look at _initReviewsHelperBlock
method in Mage_Catalog_Block_Product_Abstract
class. It returns false when initialized for the second time
Still to confirm this is a bug, but had to rewrite the class in the local
pool
Upvotes: 0