2013-10-18 53 views
0

全部。我試圖從數據庫中獲取所有訂單項目,其中訂單狀態未被「取消」。下面是一段代碼:Magento。未知列'sales_flat_order_item.order_id'

$items = Mage::getModel('sales/order_item')->getCollection(); 
$rents->getSelect()->join(array('sales_order'=>Mage::getSingleton('core/resource')->getTableName('sales/order')), Mage::getSingleton('core/resource')->getTableName('sales/order_item') . '.order_id = sales_order.entity_id', array('sales_order.state')); 
$rents->addFilter('product_id', $productId); 
$rents->addFilter('state', array('neq' => 'canceled')); 

DUT,當我試圖運行這段代碼,我得到一個錯誤:「列未找到:1054未知列在‘sales_flat_order_item.order_id’‘的條款’」下面的代碼

回答

0

嘗試慾望的結果,我試圖與訂購的產品之一。

$items = Mage::getModel('sales/order_item')->getCollection(); 
$items->getSelect()->join(array('sales_order'=>Mage::getSingleton('core/resource')->getTableName('sales/order')), 'main_table.order_id = sales_order.entity_id', array('sales_order.state')); 
$items->getSelect()->where('product_id=?', $productId); 
$items->getSelect()->where('state!=?','canceled'); 
echo $items->getSelect();// will print sql query 
print_r($items->getData()); // will print order into array format 

希望它能幫上忙!