Create Magento Featured Products

04 Aug 2010
For an online store, it is essential to have the ability to display and sort your products, and thus support your customers in searching and choosing products. This article shows you how to create these featured products on homepage in Magento.

In this article, I will guide you how to display the featured products on frontent Home Page

 

Step1:  Create attribute "featured".

 

Go to admin-> 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

 

Manage Label/Options

 

Default: Featured Product

 

English: Featured Product

 

Step2:  Adding these attributes to attribute set.

 

After creating attributes, you need to add them into attribute sets, if you use default attribute set (or any attribute set you define), please add these attributes into the attribute set you used. (Below is example for Default Attribute Set).

 

Step 3:

 

Go to folder: …\app\design\frontend\default\your theme\template\catalog\product

 

Create file featured.phtml and add the following code into this file

 

<?php

 

//

 

$totalPerPage = ($this->show_total) ? $this->show_total : 12;

 

$visibility = array(

 

                      Mage_Catalog_Model_Product_Visibility::VISIBILITY_BOTH,

 

                      Mage_Catalog_Model_Product_Visibility::VISIBILITY_IN_CATALOG

 

                  );

 

$storeId = Mage::app()->getStore()->getId();

 

$_productCollection = Mage::getResourceModel('reports/product_collection')

 

                        ->addAttributeToSelect('*')    

 

                        ->setStoreId($storeId)

 

                        ->addStoreFilter($storeId)    

 

                        ->addAttributeToFilter('visibility', $visibility)

 

                        ->addAttributeToFilter('featured', true)

 

                        ->setOrder('created_at', 'desc')

 

                        ->addAttributeToSelect('status')

 

                        ->setPageSize($totalPerPage);

 

Mage::getSingleton('catalog/product_status')->addVisibleFilterToCollection($_productCollection);

 

Mage::getSingleton('cataloginventory/stock')->addInStockFilterToCollection($_productCollection);

 

Mage::getSingleton('catalog/product_visibility')->addVisibleInSearchFilterToCollection($_productCollection);

 

?>

 

<h1>Featured product (test module)</h1>

 

<br><br>

 

<div style="width:95%; text-align:center;">

 

<?php $_collectionSize = $_productCollection->count() ?>

 

    <table cellspacing="0" class="generic-product-grid" id="product-list-table">

 

    <?php $i=0; foreach ($_productCollection as $_product): ?>

 

    <?php if ($i++%4==0): ?>

 

    <tr>

 

    <?php endif ?>

 

        <td>

 

            <p class="product-image">

 

                <a href="<?php echo $_product->getProductUrl() ?>" title="<?php echo $this->htmlEscape($this->getImageLabel($_product, 'small_image')) ?>">

 

                    <img src="<?php echo $this->helper('catalog/image')->init($_product, 'small_image')->resize(170, 170); ?>" alt="<?php echo $this->htmlEscape($this->getImageLabel($_product, 'small_image')) ?>" title="<?php echo $this->htmlEscape($this->getImageLabel($_product, 'small_image')) ?>" />

 

                </a>

 

            </p>

 

            <h5><a href="<?php echo $_product->getProductUrl() ?>" title="<?php echo $this->htmlEscape($_product->getName()) ?>"><?php echo $this->htmlEscape($_product->getName()) ?></a></h5>

 

            <div>

 

            <?php if ($_product->getSpecialPrice()>0):?>

 

                <span class="old"><?php echo $this->helper('checkout')->formatPrice($_product->getPrice()) ?></span>&nbsp;

 

                <span class="new"><?php echo $this->helper('checkout')->formatPrice($_product->getSpecialPrice()) ?></span>

 

            <?php else: ?>

 

                <span class="new"><?php echo $this->helper('checkout')->formatPrice($_product->getPrice()) ?></span>

 

            <?php endif; ?>

 

            </div>

 

            <?php echo $_product->getShortDescription() ?>

 

            <div class="clear"></div>

 

            

 

        </td>

 

    <?php if ($i%4==0 && $i!=$_collectionSize): ?>

 

    </tr>

 

    <?php endif ?>

 

    <?php endforeach ?>

 

    <?php for($i;$i%4!=0;$i++): ?>

 

          <td class="empty-product">&nbsp;</td>

 

    <?php endfor ?>

 

    <?php if ($i%4==0): ?>

 

    </tr>

 

    <?php endif ?>

 

    </table>

 

    <script type="text/javascript">decorateTable('product-list-table')</script>

 

</div>

 

Step 4: Display the featured products on frontent Home Page:

 

You copy and Paste the following code into CMS home page

 

 

Step 5:

 

Go to admin-> Catalog-> Manage Products-> add new Products:

 

Input full information for product.

 

You will see Featured Products on left side: choose Yes. And Save Products.

 

Now go back to Homepage and refresh. You should see the attribute product you’ve created.

 

Good luck to your business.

 

Related Posts

Adding a Static Block to your .phtml files in Magento

Adding a Static Block to your .phtml files in Magento

28 Jul 2010
Adding a Static Block to your .phtml files in Magento
Magento - Layered navigation on product pages

Magento - Layered navigation on product pages

20 Jul 2010
To attract more potential customers to your online store, you must create an ease for them when browsing products they need. In Magento, Layered Navigation is a useful feature that allows customers to find item according to two default properties: Price and Categories.
Upgrade magento theme from 1.4.0.1 to 1.4.1.0

Upgrade magento theme from 1.4.0.1 to 1.4.1.0

16 Jul 2010
Finally, Magento version 1.4.1.0 has been released, and much improved since 1.4.0.1. Here is the tip for fixing common theme issue while upgrading.