If my web pages show many products (include title and rating), then web page needs to calculate rating percentage by every products with following code.
I am sure this kinds of calculation will slow down my web page.
Is this the only choice that i can choose, or is there any better performance code that i can use?
if (count($reviews) > 0)
{
foreach ($reviews->getItems() as $review)
{
foreach( $review->getRatingVotes() as $vote )
{
$ratings[] = $vote->getPercent();
}
}
$avg = array_sum($ratings)/count($ratings);
}
3
Answers
you can used this code, magento use same code on category list page.
You need to just pass your
$product
object in this code.You can use review model of Magento’s core
You can use below code to get rating on any page: