Magento 1.6.2畅销产品无效

时间:2012-04-12 13:06:50

标签: magento

$storeId = Mage::app()->getStore()->getId();
$products = Mage::getResourceModel('reports/product_collection')
->addOrderedQty()
->addAttributeToSelect(array('name', 'price', 'small_image', 'short_description', 'description'))
->addStoreFilter($storeId)
->setPageSize(4)
->setCurPage(1)
->setOrder('ordered_qty', 'desc')->load();

畅销书代码在Magento 1.6.2中无效。该集合甚至未被商店过滤。

Zend_Debug::dump($storeId);给了我string '2' (length=1)但是我无法执行Zend_Debug::dump($products->getSelect());,因为它给了我一个像There has been and error processing your request这样的错误,它给了我以下查询:

SELECT SUM(order_items.qty_ordered) AS ordered_qty, order_items.name AS order_items_name, order_items.product_id AS entity_id, e.entity_type_id, e.attribute_set_id, e.type_id, e.sku, e.has_options, e.required_options, e.created_at, e.updated_at, e.name, e.price, e.small_image, e.short_description FROM tp_sales_flat_order_item AS order_items INNER JOIN tp_sales_flat_order AS order ON order.entity_id = order_items.order_id AND order.state <> 'cancelled' LEFT JOIN tp_catalog_product_entity AS e ON (e.type_id NOT IN ('grouped', 'configurable', 'bundle')) AND e.entity_id = order_items.product_id AND e.entity_type_id = 4 WHERE (parent_item_id IS NULL) GROUP BY order_items.product_id HAVING (SUM(order_items.qty_ordered) > 0) ORDER BY ordered_qty desc LIMIT 4

请帮帮我。

4 个答案:

答案 0 :(得分:1)

试试这个:

<?php 
    $products = Mage::getResourceModel('reports/product_collection')
               ->addAttributeToSelect('*')
               ->addOrderedQty($from, $to, true)
               ->addAttributeToSelect(array('name', 'price', 'small_image'))
               ->addCategoryFilter($category)
               ->setStoreId($storeId)
               ->addStoreFilter($storeId)
               ->setOrder('ordered_qty', 'desc');
?>

答案 1 :(得分:0)

试试这个:

$storeId = Mage::app()->getStore()->getId();
$products = Mage::getResourceModel('reports/product_collection')
->addOrdersCount()
->addAttributeToSelect(array('name', 'price', 'small_image', 'short_description', 'description'))
->addStoreFilter($storeId)
->setPageSize(4)
->setCurPage(1)
->setOrder('orders', 'desc')->load();

更改是addOrdersCount()方法和 - &gt; setOrder()方法。

答案 2 :(得分:0)

我也在magento 1.6.2中面对这类问题。 我发现在过滤集合时属性过滤器存在一些问题。

我已将 addAttributeToFilter 替换为 addFieldToFilter 以及它的工作。

尝试这可能会对您的

有所帮助

答案 3 :(得分:0)

尝试为集合设置storeid。添加OrderedQty后插入此行:

->setStoreId($storeId)