Eglobe IT Solutions
open

Magento Create Featured Product Block on Home Page

  • Magento Create Featured Product Block on Home Page

    Create a Featured Attribute in Magento Backend first Create an attribute featured with yes/no property from Catalog Input Type for Store Owner drop down, then include it in attribute set and assign one product as Featured “yes” from Catalog->Manage Products. Create a Custom Module Create custom module and block file “app/code/local/FeaturedProduct/Catalog/Block/Product/Featured.php” with following code in it.

    class FeaturedProduct_Catalog_Block_Product_Featured extends Mage_Catalog_Block_Product_List
    {
        protected $_productCollection;
        public function fetchProducts()
        {
           $this->productCollection =Mage::getModel('catalog/product')->getCollection()
            ->addAttributeToSelect('*')
            ->addFieldToFilter('featured_products', array('eq' => '1'));
          return $this->productCollection;
        }
    }
    
    Create a configuration file in app/code/local/FeaturedProduct/Catalog/etc/config.xml You have to specify a configuration file to tell magento about which XML is going to declare the block need to display featured products in homepage and which is located in app/code/local/FeaturedProduct/Catalog/etc/config.xml as:
    
    
    
            
                1.0.0                        
            
    
    
            
                
                    FeaturedProduct_Catalog_Block
                
            
    
    
            
                
                    
                        featuredproduct.xml
                    
                
            
    
    
    
    Create featuredproducts.xml in location app/design/frontend/mytheme/default/layout/featuredproduct.xml as follows:
    
    
        
            
                
                    
                        4
                    
                
            
        
    
    
    Finally , create a view file to display featured products in a Grid layout as : Create view file “app/design/frontend/mytheme/default/template/catalog/product/featured.phtml” with following code in it :
    fetchProducts();
        $_helper = $this->helper('catalog/output');
    ?>
    
    count()): ?>

    __('There are no products in the featured product list!!') ?>

    count() ?> getColumnCount(); ?>
    That’s it. Prefer to choose Installer Script for creating featured attribute mentioned in the beginning.Try it :-)

  • Post Comments

    Submit Comment




    * Required Fields