I can get sales revenue with this

$orderTotals = Mage::getModel( 'sales/order' )->getCollection()
    ->addAttributeToFilter( 'created_at', array( 'from' => date( 'Y-m-d' ), 'to' => date( 'Y-m-d', strtotime( '+1 days' ) ) ) )
    ->addAttributeToSelect( 'grand_total' )
    ->getColumnValues( 'grand_total' );
$totalSum = array_sum( $orderTotals );
$totalSum = Mage::helper( 'core' )->currency( $totalSum, true, false );

echo $totalSum;

But how do I get the total amount of orders and sales shipping total?

also is there a better way to find current days orders as I think I've done it a confusing way. Will this only show today? It appears to look right.


Just a thought, is there a way to count the orders?


I think it's the best solution to do the calculation directly in the Database.

/* Load the Collection by Date */
$order = Mage::getModel('sales/order')->getCollection()
    ->addAttributeToFilter('created_at', array('from' => date('Y-m-d'), 'to' => date('Y-m-d', strtotime('+1 days'))));

    ->reset(Zend_Db_Select::COLUMNS) //remove existings selects
    ->columns(array('grand_total' => new Zend_Db_Expr('SUM(grand_total)'))) //add expresion to sum the grand_total
    ->columns(array('count' => new Zend_Db_Expr('COUNT(entity_id)'))) //add expression to count the orders
    ->columns(array('shipping_total' => new Zend_Db_Expr('SUM(shipping_amount+shipping_tax_amount)'))); //add expression to calculate the shipping costs

$data = $order->getFirstItem(); //because this is a collection, we need just the first item.

echo $data['grand_total'];
echo $data['count'];
echo $data['shipping_total'];

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.