magento:根据当前的产品系列获得最畅销的产品

Niv*_*ved 2 magento

我试图通过覆盖Catalog/Product/List.php来使用当前产品集合检索畅销产品

<?php
 if($this->getRequest()->getParam('best')==1){ 

     $this->_productCollection->getSelect()
          ->joinLeft(array('items'=>'sales_flat_order_item'), "items.product_id = e.entity_id", array('count'=>'SUM(qty_ordered)'))
          ->group('e.entity_id');
     $this->_productCollection->getSelect()->having('SUM(items.qty_ordered) > ?',0);
     return $this->_productCollection;
 }
?>
Run Code Online (Sandbox Code Playgroud)

使用上面的代码我得到以下SQL错误,错误是由于having子句引起的,我怎么能在上面的代码中使用havinh子句来避免产生qty_ordered <1的结果行

SQLSTATE[42S22]: Column not found: 1054 Unknown column 'items.qty_ordered' in 'having clause'
Run Code Online (Sandbox Code Playgroud)

Ren*_*art 10

如果你只想获得最畅销的产品

$storeId    = Mage::app()->getStore()->getId();

$products = Mage::getResourceModel('reports/product_collection')
            ->addOrderedQty()
            ->addAttributeToSelect(array('name', 'price', 'small_image')) //edit to suit tastes
            ->setStoreId($storeId)
            ->addStoreFilter($storeId)
            ->setOrder('ordered_qty', 'desc'); //best sellers on top

Mage::getSingleton('catalog/product_status')->addVisibleFilterToCollection($products);
Mage::getSingleton('catalog/product_visibility')->addVisibleInCatalogFilterToCollection($products);

print_r($products->getData());
Run Code Online (Sandbox Code Playgroud)

查看更多@ http://magentocommerce.com/boards/viewthread/14764