in Magento 1.9 I am working on order collection I am getting order collection successfully using the 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));

3 Answers 3


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();

  • i also want to skip if orders status follow one of them i want skip those orders
    – imtiazau
    May 15, 2019 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, 2019 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, 2019 at 9:35

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

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


foreach ($ordercollection as $orderkey => $ordervalue) { 
    foreach ($ordervalue->getAllVisibleItems() as $item) {
        $sku = $item->getSku();
        $name = $item->getName();
        $qty = $item->getOrderedQty();

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();

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.