Magento 1.9 – Get Order Items from Product SKU and Customer Email

customermagento-1.9ordersproducts

Currently i can retrieve my order collection from customer email like this, but it will retrieve all the order and when i print the data there's no information about product items for each order:

if(Mage::getSingleton('customer/session')->isLoggedIn()) {
      $customer = Mage::getSingleton('customer/session')->getCustomer();
      $email = $customer->getEmail();

      $orderCollection = Mage::getModel('sales/order')->getCollection();
      $orderCollection->addFieldToFilter('customer_email', $email);
      echo "<pre>";
      print_r($orderCollection->getData());
}

basically i want to retrieve an order id based on product sku and customer email so i can get the order items, is there a way to do this?

Best Answer

Can you try this.

if(Mage::getSingleton('customer/session')->isLoggedIn()) {
    $customer = Mage::getSingleton('customer/session')->getCustomer();
    $email = $customer->getEmail();
    $orders = Mage::getModel('sales/order')->getCollection()->addAttributeToFilter('Customer_email',$email);
    echo "<pre>";
    print_r($orders->getData());

}

recently i try and it's work for me also you can try below code to get product sku

foreach ($orders as $order) {
    $orderdata = Mage::getModel('sales/order')->load($order['entity_id']);
    $orderItems = $orderdata->getItemsCollection();
    foreach ($orderItems as $item) {
        echo "<br>".$item->getSku();

    }
}