获取状态已完成的订单数量' AND'处理'

时间:2014-07-15 12:18:14

标签: php api magento mage

我使用Magento市场细分插件,我试图不仅分割具有订单状态的用户"已完成"但是"完成" AND"处理"。

基于客户进行细分的原始代码部分如下所示:

if ($this->getAttribute() == 'ordered') {
        $customersOrders = Mage::helper('marketsuite/customer')->getOrderCollectionByCustomerIds($_customerIds);
        $customersOrders->addFieldToFilter('state', Mage_Sales_Model_Order::STATE_COMPLETE);
        $_arrayOrderIdCustomerId = $customersOrders->getConnection()->fetchPairs($customersOrders->getSelect());
        $_arrayOrderIdTotal = $this->_getValidatedTotalOrderedCount(array_keys($_arrayOrderIdCustomerId));
        $_validatedArrayOrderIdCustomerId = array_intersect_key($_arrayOrderIdCustomerId, $_arrayOrderIdTotal);

基于订单进行细分的另一部分:

public function validateOrderCollection(Zend_Db_Select $select)
{
    if ($this->getAttribute() == 'ordered') {
        $select
            ->where('state = ?', Mage_Sales_Model_Order::STATE_COMPLETE)
        ;
        $_orderIds = Mage::helper('marketsuite/order')->getAllIds($select);
        $orderTotals = $this->_getValidatedTotalOrderedCount($_orderIds);
        $validatedOrders = array();
        foreach ($orderTotals as $orderId => $totalOrderedCount) {
            if ($this->validateAttribute($totalOrderedCount)) {
                array_push($validatedOrders, $orderId);
            }
        }
        return $validatedOrders;
    }
    return array();
}

问题:我如何同时包含"已完成"和"处理"两种情况下的订单。我知道它与这部分$customersOrders->addFieldToFilter('state', Mage_Sales_Model_Order::STATE_COMPLETE);有关,但我不确定如何实现这一点。

非常感谢您的帮助。

2 个答案:

答案 0 :(得分:0)

您可以尝试以下方法:

$connection = Mage::getModel('core/resource')->getConnection('core_read');
$sql = 'SELECT `customer_id` FROM `sales_flat_order` WHERE `status` LIKE ? OR `status` LIKE ?';
$customers = $connection->fetchAll($sql, array('complete', 'processing'));
$customer = Mage::getModel('customer/customer');
foreach ($customers as $customer_info){
    $customer = $customer->load($customer_info['customer_id']);
    /* Do what you need to do here, e.g:
     * echo $customer->getName() . "<br/>";
     * This example will print all customers who have complete/processing orders full names
     */
}

答案 1 :(得分:0)

您可以尝试这样的事情

$customersOrders->addFieldToFilter('state', 
          array(
                    array('eq' => Mage_Sales_Model_Order::STATE_COMPLETE),
                    array('eq' => Mage_Sales_Model_Order::STATE_PROCESSING),
                )
);