How to find the number of orders canceled, processed, pending etc from the order collection. Currently I am clearing the loaded collection and applying the filters and calling count. So for all the status I am getting the count. But When checked the mysql logs I understand that its making lot of queries, Is there way I can do it optimally.?

1 Answer 1


you can get it like that

$orders = Mage::getModel('sales/order')->getCollection()

   echo  count($orders->getAllIds());

you can get it direct query

$connectionresource = Mage::getSingleton('core/resource');
    $readconnection = $connectionresource->getConnection('core_read');
$sel_qry = "SELECT COUNT(*),`status` FROM sales_flat_order  GROUP BY  `status`";
$selected = $readconnection->fetchAll($sel_qry);
  • Then for all status I have to do it right ? So If there is 7 status then 7 time the collection is loaded. Is there a way I can do it in a single operation like using Mysql Group command or something
    – ted
    Oct 15, 2015 at 11:45
  • you can use the query method to get the result... Oct 15, 2015 at 12:14

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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