How to display featured product in magento


<div>

<?php

 $featuredproducts = array();
 $i = 0;
 try {
 $storeId = Mage::app()->getStore()->getId();
 $resource = Mage::getSingleton('core/resource');
 $read = $resource->getConnection('catalog_read');
 $categoryProductTable = $resource->getTableName('catalog/category_product');
 $productEntityIntTable = (string)Mage::getConfig()->getTablePrefix() . 'catalog_product_entity_int';
 $eavAttributeTable = $resource->getTableName('eav/attribute');

 $select = $read->select()
 ->from(array('cp'=>$categoryProductTable))
 ->join(array('pei'=>$productEntityIntTable), 'pei.entity_id=cp.product_id', array())
 ->joinNatural(array('ea'=>$eavAttributeTable))
 ->where('pei.value=1')
 ->where('ea.attribute_code="fooger_featured_product"'); //this is attribute code

 $featuredproducts = $read->fetchAll($select);
 } catch (Exception $e) {
 // Blank
 }
 if(count($featuredproducts)) :
 foreach($featuredproducts as $data) :
 $prodInfo = Mage::getModel('catalog/product')->setStoreId($storeId)->load($data['product_id']);
?>
 <div>
 <div>
 <a href="<?php echo $baseUrl.$prodInfo->url_path ?>" title="View <?php echo $prodInfo->name ?>" target="_blank">
 <img height="114" width="140" src="<?php echo $this->helper('catalog/image')->init($prodInfo, 'image');//->resize(82); ?>" />
 </a>
 </div>
 </div>
 <?php
 $i++;
 if($i == 3) return; // Total 3 feature products only
 ?>
 <?php endforeach ?>
 <?php else :?>
 <div>No feature products</div>
 <?php endif ?>
 </div>

&nbsp;

for more magento tutorial visit: http://blog.free-extension.com/

Advertisements
  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: