2017-04-05 53 views

回答

0

我在我的Magento根目錄中試過這個,它給我所有的客戶id和他們的total order count

你想要的是當你得到訂單集合,你需要使用過濾器的狀態。

$orders = Mage::getModel('sales/order')->getCollection() 
    ->addFieldToFilter('status', 'complete');//This gives all orders which are completed 

$customerIds = array(); 

    foreach($orders as $v => $order){ 

     if(in_array($order['customer_id'],$customerIds)){ 

      }else{ 
      $customerIds[] = $order['customer_id']; 
     } 
    }// now in $customerIds you will have all customer ids. 
$cIds = array_filter($customerIds);//This will remove empty value from $customerIds 
    $result = array(); 
    foreach($cIds as $k => $customerId){ 
     $ord = Mage::getModel('sales/order')->getCollection() 
     ->addFieldToFilter('status', 'complete') 
     ->addFieldToFilter('customer_id', $customerId); 

     $result[$k]['customer_id'] = $customerId; 
     $result[$k]['total_order'] = count($ord->getData()); 
    } 

    echo "<pre>";print_r($result);die; 

而且在$result陣列,您將擁有所有的客戶ID和它們的總訂單數。

+0

很好的幫助!它運作良好。 – Anwar

+0

如果它在工作,那麼你應該接受@Anwar的答案 – Vky