在 Magento 1.9 CE 中获取当前类别的平均评分

Get average rating of the current category in Magento 1.9 CE

我是 magento 的新手,目前正在为工作开发 CE1.9。我无法获得当前类别的平均评分。有人可以帮助我吗?

$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();
    $totalRating += $_votes->getFirstItem()->getValue();
}
Zend_debug::dump(100 * $totalRating / (5 * $reviews));

我是不是漏掉了什么?

提前致谢

好的,我自己解决了

有兴趣的朋友,这里是代码:

    $categoryId = Mage::getModel('catalog/layer')->getCurrentCategory()->getId();
    $currentCategory = Mage::getModel('catalog/category')->load($categoryId);
    $productList = Mage::getModel('catalog/product')->getCollection()->addAttributeToSelect('*')->addCategoryFilter($currentCategory)->load();
    $reviewList = array();
    $storeId = Mage::app()->getStore()->getId();
    foreach ($productList as $product) {
        $summaryData = Mage::getModel('review/review_summary')->setStoreId($storeId)->load($product->getEntityID());
        $reviewData[] = $summaryData['rating_summary'] / 20;
    }
    $nbReview = 0;
    foreach ($reviewData as $review) {
        if ($review != Null)
            $nbReviews++;
            $totalReviewIntoStar += $review;
    }
    return $AvgRating = $totalReviewIntoStar / $nbReviews;