Tuesday, June 1, 2010

How to add featured products to homepage in magento

====== Add Featured Products to Home Page ======

- Create a category to contain the featured products. Call it e.g. "Featured" or "Home Page". Set "Is Active" to No. That way, it won't display in the catalog menu.
- After saving the category, please note what ID it gets. You can see it in the last part of the URL. If the URL ends with ''catalog_category/edit/id/8/'', the ID is 8. On later version, the ID is next to the category name:{{how_to:categoryid.png?625}}
- Add products for the home page to the new category.
- Edit the Home Page (CMS -> Manage Pages -> Home Page) and add the following content, where 8 should be replaced by your category ID:

{{block type="catalog/product_list" category_id="8" template="catalog/product/list.phtml"}}

{{how_to:notice.png}} If your product/list.html references $this->getColumnCount() you can vary the column count (e.g. 4 columns) from the default (3) displayed by using:
{{block type="catalog/product_list" column_count="4" category_id="8" template="catalog/product/list.phtml"}}
Although displaying more than 3 columns in your template would likely require additional CSS/layout changes as well.

If you want a view that is different from the category lists, you can copy and modify list.phtml and change the path above. Following steps is an example.

==== Add Bestsellers to Home Page using the best-selling box of Blue Theme ====
In Blue Theme, there is a sample HTML code in the content box (Admin -> CMS -> Manage Pages -> Home Page) that displays a list of Best Selling Products. You can easily modify list.phtml to reuse the skin of the best-selling box. Adding featured products to Home Page is a matter of clicking to select the required products in the category (Admin -> CMS -> Manage Categories -> Category Products tab) as outlined in the above method and there is no need to mess with the HTML code in the CMS.

- Copy the following code to your preferred text editor
getLoadedProductCollection() ?>
count()): ?>

__('There are no products matching the selection.') ?>
count() ?>


<?php echo $this->htmlEscape($_product->getName()) ?>

htmlEscape($_product->getName()) ?>
getPriceHtml($_product, true) ?>
getRatingSummary()): ?>
getReviewsSummaryHtml($_product, 'short') ?>

getShortDescription()) ?>
__('Learn More') ?>
count() ?>
- Name it homelist.phtml and save it in location ''app/design/frontend/default/blue/template/catalog/product'', create the folders where necessary
- Edit the Home Page (CMS -> Manage Pages -> Home Page) and add the following content, where 19 should be replaced by your category ID:



Best Selling Products

{{block type="catalog/product_list" category_id="19" template="catalog/product/homelist.phtml"}}  


**Please note:** In order to make this work for more than one block of products with different category IDs on the same page, you need to add the following code at the end of your phtml file(s):





===== Alternative way: =====
If you are on 1.4 or greater or 1.7EE or greater then this post is no longer valid as magento has moved to using widgets. You can find a featured product widget here: http://www.magewidgets.com/featured-products-widget.html

If you want more in depth way, try to view this post:
http://inchoo.net/ecommerce/magento/featured-products-on-magento-frontpage/

If you're using Magento v1.1.5 or later, you might want to use these code snippets instead:
http://www.magentocommerce.com/boards/viewthread/4780/P15/#t44262
This approach uses core functions instead of using Zend DB to figure out how to build a query statement.

2 comments:

  1. try to find the information about Magento on this site http://sam-ecommerce.com/. I have read there a lot of useful posts about Magento extension and how to speed up the site. So I think it can be useful for you too.

    ReplyDelete