Get all orders of customer by email id Magento 2Not getting NULL value or empty value when the filter fails.Why?Magento send orders email to randomHow to get name and email address of all the customer from beginning of the store?Get All Orders from DatabaseMagento: How to get customer last order by joining customers and orders?Magento 2: How to override newsletter Subscriber modelmagento 2 place order programmatically from controllerMagento 2 get custom attribute of a single product inside a pluginMagento 2 How to disable price from orders, customer account and order view if custom module is enabled?Magento 2 plugin change price of products that have a custom attribute with

How to cope with regret and shame about not fully utilizing opportunities during PhD?

Why are solar panels kept tilted?

Does SQL Server allow (make visible) DDL inside a transaction to the transaction prior to commit?

Wireless headphones interfere with Wi-Fi signal on laptop

Trim trailing zeroes off a number extracted by jq

How exactly does artificial gravity work?

Does gravity affect the time evolution of a QM wave function?

Why is it harder to turn a motor/generator with shorted terminals?

Do Life Drain attacks from wights stack?

Determine the slope and write the Cartesian equation of the line.

Why was Thor doubtful about his worthiness to Mjolnir?

Why did the metro bus stop at each railway crossing, despite no warning indicating a train was coming?

Effects of ~10atm pressure on engine design

Smallest Guaranteed hash collision cycle length

Ito`s Lemma problem

Why does lemon juice reduce the "fish" odor of sea food — specifically fish?

Do I need to say 'o`clock'?

Find hamming distance between two Strings of equal length in Java

Magento 2: How to get type columns of table in sql?

What kind of SATA connector is this?

How to distinguish PICTURE OF ME and PICTURE OF MINE in Chinese?

Developers demotivated due to working on same project for more than 2 years

Newly installed programs always appear with external drives in Finder

Unexpected Netflix account registered to my Gmail address - any way it could be a hack attempt?



Get all orders of customer by email id Magento 2


Not getting NULL value or empty value when the filter fails.Why?Magento send orders email to randomHow to get name and email address of all the customer from beginning of the store?Get All Orders from DatabaseMagento: How to get customer last order by joining customers and orders?Magento 2: How to override newsletter Subscriber modelmagento 2 place order programmatically from controllerMagento 2 get custom attribute of a single product inside a pluginMagento 2 How to disable price from orders, customer account and order view if custom module is enabled?Magento 2 plugin change price of products that have a custom attribute with






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;








1















How can I get all orders of a customer via his/her email id who is logged in,
I am using current session to get user's email id



public function getCustomerData() 
if ($this->_customerSession->isLoggedIn())
return $this->_customerSession->getCustomerData();

return false;



In phtml



 $customerData = $block->getCustomerData();
if($customerData)
echo 'Customer Email: ' . $customerData->getEmail() . '<br/>';


Earlier I was getting my orders information by order id



public function getOrderInformation($orderid)

$objectManager = MagentoFrameworkAppObjectManager::getInstance();
$order = $objectManager->create('MagentoSalesApiOrderRepositoryInterface')->get($orderid);
return $order;



How can I get all orders by customer email id










