我想知道为产品下了多少订单。为此,我想使用以下代码,但它不提供任何输出:
$order = Mage::getModel('sales/order');
$order_detail=$order->setStoreId($storeId)->getCollection()- >addAttributeToFilter('product_id',$product_id);
print_r($order_detail);
请告诉我哪里错了?
答案 0 :(得分:1)
尝试使其工作,您需要使用模型Mage_Sales_Model_Order_Item而不是Mage_Sales_Model_Order:
$order = Mage::getModel('sales/order_item');
$order_detail = $order->getCollection()
->addAttributeToFilter('store_id', Mage::app()->getStore()->getId())
->addAttributeToFilter('product_id', $product_id)
//->load(); // if you don't use $order_detail->getItems() below uncomment it
foreach ($order_detail->getItems() as $order){
echo $order->getId();
echo '<br>';
}