0

I'm trying to do the sum of the amount of all complete orders by a particular customer. I write this to do so:

$collectionOrders = Mage::getModel('sales/order')->getCollection()->addFieldToFilter('customer_email', $email)->addFieldToFilter('status', 'complete');
foreach ($collectionOrders as $order) {
    $total += $order->getGrandTotal();
}
echo $total . "\n";

But when i check in the admin section the orders, i find the value of is actually higher. I think i've got something wrong in the loop.

  • do you give any value for $total?? Like $total = 0; – Asish Hira Apr 11 '16 at 11:38
2

Replace your code with this :

    <?php
    $total=0;
    $collectionOrders = Mage::getModel('sales/order')->getCollection()->addFieldToFilter('customer_email',$email)->addFieldToFilter('status','complete');
       foreach($collectionOrders as $order){
               $total += $order->getGrandTotal();
       }
        echo $total."\n";

?>

See more here.

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.