Monday, July 16, 2012

How to Show Featured Products in Magento

Here I'll show you how to add featured products in Magento. "Featured" is a term that normally we use. You can use another name but here I'm showing you with the name "Featured". You can show this featured product collections in Home Page or any other page. In two way we can achieve this. First we can create an attribute in product level and get collection with filter of that attribute. Another one the easy way, we can create a category named "Featured" and assign those products you want to show in your phtml page.

Here is the First Step:

>>    Create new "Featured" attribute
        Create a new attribute by going to Catalog -> Attributes -> Manage Attributes -> Add New Attribute.
     
        Attribute Properties
            Attribute Identifier: featured
            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 Configurable/Grouped Product: Yes
     
        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
     
        System Properties
            Data Type for Saving in Database: String
            Globally Editable: No
            Visible on Catalog Pages on Front-end: Yes
     
        Manage Label/Options
            Default: Featured Product
            English: Featured Product

Now set the attribute within ant attribute set by going to Catalog -> Attributes -> Manage Attribute Set.
you're ready with the attribute now set the attribute value "Yes" by editing those products you want to show in your phtml page.
>>  Add this code in your phtml page:

    $featured_products = Mage::getModel('catalog/product')
                                    ->getCollection()
                                    ->addAttributeToFilter('status', 1)
                                    ->addAttributeToFilter('visibility', 4)
                                    ->addAttributeToFilter('featured', 1);
     
    foreach($featured_products as $_product)
    {
        echo $_product->getName();
    }

 
Above is the example of showing by attribute. Now I'm Showing you the Second Step with category. It's the simple way. Create a category named "Featured" and make the category attribute "Include in Navigation Menu" false. In this category add some products which you want to show in your phtml page.

>> Add this code in your phtml page:

$category = Mage::getModel('catalog/category')->load(15);  // Here 15 is your new category ID
        $collection = $category->getProductCollection();


No comments:

Post a Comment