Magento客户(按订单数量)仅筛选完成状态

Magento客户(按订单数量)仅筛选完成状态,magento,Magento,我们只想显示订单状态已完成。我曾尝试在查询“订单金额/订单数量”中进行筛选,但失败。我在我的Magento根目录中尝试了此操作,它将为我提供所有客户的id及其订单总数 您想要的是,当您获得订单集合时,您需要使用状态过滤器 $orders = Mage::getModel('sales/order')->getCollection() ->addFieldToFilter('status', 'complete');//This gives all orders which a


我们只想显示订单状态已完成。我曾尝试在查询“订单金额/订单数量”中进行筛选,但失败。

我在我的Magento根目录中尝试了此操作,它将为我提供所有客户的
id
及其
订单总数

您想要的是,当您获得订单集合时,您需要使用状态过滤器

$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;
$orders=Mage::getModel('sales/order')->getCollection()
->addFieldToFilter(“状态”、“完成”)//这将给出所有已完成的订单
$customerIds=array();
foreach($v=>$order的订单){
if(在数组中($order['customer\u id',$customerIds)){
}否则{
$customerIds[]=$order['customer_id'];
}   
}//现在,在$customerIds中,您将拥有所有客户ID。
$cIds=数组过滤器($customerIds)//这将从$CustomerID中删除空值
$result=array();
foreach($cIds作为$k=>$customerId){
$ord=Mage::getModel('sales/order')->getCollection()
->addFieldToFilter('状态','完成')
->addFieldToFilter('customer\u id',$customerId);
$result[$k]['customer\u id']=$customerId;
$result[$k]['total_order']=count($ord->getData());
}
回声“;打印(结果);死亡

$result
数组中,您将获得所有客户ID及其总订单数。

如果有效,那么您应该接受答案@Anwar