Home » Magento Customization, Magento Guide

Bestseller products in Magento

12 September 2009 No Comment

Bestseller products in Magento

Bestseller or best selling product is one of the features people tend to ask for when it comes to Magento™.

There are multiple ways to implement this feature.

In this example, I’m not using controller or model directories at all; I’m going to show you how to implement this feature using only one file: the View.

Basically, what you need to do is to create the directory inside your template directory and place the bestseller.phtml file in it. In my example, I’m using the custom-created directory /inchoo. All of the screenshots provided here are based on that directory structure.

Adding this feature to your store is a matter of two simple steps:

  • copy bestseller-phtml file to your directory
  • display the block on home page

To add a block to a home page, you simply log into the Magento, CMS > Manage Pages > Home. Then add the following to the content area:

{{block type=”core/template” template=”inchoo/bestseller.phtml”}}

Notice the type attribute. I used core/template which means you can place this code anywhere in your site and it will work. Code does not inherit any collection objects from controllers since it has none. All that is necessary for the bestseller.phtml to work is defined in that single file.

One more thing: If you study the code in bestseller.phtml file you will see, at the very top of the file, the part that says: $this->show_total.

If I were to write

{{block type=”core/template” show_total=”12″ template=”inchoo/bestseller.phtml”}}

in my home page, then $this would be assigned property show_total with a value of 12.

Therefore, the provided bestseller.phtml file provides the option of setting the number of products you wish to see listed.

Here is the bestseller.phtml packed in bestseller.zip.

Hope you find this useful.

By Branko Ajzele from inchoo.net

Related posts:

  1. Bestseller module (with Toolbar!) – Magento 1.2.1
  2. Some custom Blocks to help you show products
  3. Adding simple Tweet this for Magento products
  4. How to use WordPress home page in Magento home page (CMS page)
  5. Add Adwords tracking code to order confirmation page in Magento

Leave your response!

Add your comment below, or trackback from your own site. You can also subscribe to these comments via RSS.

Be nice. Keep it clean. Stay on topic. No spam.

You can use these tags:
<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

Spam Protection by WP-SpamFree

Security Code: