Featured Product: When the store owner tries to increase the sale of a product, he needs to make the product as a featured product. So that the owner could able to do more publicity of those products.
Here I am describing how can you create a featured product and show the block in the home page of your Magento Store.
Following are the steps:
Step1: Create a attribute “featured” with yes/no property from Catalog Input Type for Store Owner dropdown present in the Add new atrribute.
Include the featured attribute in the attribute set you want.
Step2:
Create a new product and add that particular atrribute set and set the featured attribute as “yes” from manage products.
Step3:
Create a extension module in your local folder and named it as featuredproduct.
Create block file “app/code/local/FeaturedProduct/Catalog/Block/Product/Featured.php”
Add the code below:
/Code will fetch all the products whose featured attribute is set to "Yes"
public function getFeaturedProducts()
{
$resource = Mage::getSingleton('core/resource');
$read = $resource->getConnection('catalog_read');//Make a connection
$productEntityIntTable = (string)Mage::getConfig()->getTablePrefix() . 'catalog_product_entity_int';
$eavAttributeTable = $resource->getTableName('eav/attribute');// Get the attribute table
$categoryProductTable = $resource->getTableName('catalog/category_product');//get the product table
$select = $read->select()
->distinct(true)
->from(array('cp'=>$categoryProductTable), 'product_id')
->join(array('pei'=>$productEntityIntTable), 'pei.entity_id=cp.product_id', array())
->joinNatural(array('ea'=>$eavAttributeTable))
->where('pei.value=1')
->where('ea.attribute_code="featured"');
$res = $read->fetchAll($select);
return $res;
}
Step6:
Create block file “app/code/local/FeaturedProduct/Catalog/Block/Category/View.php”
Add the following code:
public function getFeaturedProductHtml()
{
return $this->getBlockHtml('product_featured');
}
Step5:
Create file “app/design/frontend/base/default/template/catalog/product/featured.phtml”
Add the code: