2017-04-05 71 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