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: <?php $featured_products = $this->getFeaturedProducts(); ?> <?php shuffle($featured_products); ?> <div class="box recently" style="padding-left:15px; padding-right:15px;"> <h3><?php echo $this->__('Featured Products') ?></h3> <div class="listing-type-grid catalog-listing"> <?php $_collectionSize = count($featured_products) ?> <table cellspacing="0" class="recently-list" id="product-list-table"> <?php $i=0; foreach ($featured_products as $_res): ?> <?php $_product = Mage::getModel('catalog/product')->load($_res['product_id']); ?> <?php if ($i++%3 == 0): ?> <tr> <?php endif ?> <td> <div> <a href="<?php echo $_product->getProductUrl() ?>" title="<?php echo $this->htmlEscape($_product->getName()) ?>"> <img class="product-image" src="<?php echo $this->helper('catalog/image')->init($_product, 'small_image')->resize(120, 120); ?>" width="120" height="120" alt="<?php echo $this->htmlEscape($_product->getName()) ?>" /> </a> </div> <p> <a class="product-name" href="<?php echo $_product->getProductUrl() ?>" title="<?php echo $this->htmlEscape($_product->getName()) ?>)"> <?php echo $this->htmlEscape($_product->getName()) ?> </a> </p> <?php echo $this->getReviewsSummaryHtml($_product, 'short') ?> </td> <?php if ($i%3 == 0 && !=$_collectionSize): ?> </tr> <?php endif ?> <?php endforeach ?> <?php for($i;$i%3!=0;$i++): ?> <td class="empty-product"> </td> <?php endfor ?> <?php if ($i%3==0): ?> <?php endif ?> </table> <script type="text/javascript">decorateTable('product-list-table')</script> </div> </div> Step6: Create the “app/code/local/FeaturedProduct/etc/config.xml" <block> <catalog> <rewrite> <product_featured>Mindfire_Featuredproduct_Block_Catalog_Product_Featured </product_featured> </rewrite> <rewrite> <category_view>Mindfire_Featuredproduct_Block_Catalog_Category_View </category_view> </rewrite> </catalog> </block>
Step7:
Cms pages -> home page content area write
{{block type=”catalog/product_featured” name=”product_featured” as=”product_featured” template=”catalog/product/featured.phtml”}}
As you are making a new module so add the .xml file in the app/etc/Module and check whether it is active in admin side or not.
Refesh your page to see the featured product.