0

in magento 1.9 i am working on order collection i am getting order collection successfully using below code now i want to get item details from order how i can get this .i am using this collection

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

You can fetch the order items using the below code snippet. Loop through each order and get the item details.

$orders = Mage::getModel('sales/order')->getCollection()
->addAttributeToFilter('created_at',array('from'=>$fromDate, 'to'=>$toDate));
$items = array();
foreach($orders as $order) {
    // Get Items from the order
    foreach($order->getAllItems() as $orderItem){
         $items[] = $orderItem->getData();

     }
}
| improve this answer | |
  • i also want to skip if orders status follow one of them i want skip those orders – imtiazau May 15 '19 at 8:11
  • Add the status filter at the end of your order collection $orders = Mage::getModel('sales/order')->getCollection() ->addAttributeToFilter('created_at',array('from'=>$fromDate, 'to'=>$toDate)) ->addAttributeToFilter('status', array('in' => array('canceled','complete'))); – mydons May 15 '19 at 8:54
  • Actually you can either use 'in' (In Filter) or 'nin' (Not In Filter) to skip or fetch the orders you want – mydons May 15 '19 at 9:35
0

You can try fetching order collection and item details by the following code

$ordercollection = Mage::getResourceModel('sales/order_item_collection')
        ->addAttributeToSelect('order_id')
        ->addAttributeToSelect('created_at')
        ->addAttributeToFilter('created_at', array('from' => $fromDate, 'to' => $toDate))
        ->load();

        count($ordercollection);

foreach ($ordercollection as $orderkey => $ordervalue) { 
    foreach ($ordervalue->getAllVisibleItems() as $item) {
        $sku = $item->getSku();
        $name = $item->getName();
        $qty = $item->getOrderedQty();
        }
    }
| improve this answer | |
0

Your code:

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

Getting order item ids:

$orderedItems = $orders->getAllVisibleItems();
$orderedProductIds = [];
foreach ($orderedItems as $item) {
    $orderedProductIds[] = $item->getData('product_id');
}

Getting products:

$productCollection = Mage::getModel('catalog/product')->getCollection();
$productCollection->addAttributeToSelect('*');
$productCollection->addIdFilter($orderedProductIds)
| improve this answer | |

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.