在Magento商店社区版v1.7的主页上显示最佳产品


Displaying the best products in the home page of a Magento Store Community edition v1.7

我正试图在主页上展示演示商店Community edition v1.7的最佳产品,首先,我尝试从这个链接安装一个名为Magento畅销产品扩展的扩展http://www.magentocommerce.com/magento-connect/bestseller-products-7401.html,但它不起作用

所以我决定自己生产最好的产品,

为了实现这一点,我创建了两个文件:

app/code/core/Mage/Catalog/Block/Product/MyBestSeller.php
app/design/frontend/default/my_theme/template/catalog/product/mybestseller.phtml    

我在主页上加了一行:

{{block type="catalog/product_mybestseller" template="catalog/product/mybestseller.phtml"}}

然后我刷新了缓存

我的问题是什么都没有输出!这是在主页中输出数据的正确方式吗?

这是MyBestSeller.php 的代码

class Mage_Catalog_Block_Product_MyBestSeller extends Mage_Catalog_Block_Product_Abstract{
public function __construct()
{
    parent::__construct();
    $storeId    = Mage::app()->getStore()->getId();
    $products = Mage::getResourceModel('reports/product_collection')
        ->addAttributeToSelect('*')
        ->setStoreId($storeId)
        ->addStoreFilter($storeId)
        ->setOrder('ordered_qty', 'desc');
    Mage::getSingleton('catalog/product_status')->addVisibleFilterToCollection($products);
    Mage::getSingleton('catalog/product_visibility')->addVisibleInCatalogFilterToCollection($products);
    $products->setPageSize(6)->setCurPage(1);
    $this->setProductCollection($products);
}

}

我的畅销书.html是这样开始的(我认为其余的代码并不重要,这就是我没有包含它的原因):

<h2 style="background-color: red">from myestseller.phtml</h2><!-- just a test -->
<?php if (($_products = $this->getProductCollection()) && $_products->getSize()): ?>
<?php $_collectionSize = count($_products->getItems()) ?>
<table class="products-grid" id="products-grid-table">
<?php $i=1; foreach ($_products->getItems() as $_product): ?>

提前感谢您的帮助

最后,我通过关闭系统->工具->编译->禁用来解决了我的问题