3

I'm using a custom template on my magento site and I've got everything working but star ratings are not showing on the site's homepage (The one that displays latest and featured product). Its also not showing on recently seen items on side bar and also related products but it is showing on category pages and on product individual pages.

Can someone please explain what I need to do?

Appreciate your response(S). Below is the code;

<?php
    $_productCollection=$this->getLoadedProductCollection();
    $_helper = $this->helper('catalog/output');
    $store = Mage::app()->getStore();
    $code  = $store->getCode();
?>
<?php if(!$_productCollection->count()): ?>
<p class="note-msg"><?php echo $this->__('There are no products matching the selection.') ?></p>
<?php else: ?>
<div class="category-products">
    <?php // Grid Mode ?>

    <?php $_collectionSize = $_productCollection->count() ?>
    <?php
        $_columnCount = $this->getColumnCount();
        if(!$_columnCount)
            $_columnCount = 4;
    ?>
    <ul class="products-grid columns<?php echo $_columnCount; ?>">
    <?php $i=0; foreach ($_productCollection as $_product): ?>
            <li class="item"><div class="item-area">
                <div class="product-image-area">
                    <?php
                    if( Mage::getStoreConfig("quickview/general/enableview", $code) ){
                        $base_url = $this->getUrl();
                        if(strpos($base_url,'?')!==false)
                            $base_url = explode("?",$this->getUrl());
                        if(is_array($base_url))
                            $base_url = $base_url[0];
//                        if(strpos($base_url,'index.php')!==false){
//                            $base_url = str_replace('index.php/','',$base_url);
//                            $base_url .= "index.php/quickview/index/view/";
//                        }else{
//                            $base_url .= "quickview/index/view/";
//                        }
                        $base_url .= "quickview/index/view/";
                        $quickview_url = $base_url."id/".$_product->getId();
                        ?>
                        <a href="<?php echo $quickview_url; ?>" class="quickview-icon"><i class="icon-export"></i><span><?php echo $this->__("Quick View"); ?></span></a>
                    <?php
                    }
                    ?>
                    <a href="<?php echo $_product->getProductUrl() ?>" title="<?php echo $this->stripTags($this->getImageLabel($_product, 'small_image'), null, true) ?>" class="product-image">
                    <?php
                        if(Mage::getStoreConfig("porto_settings/category/alternative_image", $code)){
                    ?>
                        <img class="defaultImage" src="<?php if(Mage::getStoreConfig("porto_settings/category/aspect_ratio",$code)):?><?php echo $this->helper('catalog/image')->init($_product, 'small_image')->constrainOnly(FALSE)->keepAspectRatio(TRUE)->keepFrame(FALSE)->resize(250);?><?php else: ?><?php echo $this->helper('catalog/image')->init($_product, 'small_image')->resize(Mage::getStoreConfig("porto_settings/category/ratio_width",$code),Mage::getStoreConfig("porto_settings/category/ratio_height",$code)); ?><?php endif; ?>" alt="<?php echo $this->stripTags($this->getImageLabel($_product, 'small_image'), null, true) ?>"/>
                        <img class="hoverImage" src="<?php if(Mage::getStoreConfig("porto_settings/category/aspect_ratio",$code)):?><?php echo $this->helper('catalog/image')->init($_product, 'thumbnail')->constrainOnly(FALSE)->keepAspectRatio(TRUE)->keepFrame(FALSE)->resize(250);?><?php else: ?><?php echo $this->helper('catalog/image')->init($_product, 'thumbnail')->resize(Mage::getStoreConfig("porto_settings/category/ratio_width",$code),Mage::getStoreConfig("porto_settings/category/ratio_height",$code)); ?><?php endif; ?>" alt="<?php echo $this->stripTags($this->getImageLabel($_product, 'thumbnail'), null, true) ?>"/>
                    <?php
                        } else {
                    ?>
                        <img src="<?php if(Mage::getStoreConfig("porto_settings/category/aspect_ratio",$code)):?><?php echo $this->helper('catalog/image')->init($_product, 'small_image')->constrainOnly(FALSE)->keepAspectRatio(TRUE)->keepFrame(FALSE)->resize(250);?><?php else: ?><?php echo $this->helper('catalog/image')->init($_product, 'small_image')->resize(Mage::getStoreConfig("porto_settings/category/ratio_width",$code),Mage::getStoreConfig("porto_settings/category/ratio_height",$code)); ?><?php endif; ?>" alt="<?php echo $this->stripTags($this->getImageLabel($_product, 'small_image'), null, true) ?>"/>
                    <?php
                        }
                    ?>
                    </a>
                    <?php 
                        // Get the Special Price
                        $specialprice = Mage::getModel('catalog/product')->load($_product->getId())->getSpecialPrice(); 
                        // Get the Special Price FROM date
                        $specialPriceFromDate = Mage::getModel('catalog/product')->load($_product->getId())->getSpecialFromDate();
                        // Get the Special Price TO date
                        $specialPriceToDate = Mage::getModel('catalog/product')->load($_product->getId())->getSpecialToDate();
                        // Get Current date
                        $today =  time();

                        if ($specialprice){
                            if($today >= strtotime( $specialPriceFromDate) && $today <= strtotime($specialPriceToDate) || $today >= strtotime( $specialPriceFromDate) && is_null($specialPriceToDate)){
                                if(Mage::getStoreConfig("porto_settings/product_label/sale", $code)){
                    ?>
                                <div class="product-label" style="right: 10px;"><span class="sale-product-icon"><?php echo Mage::getStoreConfig("porto_settings/product_label/sale_label_text", $code);?></span></div>
                    <?php       
                                }
                            }
                        }
                    ?>
                    <?php
                        $now = date("Y-m-d");
                        $newsFrom= substr($_product->getData('news_from_date'),0,10);
                        $newsTo=  substr($_product->getData('news_to_date'),0,10);
                        if ($newsTo != '' || $newsFrom != ''){
                            if (($newsTo != '' && $newsFrom != '' && $now>=$newsFrom && $now<=$newsTo) || ($newsTo == '' && $now >=$newsFrom) || ($newsFrom == '' && $now<=$newsTo))
                            {
                                if(Mage::getStoreConfig("porto_settings/product_label/new", $code)){
                        ?> 
                                <div class="product-label" style="left: 10px;"><span class="new-product-icon"><?php echo Mage::getStoreConfig("porto_settings/product_label/new_label_text", $code);?></span></div>
                        <?php 
                                }
                            }
                        }
                    ?>
                </div>
                <div class="details-area">
                    <h2 class="product-name">
                    <a title="<?php echo $this->htmlEscape($_product->getName()) ?>" href="<?php echo $_product->getProductUrl() ?>">  
                                    <?php 
                                    if (strlen($_product->getName()) > 24) :
                                      echo strip_tags(substr($_product->getName(), 0, 20)).'...';
                                    else : 
                                      echo $_product->getName();
                                    endif;
                                  ?>
                                  </a>
                    </h2>
                    <?php 
                   if (Mage::helper('catalog')->isModuleEnabled('Mage_Review')):
                    if($_product->getRatingSummary()): 
                    ?>
                    <?php 
                        $review_html = $this->getReviewsSummaryHtml($_product, 'short');
                        if($review_html){
                            echo $review_html;
                        }else{
                    ?>
                        <div class="ratings">
                            <div class="rating-box">
                                <div class="rating" style="width:0"></div>
                            </div>
                        </div>
                    <?php                            
                        }
                    ?>
                    <?php else: ?>
                        <div class="ratings">
                            <div class="rating-box">
                                <div class="rating" style="width:0"></div>
                            </div>
                        </div>
                    <?php 
                    endif; 
                    endif;
                    ?>
                    <?php echo $this->getPriceHtml($_product, true) ?>
                    <div class="actions">
                        <?php if ($this->helper('wishlist')->isAllow()) : ?>
                            <a href="<?php if(Mage::getStoreConfig("ajaxcart/addtolinks/enablecategory", $code)):?>javascript:ajaxWishlist('<?php echo $this->helper('wishlist')->getAddUrl($_product) ?>','<?php echo $_product->getId()?>');<?php else: ?><?php echo $this->helper('wishlist')->getAddUrl($_product) ?><?php endif; ?>" class="addtowishlist" title="<?php echo $this->__('Add to Wishlist') ?>"><i class="icon-wishlist"></i></a>
                        <?php endif; ?>
                        <?php if($_product->isSaleable()): ?>
                            <?php  if ( !($_product->getData('has_options') || $_product->isGrouped()) ) :  ?>
                                <a href="<?php if(Mage::getStoreConfig("ajaxcart/addtocart/enablecategory", $code)):?>javascript:setLocationAjax('<?php echo $this->getAddToCartUrl($_product) ?>')<?php else: ?><?php echo $this->getAddToCartUrl($_product) ?><?php endif; ?>" class="addtocart" title="<?php echo $this->__('Add to Cart') ?>"><i class="icon-cart"></i><span>&nbsp;<?php echo $this->__('Add to Cart') ?></span></a>
                            <?php else : ?>
                                <a href="<?php if(Mage::getStoreConfig("ajaxcart/addtocart/enablecategory", $code)):?>javascript:showOptions('<?php echo $_product->getId()?>')<?php else: ?><?php echo $this->getAddToCartUrl($_product) ?><?php endif; ?>" class="addtocart" title="<?php echo $this->__('Add to Cart') ?>"><i class="icon-cart"></i><span>&nbsp;<?php echo $this->__('Add to Cart') ?></span></a>
                                <a href='<?php echo $this->getUrl('ajaxcart/index/options',array('product_id'=>$_product->getId()));?>' class='fancybox' id='fancybox<?php echo $_product->getId()?>' style='display:none'>Options</a>
                            <?php endif;?>
                        <?php else: ?>
                            <a href="javascript:void(0);" class="addtocart outofstock" title="<?php echo $this->__('Out of stock') ?>"><?php echo $this->__('Out of stock') ?></span></a>
                        <?php endif; ?>
                        <?php if(Mage::getStoreConfig("porto_settings/category/compare", $code) && $_compareUrl=$this->getAddToCompareUrl($_product)): ?>
                            <a href="<?php if(Mage::getStoreConfig("ajaxcart/addtolinks/enablecategory", $code)):?>javascript:ajaxCompare('<?php echo $_compareUrl ?>','<?php echo $_product->getId()?>');<?php else: ?><?php echo $_compareUrl ?><?php endif; ?>" class="comparelink" title="<?php echo $this->__('Add to Compare') ?>"><i class="icon-compare"></i></a>
                        <?php endif; ?>
                        <div class="clearer"></div>
                    </div>
                </div>
            </div></li>
        <?php endforeach ?>
        </ul>
        <script type="text/javascript">
            jQuery('.col-main .products-grid li:nth-child(2n)').addClass('nth-child-2n');
            jQuery('.col-main .products-grid li:nth-child(2n+1)').addClass('nth-child-2np1');
            jQuery('.col-main .products-grid li:nth-child(3n)').addClass('nth-child-3n');
            jQuery('.col-main .products-grid li:nth-child(3n+1)').addClass('nth-child-3np1');
            jQuery('.col-main .products-grid li:nth-child(4n)').addClass('nth-child-4n');
            jQuery('.col-main .products-grid li:nth-child(4n+1)').addClass('nth-child-4np1');
            jQuery('.col-main .products-grid li:nth-child(5n)').addClass('nth-child-5n');
            jQuery('.col-main .products-grid li:nth-child(5n+1)').addClass('nth-child-5np1');
            jQuery('.col-main .products-grid li:nth-child(6n)').addClass('nth-child-6n');
            jQuery('.col-main .products-grid li:nth-child(6n+1)').addClass('nth-child-6np1');
            jQuery('.col-main .products-grid li:nth-child(7n)').addClass('nth-child-7n');
            jQuery('.col-main .products-grid li:nth-child(7n+1)').addClass('nth-child-7np1');
            jQuery('.col-main .products-grid li:nth-child(8n)').addClass('nth-child-8n');
            jQuery('.col-main .products-grid li:nth-child(8n+1)').addClass('nth-child-8np1');
        </script>
