答案 0 :(得分: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及其总订单数。