share|improve this question






























    1















    How can I get all orders of a customer via his/her email id who is logged in,
    I am using current session to get user's email id



    public function getCustomerData() 
    if ($this->_customerSession->isLoggedIn())
    return $this->_customerSession->getCustomerData();

    return false;



    In phtml



     $customerData = $block->getCustomerData();
    if($customerData)
    echo 'Customer Email: ' . $customerData->getEmail() . '<br/>';


    Earlier I was getting my orders information by order id



    public function getOrderInformation($orderid)

    $objectManager = MagentoFrameworkAppObjectManager::getInstance();
    $order = $objectManager->create('MagentoSalesApiOrderRepositoryInterface')->get($orderid);
    return $order;



    How can I get all orders by customer email id










    share|improve this question


























      1












      1








      1








      How can I get all orders of a customer via his/her email id who is logged in,
      I am using current session to get user's email id



      public function getCustomerData() 
      if ($this->_customerSession->isLoggedIn())
      return $this->_customerSession->getCustomerData();

      return false;



      In phtml



       $customerData = $block->getCustomerData();
      if($customerData)
      echo 'Customer Email: ' . $customerData->getEmail() . '<br/>';


      Earlier I was getting my orders information by order id



      public function getOrderInformation($orderid)

      $objectManager = MagentoFrameworkAppObjectManager::getInstance();
      $order = $objectManager->create('MagentoSalesApiOrderRepositoryInterface')->get($orderid);
      return $order;



      How can I get all orders by customer email id










      share|improve this question
















      How can I get all orders of a customer via his/her email id who is logged in,
      I am using current session to get user's email id



      public function getCustomerData() 
      if ($this->_customerSession->isLoggedIn())
      return $this->_customerSession->getCustomerData();

      return false;



      In phtml



       $customerData = $block->getCustomerData();
      if($customerData)
      echo 'Customer Email: ' . $customerData->getEmail() . '<br/>';


      Earlier I was getting my orders information by order id



      public function getOrderInformation($orderid)

      $objectManager = MagentoFrameworkAppObjectManager::getInstance();
      $order = $objectManager->create('MagentoSalesApiOrderRepositoryInterface')->get($orderid);
      return $order;



      How can I get all orders by customer email id







      magento2 orders sales-order magento2.3 order-email






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited May 9 at 5:58









      Muhammad Hasham

      3,80231656




      3,80231656










      asked Feb 15 at 4:38









      summusummu

      17710




      17710




















          2 Answers
          2






          active

          oldest

          votes


















          2














          $objectManager = MagentoFrameworkAppObjectManager::getInstance();
          $resource = $objectManager->get('MagentoFrameworkAppResourceConnection');
          $connection = $resource->getConnection();

          //*****************loading Customer session *****************//
          $customerSession = $objectManager->create('MagentoCustomerModelSession');

          //******** Checking whether customer is logged in or not ********//
          if ($customerSession->isLoggedIn())
          $customer_email = $customerSession->getCustomer()->getEmail();

          // ***********Getting order collection using customer email id ***********//
          $order_collection = $objectManager->create('MagentoSalesModelOrder')->getCollection()->addAttributeToFilter('customer_email', $customer_email);

          //echo "<pre>";print_r($order_collection->getData());
          foreach ($order_collection as $order)
          echo "Order Id: ".$order->getEntityId();
          echo "Customer Id: ".$order->getCustomerId();





          Order collection based on logged in Customer Email Id (Customer All orders)




          I hope this will help






          share|improve this answer

























          • how to get entity id and customer id from $order_collection->getData() my output is like this . Array ( [0] => Array ( [entity_id] => 166952 ) ) customerid 12004 . , what kind of format is this its not json for sure

            – summu
            Feb 15 at 10:22












          • i get this error . Call to undefined method MagentoSalesModelResourceModelOrderCollection::getEntityId()

            – summu
            Feb 15 at 10:29











          • foreach ($order_collection as $order) echo "Order Id: ".$order->getEntityId(); echo "Customer Id: ".$order->getCustomerId(); try this

            – Muhammad Hasham
            Feb 15 at 10:33



















          2














          Try this,



          <?php 
          namespace VendorModuleControllerOrders;
          class ReadOrders extends MagentoFrameworkAppActionAction
          public function __construct(
          MagentoFrameworkAppActionContext $context,
          MagentoSalesModelResourceModelOrderCollectionFactory $orderCollectionFactory,
          MagentoCustomerModelSessionFactory $customerSession)
          $this->_customerSession = $customerSession->create();
          $this->orderCollectionFactory = $orderCollectionFactory;
          parent::__construct($context);


          public function getCustomerData()

          if ($this->_customerSession->isLoggedIn())
          return $this->_customerSession->getCustomerData()->getEmail();


          public function execute()

          if (!$this->_customerSession->isLoggedIn())
          return;

          $orders = $this->orderCollectionFactory->create()
          ->addAttributeToFilter('customer_email', $this->getCustomerData());
          foreach ($orders as $items)
          echo $items->getCustomerEmail() . '<pre>';




          Hope this help, if you need any other information. Let me know.
          Peace :)






          share|improve this answer


















          • 1





            Nice effort. +1

            – Muhammad Hasham
            Mar 28 at 9:59












          Your Answer








          StackExchange.ready(function()
          var channelOptions =
          tags: "".split(" "),
          id: "479"
          ;
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function()
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled)
          StackExchange.using("snippets", function()
          createEditor();
          );

          else
          createEditor();

          );

          function createEditor()
          StackExchange.prepareEditor(
          heartbeatType: 'answer',
          autoActivateHeartbeat: false,
          convertImagesToLinks: false,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: null,
          bindNavPrevention: true,
          postfix: "",
          imageUploader:
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          ,
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          );



          );













          draft saved

          draft discarded


















          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmagento.stackexchange.com%2fquestions%2f261912%2fget-all-orders-of-customer-by-email-id-magento-2%23new-answer', 'question_page');

          );

          Post as a guest















          Required, but never shown

























          2 Answers
          2






          active

          oldest

          votes








          2 Answers
          2






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes









          2














          $objectManager = MagentoFrameworkAppObjectManager::getInstance();
          $resource = $objectManager->get('MagentoFrameworkAppResourceConnection');
          $connection = $resource->getConnection();

          //*****************loading Customer session *****************//
          $customerSession = $objectManager->create('MagentoCustomerModelSession');

          //******** Checking whether customer is logged in or not ********//
          if ($customerSession->isLoggedIn())
          $customer_email = $customerSession->getCustomer()->getEmail();

          // ***********Getting order collection using customer email id ***********//
          $order_collection = $objectManager->create('MagentoSalesModelOrder')->getCollection()->addAttributeToFilter('customer_email', $customer_email);

          //echo "<pre>";print_r($order_collection->getData());
          foreach ($order_collection as $order)
          echo "Order Id: ".$order->getEntityId();
          echo "Customer Id: ".$order->getCustomerId();





          Order collection based on logged in Customer Email Id (Customer All orders)




          I hope this will help






          share|improve this answer

























          • how to get entity id and customer id from $order_collection->getData() my output is like this . Array ( [0] => Array ( [entity_id] => 166952 ) ) customerid 12004 . , what kind of format is this its not json for sure

            – summu
            Feb 15 at 10:22












          • i get this error . Call to undefined method MagentoSalesModelResourceModelOrderCollection::getEntityId()

            – summu
            Feb 15 at 10:29











          • foreach ($order_collection as $order) echo "Order Id: ".$order->getEntityId(); echo "Customer Id: ".$order->getCustomerId(); try this

            – Muhammad Hasham
            Feb 15 at 10:33
















          2














          $objectManager = MagentoFrameworkAppObjectManager::getInstance();
          $resource = $objectManager->get('MagentoFrameworkAppResourceConnection');
          $connection = $resource->getConnection();

          //*****************loading Customer session *****************//
          $customerSession = $objectManager->create('MagentoCustomerModelSession');

          //******** Checking whether customer is logged in or not ********//
          if ($customerSession->isLoggedIn())
          $customer_email = $customerSession->getCustomer()->getEmail();

          // ***********Getting order collection using customer email id ***********//
          $order_collection = $objectManager->create('MagentoSalesModelOrder')->getCollection()->addAttributeToFilter('customer_email', $customer_email);

          //echo "<pre>";print_r($order_collection->getData());
          foreach ($order_collection as $order)
          echo "Order Id: ".$order->getEntityId();
          echo "Customer Id: ".$order->getCustomerId();





          Order collection based on logged in Customer Email Id (Customer All orders)




          I hope this will help






          share|improve this answer

























          • how to get entity id and customer id from $order_collection->getData() my output is like this . Array ( [0] => Array ( [entity_id] => 166952 ) ) customerid 12004 . , what kind of format is this its not json for sure

            – summu
            Feb 15 at 10:22












          • i get this error . Call to undefined method MagentoSalesModelResourceModelOrderCollection::getEntityId()

            – summu
            Feb 15 at 10:29











          • foreach ($order_collection as $order) echo "Order Id: ".$order->getEntityId(); echo "Customer Id: ".$order->getCustomerId(); try this

            – Muhammad Hasham
            Feb 15 at 10:33














          2












          2








          2







          $objectManager = MagentoFrameworkAppObjectManager::getInstance();
          $resource = $objectManager->get('MagentoFrameworkAppResourceConnection');
          $connection = $resource->getConnection();

          //*****************loading Customer session *****************//
          $customerSession = $objectManager->create('MagentoCustomerModelSession');

          //******** Checking whether customer is logged in or not ********//
          if ($customerSession->isLoggedIn())
          $customer_email = $customerSession->getCustomer()->getEmail();

          // ***********Getting order collection using customer email id ***********//
          $order_collection = $objectManager->create('MagentoSalesModelOrder')->getCollection()->addAttributeToFilter('customer_email', $customer_email);

          //echo "<pre>";print_r($order_collection->getData());
          foreach ($order_collection as $order)
          echo "Order Id: ".$order->getEntityId();
          echo "Customer Id: ".$order->getCustomerId();





          Order collection based on logged in Customer Email Id (Customer All orders)




          I hope this will help






          share|improve this answer















          $objectManager = MagentoFrameworkAppObjectManager::getInstance();
          $resource = $objectManager->get('MagentoFrameworkAppResourceConnection');
          $connection = $resource->getConnection();

          //*****************loading Customer session *****************//
          $customerSession = $objectManager->create('MagentoCustomerModelSession');

          //******** Checking whether customer is logged in or not ********//
          if ($customerSession->isLoggedIn())
          $customer_email = $customerSession->getCustomer()->getEmail();

          // ***********Getting order collection using customer email id ***********//
          $order_collection = $objectManager->create('MagentoSalesModelOrder')->getCollection()->addAttributeToFilter('customer_email', $customer_email);

          //echo "<pre>";print_r($order_collection->getData());
          foreach ($order_collection as $order)
          echo "Order Id: ".$order->getEntityId();
          echo "Customer Id: ".$order->getCustomerId();





          Order collection based on logged in Customer Email Id (Customer All orders)




          I hope this will help







          share|improve this answer














          share|improve this answer



          share|improve this answer








          edited Feb 15 at 10:40

























          answered Feb 15 at 4:55









          Muhammad HashamMuhammad Hasham

          3,80231656




          3,80231656












          • how to get entity id and customer id from $order_collection->getData() my output is like this . Array ( [0] => Array ( [entity_id] => 166952 ) ) customerid 12004 . , what kind of format is this its not json for sure

            – summu
            Feb 15 at 10:22












          • i get this error . Call to undefined method MagentoSalesModelResourceModelOrderCollection::getEntityId()

            – summu
            Feb 15 at 10:29











          • foreach ($order_collection as $order) echo "Order Id: ".$order->getEntityId(); echo "Customer Id: ".$order->getCustomerId(); try this

            – Muhammad Hasham
            Feb 15 at 10:33


















          • how to get entity id and customer id from $order_collection->getData() my output is like this . Array ( [0] => Array ( [entity_id] => 166952 ) ) customerid 12004 . , what kind of format is this its not json for sure

            – summu
            Feb 15 at 10:22












          • i get this error . Call to undefined method MagentoSalesModelResourceModelOrderCollection::getEntityId()

            – summu
            Feb 15 at 10:29











          • foreach ($order_collection as $order) echo "Order Id: ".$order->getEntityId(); echo "Customer Id: ".$order->getCustomerId(); try this

            – Muhammad Hasham
            Feb 15 at 10:33

















          how to get entity id and customer id from $order_collection->getData() my output is like this . Array ( [0] => Array ( [entity_id] => 166952 ) ) customerid 12004 . , what kind of format is this its not json for sure

          – summu
          Feb 15 at 10:22






          how to get entity id and customer id from $order_collection->getData() my output is like this . Array ( [0] => Array ( [entity_id] => 166952 ) ) customerid 12004 . , what kind of format is this its not json for sure

          – summu
          Feb 15 at 10:22














          i get this error . Call to undefined method MagentoSalesModelResourceModelOrderCollection::getEntityId()

          – summu
          Feb 15 at 10:29





          i get this error . Call to undefined method MagentoSalesModelResourceModelOrderCollection::getEntityId()

          – summu
          Feb 15 at 10:29













          foreach ($order_collection as $order) echo "Order Id: ".$order->getEntityId(); echo "Customer Id: ".$order->getCustomerId(); try this

          – Muhammad Hasham
          Feb 15 at 10:33






          foreach ($order_collection as $order) echo "Order Id: ".$order->getEntityId(); echo "Customer Id: ".$order->getCustomerId(); try this

          – Muhammad Hasham
          Feb 15 at 10:33














          2














          Try this,



          <?php 
          namespace VendorModuleControllerOrders;
          class ReadOrders extends MagentoFrameworkAppActionAction
          public function __construct(
          MagentoFrameworkAppActionContext $context,
          MagentoSalesModelResourceModelOrderCollectionFactory $orderCollectionFactory,
          MagentoCustomerModelSessionFactory $customerSession)
          $this->_customerSession = $customerSession->create();
          $this->orderCollectionFactory = $orderCollectionFactory;
          parent::__construct($context);


          public function getCustomerData()

          if ($this->_customerSession->isLoggedIn())
          return $this->_customerSession->getCustomerData()->getEmail();


          public function execute()

          if (!$this->_customerSession->isLoggedIn())
          return;

          $orders = $this->orderCollectionFactory->create()
          ->addAttributeToFilter('customer_email', $this->getCustomerData());
          foreach ($orders as $items)
          echo $items->getCustomerEmail() . '<pre>';




          Hope this help, if you need any other information. Let me know.
          Peace :)






          share|improve this answer


















          • 1





            Nice effort. +1

            – Muhammad Hasham
            Mar 28 at 9:59
















          2














          Try this,



          <?php 
          namespace VendorModuleControllerOrders;
          class ReadOrders extends MagentoFrameworkAppActionAction
          public function __construct(
          MagentoFrameworkAppActionContext $context,
          MagentoSalesModelResourceModelOrderCollectionFactory $orderCollectionFactory,
          MagentoCustomerModelSessionFactory $customerSession)
          $this->_customerSession = $customerSession->create();
          $this->orderCollectionFactory = $orderCollectionFactory;
          parent::__construct($context);


          public function getCustomerData()

          if ($this->_customerSession->isLoggedIn())
          return $this->_customerSession->getCustomerData()->getEmail();


          public function execute()

          if (!$this->_customerSession->isLoggedIn())
          return;

          $orders = $this->orderCollectionFactory->create()
          ->addAttributeToFilter('customer_email', $this->getCustomerData());
          foreach ($orders as $items)
          echo $items->getCustomerEmail() . '<pre>';




          Hope this help, if you need any other information. Let me know.
          Peace :)






          share|improve this answer


















          • 1





            Nice effort. +1

            – Muhammad Hasham
            Mar 28 at 9:59














          2












          2








          2







          Try this,



          <?php 
          namespace VendorModuleControllerOrders;
          class ReadOrders extends MagentoFrameworkAppActionAction
          public function __construct(
          MagentoFrameworkAppActionContext $context,
          MagentoSalesModelResourceModelOrderCollectionFactory $orderCollectionFactory,
          MagentoCustomerModelSessionFactory $customerSession)
          $this->_customerSession = $customerSession->create();
          $this->orderCollectionFactory = $orderCollectionFactory;
          parent::__construct($context);


          public function getCustomerData()

          if ($this->_customerSession->isLoggedIn())
          return $this->_customerSession->getCustomerData()->getEmail();


          public function execute()

          if (!$this->_customerSession->isLoggedIn())
          return;

          $orders = $this->orderCollectionFactory->create()
          ->addAttributeToFilter('customer_email', $this->getCustomerData());
          foreach ($orders as $items)
          echo $items->getCustomerEmail() . '<pre>';




          Hope this help, if you need any other information. Let me know.
          Peace :)






          share|improve this answer













          Try this,



          <?php 
          namespace VendorModuleControllerOrders;
          class ReadOrders extends MagentoFrameworkAppActionAction
          public function __construct(
          MagentoFrameworkAppActionContext $context,
          MagentoSalesModelResourceModelOrderCollectionFactory $orderCollectionFactory,
          MagentoCustomerModelSessionFactory $customerSession)
          $this->_customerSession = $customerSession->create();
          $this->orderCollectionFactory = $orderCollectionFactory;
          parent::__construct($context);


          public function getCustomerData()

          if ($this->_customerSession->isLoggedIn())
          return $this->_customerSession->getCustomerData()->getEmail();


          public function execute()

          if (!$this->_customerSession->isLoggedIn())
          return;

          $orders = $this->orderCollectionFactory->create()
          ->addAttributeToFilter('customer_email', $this->getCustomerData());
          foreach ($orders as $items)
          echo $items->getCustomerEmail() . '<pre>';




          Hope this help, if you need any other information. Let me know.
          Peace :)







          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Feb 15 at 7:20









          Prathap GunasekaranPrathap Gunasekaran

          2,1241721




          2,1241721







          • 1





            Nice effort. +1

            – Muhammad Hasham
            Mar 28 at 9:59













          • 1





            Nice effort. +1

            – Muhammad Hasham
            Mar 28 at 9:59








          1




          1





          Nice effort. +1

          – Muhammad Hasham
          Mar 28 at 9:59






          Nice effort. +1

          – Muhammad Hasham
          Mar 28 at 9:59


















          draft saved

          draft discarded
















































          Thanks for contributing an answer to Magento Stack Exchange!


          • Please be sure to answer the question. Provide details and share your research!

          But avoid


          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.

          To learn more, see our tips on writing great answers.




          draft saved


          draft discarded














          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmagento.stackexchange.com%2fquestions%2f261912%2fget-all-orders-of-customer-by-email-id-magento-2%23new-answer', 'question_page');

          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown







          Popular posts from this blog

          Get product attribute by attribute group code in magento 2get product attribute by product attribute group in magento 2Magento 2 Log Bundle Product Data in List Page?How to get all product attribute of a attribute group of Default attribute set?Magento 2.1 Create a filter in the product grid by new attributeMagento 2 : Get Product Attribute values By GroupMagento 2 How to get all existing values for one attributeMagento 2 get custom attribute of a single product inside a pluginMagento 2.3 How to get all the Multi Source Inventory (MSI) locations collection in custom module?Magento2: how to develop rest API to get new productsGet product attribute by attribute group code ( [attribute_group_code] ) in magento 2

          Category:9 (number) SubcategoriesMedia in category "9 (number)"Navigation menuUpload mediaGND ID: 4485639-8Library of Congress authority ID: sh85091979ReasonatorScholiaStatistics

          Magento 2.3: How do i solve this, Not registered handle, on custom form?How can i rewrite TierPrice Block in Magento2magento 2 captcha not rendering if I override layout xmlmain.CRITICAL: Plugin class doesn't existMagento 2 : Problem while adding custom button order view page?Magento 2.2.5: Overriding Admin Controller sales/orderMagento 2.2.5: Add, Update and Delete existing products Custom OptionsMagento 2.3 : File Upload issue in UI Component FormMagento2 Not registered handleHow to configured Form Builder Js in my custom magento 2.3.0 module?Magento 2.3. How to create image upload field in an admin form