0

全部。我正在尝试从数据库中获取所有订单项目,其中订单状态未“取消”。这是一段代码:

$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 Unknown column 'sales_flat_order_item.order_id' in 'on Clause'”

4

1 回答 1

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

希望它会有所帮助!

于 2013-10-18T13:45:51.257 回答