$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
请帮我。