gpt4 book ai didi

玛根托 : get best selling products based on the current product collection

转载 作者:行者123 更新时间:2023-12-02 16:53:02 25 4
gpt4 key购买 nike

我正在尝试通过覆盖 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;
}
?>

使用上面的代码我收到以下 SQL 错误,该错误是由于having子句引起的,我如何在上面的代码中使用 havinh 子句来避免结果行具有 qty_ordered<1

SQLSTATE[42S22]: Column not found: 1054 Unknown column 'items.qty_ordered' in 'having clause'

最佳答案

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

$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());

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

关于玛根托 : get best selling products based on the current product collection,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13258371/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com