Magento: Add Featured products on Magento frontpage
In this blog I’m going to describe how to add a featured products on frontend in magento. Here I am portraying by what method would you be able to make an included item and demonstrate the piece in the landing page of your Magento Store. Most of the ecommerce shops feel the urge to showcase their special products or featured products either on their shop’s home page or category listing pages depending upon the requirement.
What is featured product?
The Featured Product is a product with an attribute added from the administrative UI. When the administrator selects “Yes” in the “Featured” attribute, that product will be displayed in a content block on the category page.
Here I am portraying by what method would you be able to make an included item and demonstrate the piece in the landing page of your Magento Store.
Follow below steps:-
Step1: Create new Featured attribute
Create a new attribute by going to Catalog > Attributes > Manage Attributes > Add New Attribute.
Attribute Properties
- Attribute Identifier: featured
- Scope: Store View
- Catalog Input Type for Store Owner: Yes/No
- Unique Value (not shared with other products): No
- Values Required: No
- Input Validation for Store Owner: None
- Apply To: All Product Types
Front End Properties
- Use in quick search: No
- Use in advanced search: Yes
- Comparable on Front-end: No
- Use In Layered Navigation (Can be used only with catalog input type ‘Dropdown’): No
- Visible on Catalog Pages on Front-end: Yes
Incorporate the highlighted property in the trait set you need.
Step2:
Create a new product and include that specific atrribute set and set the highlighted trait as “yes” from oversee items.
Step3:
Make an extension module in your “local” folder and named it as featuredproduct.
Create block file “app/code/local/FeaturedProduct/Catalog/Block/Product/Featured.php”
Include the code beneath:
<?php //Code will fetch all the products whose featured attribute is set to "Yes" public function getFeaturedProducts() { $storeId = Mage::app()->getStore()->getId(); $_productCollection = Mage::getResourceModel('reports/product_collection') ->addAttributeToSelect('*') ->setStoreId($storeId) ->addStoreFilter($storeId) ->addAttributeToFilter('visibility', $visibility) ->addAttributeToFilter('featured', '1') ->setOrder('created_at', 'desc') ->addAttributeToSelect('status') ->setPageSize(5); return $_productCollection; } ?>
Step6:
Create block file “app/code/local/FeaturedProduct/Catalog/Block/Category/View.php”
Add the following code:
<?php 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>Prashant_Featuredproduct_Block_Catalog_Product_Featured </product_featured> </rewrite> <rewrite> <category_view>Prashant_Featuredproduct_Block_Catalog_Category_View </category_view> </rewrite> </catalog> </block>
Step7:
Go to 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.