I am trying to get the number of orders with status 'processing' and below is the code.
$countProcessingOrders = 0;
$processingOrders = Mage::getModel('sales/order')->getCollection()
->addFilter('status', Mage_Sales_Model_Order::STATE_PROCESSING)
->addAttributeToSelect('created_at');
foreach ($processingOrders as $order) {
$countProcessingOrders++;
}
For some reason, the (count) output compared to Magento Admin is off by one. It would be helpful if anyone can give clues as to why this may occur?
Note: I am selecting the 'created_at' attribute for some other purpose.
getSize()
method as compared tocount()
or manual looping if you don't need the collection items otherwise. It is much more efficient.Mage::getModel('sales/order')->getCollection()->addFilter('status', Mage_Sales_Model_Order::STATE_PROCESSING)->getSize()