Question

I have a configurable product from which I am trying to get reviews

$myThemeName/catalog/product/view.phtml

/**
 * Product view template
 *
 * @see Mage_Catalog_Block_Product_View
 * @see Mage_Review_Block_Product_View
 */

$_product = $this->getProduct();

I need ratings in a group count of 5 star, 4 star, 3 star, 2 star and 1 star. like this

enter image description here

I have done the following, by going through this link (check @sinclairfr's post), which is giving me complete html of ratings related to the product.

<?php $zoo = new Mage_Rating_Block_Entity_Detailed(); ?>
<?php echo $zoo->toHtml(); ?>

and also this

$review = Mage::getModel('review/review');
$collection = $review->getProductCollection();
$collection
->addAttributeToSelect('*')
->getSelect()
->limit(5)
->addFieldToFilter('product_id', $_product->getId());
$review->appendSummary($collection);

zend_debug::dump($review); 

By going through this link

still no use

Was it helpful?

Solution

You can get all the votes attached to a product with the following code. Note that the setEntityPkFilter is setting the product id.

$votesCollection = Mage::getModel('rating/rating_option_vote')
    ->getResourceCollection()
    ->setEntityPkFilter($productId)
    ->setStoreFilter(Mage::app()->getStore()->getId())
    ->load();

This will give you each type of vote. So in the default shop you will get three items in this collection per review. The ratings are done on price, quality and value.

You could then loop through each of the items in the collection and add them to the star rating. The sample data of a vote item is:

array(10) {
  ["vote_id"]=>
  string(3) "283"
  ["option_id"]=>
  string(1) "9"
  ["remote_ip"]=>
  string(9) "127.0.0.1"
  ["remote_ip_long"]=>
  string(10) "2130706433"
  ["customer_id"]=>
  NULL
  ["entity_pk_value"]=>
  string(2) "27"
  ["rating_id"]=>
  string(1) "2"
  ["review_id"]=>
  string(2) "95"
  ["percent"]=>
  string(2) "80"
  ["value"]=>
  string(1) "4"
}
Licensed under: CC-BY-SA with attribution
Not affiliated with magento.stackexchange
scroll top