0
点赞
收藏
分享

微信扫一扫

magento创建自定义页面 (Bestseller实例) Bestseller products in Magento

慕容冲_a4b8 2023-04-03 阅读 72


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.

 

magento创建自定义页面 (Bestseller实例) Bestseller products in Magento_ide

 

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 .

 

magento创建自定义页面 (Bestseller实例) Bestseller products in Magento_sed_02

 

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

 

magento创建自定义页面 (Bestseller实例) Bestseller products in Magento_html_03

magento创建自定义页面 (Bestseller实例) Bestseller products in Magento_html_04

 

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

Hope you find this useful.

举报

相关推荐

0 条评论