2014-07-15 86 views
0

我使用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); 

另一部分用於segmentating基於訂單:

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);有關,但我不完全確定如何實現這一點。

非常感謝您的幫助。

回答

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 
    */ 
} 
+0

感謝這樣的代碼,但實際上我真的不知道在哪裏把它在我的例子張貼在上面。 –

0

你可以試一下這個

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

感謝您的幫助,但不幸的是,這並沒有幫助。我正在使用由advanceWorks提供的市場細分套件。我得到的唯一提示是在一個特定的文件中看看這兩行= / –

相關問題