for each for each for each
<?php
$_product = $this->getProduct();
$_items = $this->getReviewsCollection()->getItems();
$_totalItems = $_items;
if ( $_product->getTypeId() == "bundle" ) {
$collection = $_product->getTypeInstance( true )
->getSelectionsCollection( $_product->getTypeInstance( true )->getOptionsIds( $_product ), $_product );
$itemIds = array();
$i = 0;
foreach ( $collection as $item ) {
$itemIds[ $i ]['id'] = $item->getId();
$itemIds[ $i ]['qty'] = $item->getSelectionQty();
$i ++;
}
foreach ( $itemIds as $_wineBottle ):
$_wineBottle = Mage::getModel( 'catalog/product' )->load( $_wineBottle['id'] );
$_reviews = Mage::getModel( 'review/review' )->getCollection()
->addStoreFilter( Mage::app()->getStore()->getId() )
->addEntityFilter( 'product', $_wineBottle->getId() )
->addStatusFilter( Mage_Review_Model_Review::STATUS_APPROVED )
->setDateOrder()
->addRateVotes();
$_reviewItems = $_reviews->getItems();
$_totalItems = $_totalItems + $_reviewItems;
endforeach;
}
$_items = $_totalItems;
$_ratingsAmount = count($_items);
/*
* Because some products are bundled products, we have to get the rating totals of all child products, and average those to get the overall star rating
*/
//if (count($_items)):
$sumPercent = 0;
foreach ($_items as $_review):
$_votes = $_review->getRatingVotes();
if (count($_votes)):
// get vote percent for each rating total
foreach ($_votes as $_vote) {
$_votePercent = $_vote->getPercent();
}
endif;
// add all rating percents together
$sumPercent += $_votePercent;
endforeach;
//get the average votes by dividing total of percents, by amount of ratings
$_averageVotes = $sumPercent / $_ratingsAmount;
// round down to nearest integer
$_roundAvVotes = floor($_averageVotes);
?>
<div class="product-total-reviews">
<span><?php echo $_ratingsAmount ?> review(s)</span>
<div class="raty-ratings" data-score="<?php echo $_roundAvVotes; ?>"></div>
</div>