繁体   English   中英

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

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

我试图在首页上展示演示商店社区版v1.7的最佳产品,首先,我尝试从此链接http://www.magentocommerce.com/magento-connect安装名为Magento Bestseller Products Extension的扩展 /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);
}

}

mybestseller.phtml就是这样开始的(我认为其余代码并不重要,这就是为什么我没有包含它的原因):

<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): ?>

在此先感谢您的帮助

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM