I'm new to magento and i'm currently working on the CE1.9 for work. I'm having trouble to get the average rating of the current category.
$category_id = Mage::getModel('catalog/layer')->getCurrentCategory()->getId();
$category = Mage::getModel('catalog/category')->load($category_id);
$products = Mage::getModel('catalog/product')->getCollection()->addAttributeToSelect('*')->addCategoryFilter($category)->load();
$reviews = array();
foreach ($products as $product) {
$productId = $product->getId();
array_push($reviews, Mage::getModel('review/review')
->getResourceCollection()
->addStoreFilter(Mage::app()->getStore()->getId())
->addEntityFilter('product', $productId)
->addStatusFilter(Mage_Review_Model_Review::STATUS_APPROVED)
->setDateOrder()
->addRateVotes()
);
}
foreach ($reviews as $review) {
$_votes = $review->getRatingVotes()->getFirstItem();
if($_votes->
$totalRating += $_votes->getFirstItem()->getValue();
}
Zend_debug::dump(100 * $totalRating / (5 * $reviews));