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.

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.