0

How to show list of top 10 customers, who have purchased most of the products on the site.

2

For top 5 customer order collection you can use

$_collection = Mage::getModel('sales/order')->getCollection();
echo $_collection->getSelect()
    ->columns('COUNT(*) AS cus')
    ->group('customer_id')
    ->order('cus DESC')->limit('5');

Row Query

SELECT main_table., COUNT() AS cus FROM sales_flat_order AS main_table GROUP BY customer_id ORDER BY cus DESC LIMIT

cheers

| improve this answer | |
0

I've created new file inside mychildtheme/template/catalog/category/toptencustomer.phtml

<php    
$registerCustomerOrderCollection = Mage::getModel('sales/order')
    ->getCollection()
    ->addFieldToFilter('customer_id', array('notnull' => true));
    $orderarray = [];
    foreach ($registerCustomerOrderCollection as $order)
        {
                    $order_cust = $order->getCustomerEmail(); 
                    $orderarray[] = $order_cust;
        }
        $ordercounts = array_count_values($orderarray);
        echo "<h2>Top 10 Customers</h2>";
        arsort($ordercounts);
        $count_order = count($ordercounts);

    foreach($ordercounts as $ordercounter=>$x_value)
    {
        $arr = explode('@', $ordercounter);
        $important = $arr[0];
        $imparray[] = $important;
    }

    $output = array_slice($imparray, 0, 10);
        foreach ($output as $cust_name) 
        {
            echo '<h4>'.$cust_name.'</h4>';
        }
?>

It gives me top 10 customers, who have purchased most of the products on the site.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.