Magento客户按订单数量过滤仅完成状态

时间:2017-04-05 08:24:18

标签: magento

enter image description here

我们只想显示订单状态。我在查询“orders_sum_amount / orders_count”中尝试过滤但是失败。

1 个答案:

答案 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及其总订单数。

相关问题