Magento 1.9 Orders – Get Order Collection Last One Year Month Wise

collection;magento-1.9orderssales-order

I need to get order collection of last one year, In which I have to show data month wise like

Jan - xxx(Orders)
Feb - xxx(Orders)

Best Answer

Try below code

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

/* Get the collection */
$orders = Mage::getModel('sales/order')->getCollection()
    ->addAttributeToFilter('created_at', array('from'=>$fromDate, 'to'=>$toDate))
    ->addAttributeToFilter('status', array('eq' => Mage_Sales_Model_Order::STATE_COMPLETE))->setOrder('created_at', 'ASC');
$archive=array();
foreach ($orders as $order) {
            $tmp=array();
            $time=strtotime($order->getCreatedAt());
            //save Data you want show in $tmp array
            $archive[date("Y",$time)][date("F",$time)][]=$tmp;
}
Related Topic