Magento 1 product reviews
<block type="page/html_pager" name="product_review_list.toolbar" />
<block type="core/template" name="product_review_list.count" template="review/product/view/count.phtml" />
<block type="review/product_view_list" name="product.info.product_additional_data" as="product_reviews" template="review/product/view/list.phtml">
<block type="review/form" name="product.review.form" as="review_form"/>
</block>
<?php echo $this->getChildHtml('product_reviews') ?>
\!h -----product reviews product last review
<?php
$reviews = Mage::getModel('review/review')
->getResourceCollection()
->addStoreFilter(Mage::app()->getStore()->getId())
->addEntityFilter('product', $_product->getId())
->addStatusFilter(Mage_Review_Model_Review::STATUS_APPROVED)
->setDateOrder()
->addRateVotes();
$ratings = array();
if (count($reviews) > 0):
?>
<ol id="recently-viewed-items" class="mini-products-list">
<?php foreach ($reviews->getItems() as $review): ?>
<li class="item odd">
<div class="product-details">
<p class="product-name">
<a href="<?php echo $this->getReviewUrl($_review->getId()) ?>"><?php echo $review->getTitle(); ?> <span><?php echo $this->__('Reviews of'); ?> <b><?php echo $review->getNickname(); ?></b></span></a>
</p>
<?php foreach( $review->getRatingVotes() as $vote ): ?>
<div class="ratings">
<div class="rating-box">
<span class="rating-number"></span>
<span class="rating nobr" style="width:<?php echo $vote->getPercent(); ?>%;">5 star</span>
</div>
</div>
<?php endforeach; ?>
<p><?php echo $review->getDetail(); ?></p>
</div>
</li>
<?php break; endforeach; ?>
</ol>
<?php endif; ?>
\!h ----- product url on reviews summary product info on reviews summary get product link on review
<?php echo $this->getProduct()->getUrlInStore(); ?>
\!h ----- Review Summery out sumemry reviews
<?php
$storeId = Mage::app()->getStore()->getId();
$summaryData = Mage::getModel(‘review/review_summary’)
->setStoreId($storeId)
->load($_product->getId());
/* @var $summaryData Mage_Review_Model_Review_Summary */
/*
array(
['primary_id'] => 147
['entity_pk_value'] => 166
['entity_type'] => 1
['reviews_count'] => 1
['rating_summary'] => 80
['store_id'] => 1
)
*/
?>
<?php
$currentproduct = Mage::registry('current_product');
$_product = Mage::getModel('catalog/product')->load($currentproduct->getId());
$storeId = Mage::app()->getStore()->getId();
$summaryData = Mage::getModel('review/review_summary')->setStoreId($storeId)->load($_product->getId());
if ($summaryData->getRatingSummary()):
?>
<div class="ratings">
<span><?php echo $this->__('Rate product'); ?>:</span>
<div class="rating-box">
<div class="rating" style="width:<?php echo $summaryData->getRatingSummary() ?>%"></div>
</div>
</div>
<?php endif;?>
<?php $_helper = $this->helper('catalog/output'); ?>
<?php $_product = $this->getProduct(); ?>
<?php $_items = $this->getReviewsCollection()->getItems();
$storeId = Mage::app()->getStore()->getId();
$summaryData = Mage::getModel('review/review_summary')->setStoreId($storeId)->load($_product->getId());
?>
<?php if ($summaryData->getRatingSummary()):?>
<div class="rating-box">
<div class="rating" style="width:<?php echo $summaryData->getRatingSummary() ?>%"></div>
</div>
<?php endif;?>
\!h ----- Reviews collection
/**
* Getting reviews collection object
*/
$productId = $product->getId();
$reviews = Mage::getModel('review/review')
->getResourceCollection()
->addStoreFilter(Mage::app()->getStore()->getId())
->addEntityFilter('product', $productId)
->addStatusFilter(Mage_Review_Model_Review::STATUS_APPROVED)
->setDateOrder()
->addRateVotes();
/**
* Getting average of ratings/reviews
*/
$avg = 0;
$ratings = array();
if (count($reviews) > 0) {
foreach ($reviews->getItems() as $review) {
foreach( $review->getRatingVotes() as $vote ) {
$ratings[] = $vote->getPercent();
}
}
$avg = array_sum($ratings)/count($ratings);
}
Displaying the ratings
<!-- REMOVE 'IF CONDITION', TO SHOW RATING IN ALL RATED/UNRATED PRODUCTS -->
<?php if($avg): ?>
<div class="rating-box" style="float:left;">
<div class="rating" style="width: <?php echo ceil($avg) ; ?>%;"></div>
</div>
<?php endif; ?>
\!h ----- Блок выводит 2 рандомных review продуктов
<?php
$collection = Mage::getResourceModel('catalog/product_collection');
Mage::getModel('catalog/layer')->prepareProductCollection($collection);
$collection->getSelect()->order('rand()');
$collection->addStoreFilter();
$numProducts = 10;
$collection->setPage(1, $numProducts)->load();
$review_detail = array();
foreach($collection as $product){
$_reviews = Mage::getModel('review/review')->getCollection()
->addStoreFilter(Mage::app()->getStore()->getId())
->addStatusFilter('approved')
->addEntityFilter('product', $product->getId())
->setDateOrder();
foreach($_reviews as $_review){
if( $_review = $_review->getData() ) {
$review_detail[] = $_review['detail'];
break;
}
}
}
$review_detail = array_slice( $review_detail, 0, 2 );
print_r( $review_detail );
?>
\!h ----- Блок выводит последние ревью recent review
<?php
$collection = Mage::getResourceModel('catalog/product_collection');
Mage::getModel('catalog/layer')->prepareProductCollection($collection);
$collection->addStoreFilter();
$numProducts = 1000;
$collection->setPage(1, $numProducts)->load();
$review_detail = array();
foreach($collection as $product){
$_reviews = Mage::getModel('review/review')->getCollection()
->addStoreFilter(Mage::app()->getStore()->getId())
->addStatusFilter('approved')
->addEntityFilter('product', $product->getId())
->setDateOrder();
foreach($_reviews as $_review){
$reviewid = $_review->review_id;
if( $_review = $_review->getData() ) {
$review_detail[$reviewid][] = $_review['detail'];
}
}
}
krsort($review_detail);
$review_detail = array_slice( $review_detail, 0, 5 );
?>
<section class="testimonials-box">
<div class="holder">
<header class="heading">
<h3><?php echo $this->__('Testimonials'); ?></h3>
</header>
<ul class="gallery">
<?php $counter = 0; foreach($review_detail as $review): ++$counter; ?>
<li <?php if($counter == 1) { echo 'class="active"'; } ?>>
<blockquote>
<q><img class="qt" alt="image description" src="<?php echo $this->getSkinUrl('images/qt.png'); ?>"><?php echo $review['0']; ?><img class="qb" alt="image description" src="<?php echo $this->getSkinUrl('images/qb.png'); ?>"></q>
</blockquote>
</li>
<?php endforeach; ?>
</ul>
</div>
</section>
\!h ----- Review link reviews form link
<?php
$current_url = $this->helper('core/url')->getCurrentUrl();
$review_url = Mage::getUrl('review/product/list', array('id' => $this->getProduct()->getId(), 'category' => $this->getProduct()->getCategoryId()));
if($current_url != $review_url) :
?>
<a href="<?php echo $review_url ?>#review-form" class="btn">Write a Review!</a>
<?php endif;?>
\!h ----- top rated products rated high rated high ratings high rating
http://blog.chapagain.com.np/magento-how-to-get-top-rated-products/
http://odino.org/retrieve-top-rated-products-in-magento/
/**
* Get Top Rated Products
*
* @return array
*/
public function getTopRatedProduct() {
$limit = 5;
// get all visible products
$_products = Mage::getModel('catalog/product')->getCollection();
$_products->setVisibility(Mage::getSingleton('catalog/product_visibility')->getVisibleInCatalogIds());
$_products->addAttributeToSelect('*')->addStoreFilter();
$_rating = array();
foreach($_products as $_product) {
$storeId = Mage::app()->getStore()->getId();
// get ratings for individual product
$_productRating = Mage::getModel('review/review_summary')
->setStoreId($storeId)
->load($_product->getId());
$_rating[] = array(
'rating' => $_productRating['rating_summary'],
'product' => $_product
);
}
// sort in descending order of rating
arsort($_rating);
// returning limited number of products and ratings
return array_slice($_rating, 0, $limit);
}
Now, you can display the products in any template file. Here is the sample code to display the top rated products:-
<!-- I suppose that you have put the getTopRatedProduct() function in helper class of your module -->
<?php $topRatedProducts = $this->helper('yourModule')->getTopRatedProduct();?>
<ul>
<?php foreach($topRatedProducts as $_rating): ?>
<?php $_product = $_rating['product']; ?>
<li>
<img src="<?php echo $this->helper('catalog/image')->init($_product, 'small_image')->resize(150); ?>" alt="<?php echo $this->htmlEscape($this->getImageLabel($_product, 'small_image')) ?>" title="<?php echo $this->htmlEscape($this->getImageLabel($_product, 'small_image')) ?>" />
<a href="<?php echo $_product->getProductUrl() ?>" title="<?php echo $this->htmlEscape($this->getImageLabel($_product, 'small_image')) ?>">
<span>View Details</span>
</a>
</li>
</ul>
<?php endforeach; ?>
- See more at: http://blog.chapagain.com.np/magento-how-to-get-top-rated-products/#sthash.0qRSK0hH.dpuf