</div>
<?php endif; ?>
  • share your code – Qaisar Satti Oct 15 '15 at 9:58
  • Thank you Qaisar. I've updated my question so the code can be displayed properly. – Jahswey Oct 15 '15 at 13:13
0

replace this

$review_html = $this->getReviewsSummaryHtml($_product, 'short'); 

with

$reviewHelper = $this->getLayout()->createBlock('review/helper');
echo $reviewHelper->getSummaryHtml($_product, 'short', true);

OR

you can use this for rating

$storeId = Mage::app()->getStore()->getId();
$summaryData = Mage::getModel('review/review_summary')
                    ->setStoreId($storeId)
                    ->load($_product->getId());

if ($summaryData['rating_summary']):?>
    <div class="ratings">
        <div class="rating-box">
            <div class="rating" style="width:<?php echo $summaryData['rating_summary']; ?>%"></div>
        </div>
    </div>
<?php endif; ?>
  • Hi Qaisar, thanks for the support. but I tried using both options, none of them worked – Jahswey Oct 18 '15 at 16:13
  • second option always work in every condition. check print_r($summaryData); give you what output? – Qaisar Satti Oct 18 '15 at 16:15
  • It could be an issue with the wrong template being rendered on the page. What you checked with template hints to make sure you are editing the right files? – circlesix Jul 2 '17 at 3:50
  • This answer should work – Kalyan Chakravarthi V Feb 21 '18 at 19:01

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.