4

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

3

First get all order of cutomer last 10 days.

$customer_id=10;
$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')
                ->group('product_id');
    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.