I am looking for collection which have number of products that ordered by specific customer. If anyone have any suggestion please share.


First get all order of cutomer last 10 days.

$toDate = date('Y-m-d H:i:s');
$fromDate = date('Y-m-d H:i:s', strtotime('-10 days',strtotime()));

$orders = Mage::getModel('sales/order')->getCollection()
    ->addFieldToFilter('customer_id', $customer_id)
    ->addAttributeToFilter('created_at', array('from'=>$fromDate, 'to'=>$toDate));

$ordersIds =$orders->getAllIds();

Then count number of product order on that orders.

   $collection = Mage::getResourceModel('sales/order_item_collection');
   $collection->addFieldToFilter('order_id',array('in' => $ordersIds));//order_id exist in array
   $collection ->getSelect()
                ->columns('SUM(qty_ordered) as total_qty')
    echo $collection->getFirstItem()->getTotalQty();

    foreach($collection as $collect)
        echo $collection->getTotalQty();

Not tested code only giving you general idea.

  • internal server error coming..where itemCollection varible define? – Ram Pratap Singh Gour Dec 15 '16 at 12:24
  • @Ramsystematix updated code.. – Fme Extensions Dec 15 '16 at 12:34
  • 1
    Yup! working for me. – Ram Pratap Singh Gour Dec 15 '16 at 12:43
  • Hi can u give me some idea on how can i get total order amount , instaed of product details. I want the grand total of all the orders within 10 days – Nafsss Mar 31 '20 at 4:57

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.