0

I am trying to generate SEO rich data in Magento for a category or listing page. I just don't understand how can I get the total amount of reviews for a that category.

I don't want to slow down the category page.

Is it possible to get that by directly executing an SQL command?

Please help me :(

  • Rich data in Category view – xtremprovider Jun 15 at 19:45
  • It is different based on which version you are using and you've tagged it with both for some reason. Are you on Magento 1 or 2? – mtr.web Jun 17 at 18:11
  • I have mentioned in title magento 1.9. Your help will be greatly appreciated – xtremprovider Jun 17 at 20:36
0

In the main product-list template, you will see the collection populated with $_productCollection=$this->getLoadedProductCollection(); somewhere near the top of file. Depending on whether you are using a custom theme, the file's location may be different, but the filepath will be something like this:

[magento-root]/app/design/frontend/<your-theme>/<your-subtheme>/template/catalog/product/list.phtml

Note: This is extending the default template, located at

[magento-root]/app/design/frontend/base/default/template/catalog/product/list.phtml

There are a few things that you could experiment with, but basically, you'd loop through the product-collection and use $_product->getRatingSummary() and possibly $_product->getReviewSummaryHtml() to get what some in-depth information.

Luckily, the default template already looks for a review, so you really just need to add a counter and/or custom logic in the two places that you see <?php if($_product->getRatingSummary()): ?>

So, if all you are looking for is the count. Add the following to the top of your file:

$reviewCount = 0;

..and there are two places (list and grid mode) that you would find a place to increment it. In the simplest example, you would replace this:

<?php if($_product->getRatingSummary()): ?>
<?php echo $this->getReviewsSummaryHtml($_product) ?>
<?php endif; ?>

with this:

<?php if($_product->getRatingSummary()) {
    $reviewCount++;
    echo $this->getReviewsSummaryHtml($_product) ?>
}?>

And after the loop is finished, you would have the total number of reviews for the category. If you need it at the top of the product-list, you could loop through on your own and add custom output:

<?php 
$reviews = array();  // this will be populated with the output for products with reviews

foreach ($_productCollection as $_product) {
    if($_product->getRatingSummary()) 
        $reviews[] = $this->getReviewsSummaryHtml($_product, 'short');
}
$reviewCount = count($reviews);
?>
  • This is returning all review from entire website but i needed only reviews to that category from where we load product list. For an example we have website www.example.com this website has 6 category with 800 products and 300 reviews in total. We have A B C D category. Now we have A category which has 57 review and B ,C,D has rest. So when i click category A it gives all the products it belongs and here i want to display those 57 reviews bottom of product list. – xtremprovider Jun 22 at 9:27

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.