我使用以下行来加载来自magento的订单集合:
// Load Order Collection
$order_collection = Mage::getModel('sales/order')->getCollection();
如何过滤此集合以忽略状态为“已取消”和“已完成”的订单?
更新
发布后,我感到无聊,所以我做了一些挖掘,这篇文章帮助我找到了正确的代码行:http://www.magentocommerce.com/boards/v/viewthread/201797/#t287235
这就是我解决它的方法:
// Load Order Collection
$order_collection = Mage::getModel('sales/order')
->getCollection()
->addAttributeToSelect('*')
->addAttributeToFilter('status', array('nin' => array('canceled','complete')));
答案 0 :(得分:12)
使用addFieldToFilter
方法
$order_collection = Mage::getModel('sales/order')->getCollection()->addFieldToFilter('status', array('nin' => array('canceled','complete')));
答案 1 :(得分:1)
如果您想使用原始定义:
$order_collection = Mage::getModel('sales/order')->getCollection()
->addFieldToFilter('status', array('nin' => array(
Mage_Sales_Model_Order::STATE_NEW,
Mage_Sales_Model_Order::STATE_CANCELED
)));
在Mage_Sales_Model_Order中定义:
/**
* Order states
*/
const STATE_NEW = 'new';
const STATE_PENDING_PAYMENT = 'pending_payment';
const STATE_PROCESSING = 'processing';
const STATE_COMPLETE = 'complete';
const STATE_CLOSED = 'closed';
const STATE_CANCELED = 'canceled';
const STATE_HOLDED = 'holded';
const STATE_PAYMENT_REVIEW = 'payment_review';