Magento 2, Magento Development, Customization, Extension Development and Integration, Optimization, SEO and Responsive Design

Magento 2, Magento Development, Customization, Extension Development and Integration, Optimization, SEO and Responsive Design

How to get order collection from customer email id magento


If you want to get order collection for particular user anywhere in magento using customer email ID you can simply get this using following simple code.

For that first you need to get current logged user email ID. So use following code for getting logged user email id:


     $customer = Mage::getSingleton('customer/session')->getCustomer();
     $email = $customer->getEmail();     
     $fullname = $customer->getName();
     $firstname = $customer->getFirstname();
     $lastname = $customer->getLastname();

Now you have customer email address in your $email variable. So you can easily get order collection using this email address as following: 

     $orderCollection = Mage::getModel(‘sales/order’)->getCollection();
     $orderCollection->addFieldToFilter(‘customer_email’, $email);

    foreach ($orderCollection as $_order)
    {
        echo $_order->getRealOrderId() ;
        echo $this->formatDate($_order->getCreatedAtStoreDate()) ;
        echo $_order->getShippingAddress() ? $this->escapeHtml($_order->getShippingAddress()->getName()) ;
        echo $_order->formatPrice($_order->getGrandTotal());
        echo $_order->getStatusLabel();
     }


Please support us, Like us on Facebook.

0 comments:

Post a Comment

 

Copyright @ 2017 HKBlog.