Instead of trying to do this by adding mysql expressions to the query, try the following:
$orders = Mage::getModel('sales/order')->getCollection(); $orders->addAttributeToFilter('created_at', array( 'from' => '2011-09-01', 'to' => '2011-09-30', )) ->addAttributeToSelect('grand_total') ->addAttributeToFilter('status', array('eq'=>'complete')) ; $grandTotal = 0; foreach($orders as $order) { $grandTotal += $order->getGrand_total(); }
Here we collect the collection, and then fill it with a purple loop and add up the grandiose results for each order in the collection.
Notice that we changed 'date_field' to 'created_at' . You can also put all collection modifiers on one line.
We also added a filter to exclude everything except completed orders. As previously written, he would also take into account the grandiose results from canceled orders. If you want to cancel canceled orders, just delete this line.
source share