Bestseller products in Magento

来源:互联网 发布:php 调用js 编辑:程序博客网 时间:2024/04/30 05:22

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.


an this, is the final view……

 

原创粉丝点击