adampmoss / CreareSEO

A free SEO extension for Magento 1
GNU General Public License v2.0
151 stars 72 forks source link

AggregateRating is off when a review is made without a rating #116

Closed JamesFX2 closed 6 years ago

JamesFX2 commented 6 years ago

https://github.com/adampmoss/CreareSEO/blob/master/app/design/frontend/base/default/template/creareseo/product/schema.phtml#L81

$ratingValue = round($_totalAverageRating/$this->getReviewsCount(), 1)

You're going to need to increment the number of reviews when you do if ($_averageRating >= 1) on line 69 rather than use the number of reviews. It's throwing off the data!

sprankhub commented 6 years ago

I do not really get the issue. Could you elaborate and maybe directly propose a solution / do a pull request?

JamesFX2 commented 6 years ago

You can submit a review without a rating in Magento. As in just a comment - not 1/5, not 0/5, just no rating whatsoever. For that matter, Magento doesn't let you rate an item as 0/5 (AFAIK).

So you have 2 reviews.

The current code loops through the reviews and increments the $_totalAverageRating variable. In this hypothetical example, $_totalAverageRating is 4.

->getReviewsCount() would return 2.

4 divided by 2 is an AggregateRating of 2. It should be 4. getReviewsCount gives you the number of reviews, not the number of reviews where they included a rating.

Instead of using a method that returns a count of reviews, you'll need to create another variable and increment that when (during the foreach loop) when there's a review with ->getAverageRating($review->getReviewId()) >= 1.

sprankhub commented 6 years ago

Thanks, now I got it! Working on it.