How to display rating summary in product listing in Magento?

How to display rating summary in product listing in Magento?

July 6, 2026 · Illustrated author avatarBy Stefan Bogdanescu
How to display rating summary in product listing in Magento?

Displaying Rating Summary in Product Listing for Magento

Displaying product ratings on your Magento homepage is an essential feature that can significantly enhance user trust and drive conversions. In this guide, we’ll walk you through the process of loading products from a specific category and displaying their rating summaries.

Loading Products From a Specific Category

First, let’s ensure you have the correct code to load products from a particular category using the provided URL:

// Load your product model
$model = Mage::getModel('catalog/product');

// Specify the category ID(s) you want to fetch products from
$_prdIds = array(123, 456, 789); // Replace with actual category IDs

// Fetch products using the provided category IDs
$collection = $model->getCollection()->addFieldToFilter('category_id', array('in' => $_prdIds));

This code snippet initializes a product collection filter by the specified category IDs. The array('in' => $_prdIds) condition ensures that the collection includes only products belonging to one of the specified categories.

Displaying Product Names

To display the names of these loaded products, you can iterate through the collection and use the following code:

// Iterate through each product in the collection
foreach ($collection as $product) {
    // Get the product name using getName()
    $pname = $product->getName();

    // Output the product name (you can customize this part)
    echo "Product Name: " . $pname . "<br />";
}

Replace $_prdIds with the actual IDs of the categories you want to fetch products from. The getName() method retrieves the product’s name, which is then output using echo.

Displaying Rating Summary

To display the rating summary for each product, we’ll need to load and calculate the average rating:

// Iterate through each product in the collection
foreach ($collection as $product) {
    // Get the rating details using getRatingSummary()
    $rating = $product->getRatingSummary();

    // Calculate the average rating (assuming it's configured)
    $avg_rating = $rating['summary']['count'] > 0 ? number_format($rating['summary']['rating_sum'], 2, '.', ',') : 0;

    // Output the product name and rating summary
    echo "Product Name: " . $product->getName() . "<br />";
    echo "Rating Summary: " . $avg_rating . "/5 <br /><br />";
}

The getRatingSummary() method retrieves the product’s rating details, including the total number of ratings and the sum of all ratings. We then calculate the average rating by dividing the total rating sum by the count.

Conclusion

In this guide, we’ve demonstrated how to fetch products from specific categories, display their names, and calculate and output their average rating summaries in Magento.

To learn more about advanced customizations and optimizations for your Magento store, feel free to explore our comprehensive guides and tutorials at Laravel Company.

Remember that proper configuration of the rating module is essential for accurate results. If you encounter any issues or need further assistance, don’t hesitate to contact us for expert consultation.

Happy coding!

Catalog

Our network