8

我使用以下行从 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')));
4

2 回答 2

13

使用addFieldToFilter方法

$order_collection = Mage::getModel('sales/order')->getCollection()->addFieldToFilter('status', array('nin' => array('canceled','complete')));
于 2013-05-13T14:38:03.323 回答
2

如果要使用原始定义:

$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';
于 2017-01-20T11:45:58.173 回答