Saturday 30 January 2016

How to get Review/Rating summary in Magento

We can use the below code to retrieve product Review/Rating summary in Magento



<?php 


$product = Mage::getModel('catalog/product')->load($productId);


$storeId    = Mage::app()->getStore()->getId();


$summaryReview = Mage::getModel('review/review_summary')
  ->setStoreId($storeId)
  ->load('product_id');


  if($summaryReview->getRatingSummary()){


  ?>


  <div class="rating-box" style="float:left;">


<div class="rating" style="width: <?php echo $summaryData->getRatingSummary().'%'; ?>">

                             </div>
  </div>
<?php 
}
?>

How to display category name by product id in Magento

If you want to get Category Name by Product Id in Magento. Use following code:



<?php 

$product = Mage::getModel('catalog/product')->load($_product->getId());


$cat_id = $product->getCategoryIds();


foreach($cat_id as $categorycbId) {


$category_id = Mage::getModel('catalog/category')->load($categorycbId);


echo $category_id->getName();


}

?>


Friday 29 January 2016

How to display static block with title in phtml file : Magento

If you want to display static block in PHTML file in Magento. We can use following code:


<?php echo $this->getLayout()->createBlock('cms/block')->setBlockId('identifier')->toHtml() ?>



But If you want to display static block with title. So, we can you following code:


<?php
     $block = Mage::getModel('cms/block')--->load('identifier');
     echo $block->getTitle();
     echo $block->getContent();
?>