1

I Tried this and it is working but i can only do for a specific customer but i need this for all customer.

<?php
$customer_id = 5;
$_orders = Mage::getModel('sales/order')->getCollection()->addFieldToFilter('customer_id',$customer_id);                        
$_orderCnt = $_orders->count(); //orders count
echo 'Customer with ID '.$customer_id.' has '.$_orderCnt.' orders';
?>
4

Use below code:

<?php
   $customerCollection = Mage::getModel('customer/customer')->getCollection()
      ->addAttributeToSelect('entity_id');

   foreach($customerCollection as $customer){
      $_orders = Mage::getModel('sales/order')->getCollection()->addFieldToFilter('customer_id',$customer->getId());                        
      $_orderCnt = $_orders->count(); //orders count
      echo 'Customer with ID '.$customer_id.' has '.$_orderCnt.' orders';
   }
?>
2

You need to get customer collection. You can iterate through collections. The code for interator can be found in this post

https://stackoverflow.com/questions/3786826/how-to-loop-a-magento-collection

Once you have iterator in place you need to dynamically get each customer id and pass it into your filter.

2

use group by to group them on basis of customer id and then get count from it.. you can use group by on your collection like this : $collection->getSelect()->group('table_name.entityname');

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.