cancel
Showing results for
Did you mean:

SOLVED

## Get the average rating of the current category

Hi guys!

I'm actually a noob on magento cms.

Can someone tell me how to get the average rating of the current category?

that's what I did :

```	\$category_id = Mage::getModel('catalog/layer')->getCurrentCategory()->getId();

\$reviews = array();

foreach (\$products as \$product) {
\$productId = \$product->getId();
array_push(\$reviews, Mage::getModel('review/review')
->getResourceCollection()
->setDateOrder()
);
}

foreach (\$reviews as \$review) {
}
Zend_debug::dump(100 * \$totalRating / (5 * \$reviews));```

Did I miss something?

3 REPLIES

## Re: Get the average rating of the current category

Okay, I solved it myself.

For those interested, here is the code:

```        \$categoryId = Mage::getModel('catalog/layer')->getCurrentCategory()->getId();
\$reviewList = array();
\$storeId = Mage::app()->getStore()->getId();
foreach (\$productList as \$product) {
\$reviewData[] = \$summaryData['rating_summary'] / 20;
}
\$nbReview = 0;
foreach (\$reviewData as \$review) {
if (\$review != Null)
\$nbReviews++;
\$totalReviewIntoStar += \$review;
}
return \$AvgRating = \$totalReviewIntoStar / \$nbReviews;```

## Re: Get the average rating of the current category

Hi @anthony_ip,

Are you using that calc everytime the category is rendered?

In taht case, did you see some performance issue?

--
If you've found one of my answers useful, please give "Kudos" or "Accept as Solution"

## Re: Get the average rating of the current category

I indeed use this calc in each render.

I didn't check the perf