1
  1. My function returns 0 on total sum of orders from a client when status is set to complete. When status is set to processing, everything goes O.K. Is it the right way to obtain a complete status?
  2. Also, I want to get all the SKUs from the customer of all orders. I tried to change getGrandTotal to getSku() but it returns nothing.

The code:

$customer_email = Mage::getSingleton('customer/session')->getCustomer()->getEmail();
$collection = Mage::getModel('sales/order')->getCollection()
    ->addFieldToFilter('status', 'complete')
    ->addAttributeToFilter('customer_email', array('like' => $customer_email));

foreach ($collection as $order) {
    //do something
    //echo round($order->getGrandTotal(), 2) . " ";
    $sum += $order->getGrandTotal();
}

echo round($sum,2); ?>
1
  • What do you get when you uncomment the echo line? Do you actually see the right grand total(s)? What do you see if you replace it with var_dump()?
    – 7ochem
    Commented Mar 2, 2015 at 10:24

2 Answers 2

1

There is one case when the result can be 0.
Your collection does not have items.
Check what $collection->count() returns.
Well there is actually an other case, but I assume you did not modify the getGrandTotal() method.

0

Nr (2): To get all SKU's you could do...

$skus = array();
foreach ($collection as $order) {
    foreach ($order->getAllItems() as $item) {
        $skus[] = $item->getSku();
    }
}

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.