How to get the items orders by the customer in the order collection? Planned maintenance scheduled April 23, 2019 at 23:30 UTC (7:30pm US/Eastern) Announcing the arrival of Valued Associate #679: Cesar Manara Unicorn Meta Zoo #1: Why another podcast?How Can I override Sales_Order_History template in customer section at frontendElement 'css', attribute 'order': The attribute 'order' is not allowedConvert MagentoQuoteModelQuote to MagentoSalesModelOrder: Magento 2How to get all order data using sql?Category order does not work, always sort by the entity_id desc{M1) Product collection sort order by views for Most Viewed ProductsMagento 2.2 Create Order for customer from frontend As Sales RepMagento 2 : How to get order collection group by customer?Get order collection by order id in Magento 2?Get collection of orders excluding cancelled order in Magento 2

Determine the generator of an ideal of ring of integers

Can a Wizard take the Magic Initiate feat and select spells from the Wizard list?

Why these surprising proportionalities of integrals involving odd zeta values?

Would I be safe to drive a 23 year old truck for 7 hours / 450 miles?

Married in secret, can marital status in passport be changed at a later date?

Should man-made satellites feature an intelligent inverted "cow catcher"?

Can this water damage be explained by lack of gutters and grading issues?

What were wait-states, and why was it only an issue for PCs?

tabularx column has extra padding at right?

What could prevent concentrated local exploration?

Why doesn't the university give past final exams' answers?

How to create a command for the "strange m" symbol in latex?

Like totally amazing interchangeable sister outfit accessory swapping or whatever

Protagonist's race is hidden - should I reveal it?

Is there a way to convert Wolfram Language expression to string?

Do chord progressions usually move by fifths?

Can I ask an author to send me his ebook?

How can I introduce the names of fantasy creatures to the reader?

Can gravitational waves pass through a black hole?

What's the connection between Mr. Nancy and fried chicken?

A German immigrant ancestor has a "Registration Affidavit of Alien Enemy" on file. What does that mean exactly?

Is my guitar’s action too high?

Why do C and C++ allow the expression (int) + 4*5?

Who can become a wight?



How to get the items orders by the customer in the order collection?



Planned maintenance scheduled April 23, 2019 at 23:30 UTC (7:30pm US/Eastern)
Announcing the arrival of Valued Associate #679: Cesar Manara
Unicorn Meta Zoo #1: Why another podcast?How Can I override Sales_Order_History template in customer section at frontendElement 'css', attribute 'order': The attribute 'order' is not allowedConvert MagentoQuoteModelQuote to MagentoSalesModelOrder: Magento 2How to get all order data using sql?Category order does not work, always sort by the entity_id desc{M1) Product collection sort order by views for Most Viewed ProductsMagento 2.2 Create Order for customer from frontend As Sales RepMagento 2 : How to get order collection group by customer?Get order collection by order id in Magento 2?Get collection of orders excluding cancelled order in Magento 2



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








0















I need to get the collection of orders with the the items ordered by using the customer ID. But I am not getting the items ordered in my collection. Please help.



 $objectManager = MagentoFrameworkAppObjectManager::getInstance();
$order = $objectManager->create('MagentoSalesModelOrder')->getCollection()->addAttributeToFilter('customer_id', $captinId)->setOrder('entity_id',$direction)->setPageSize($pageSize)->setCurPage($currentPage);
$orderResult = $order->getData();
return $orderResult;









share|improve this question




























    0















    I need to get the collection of orders with the the items ordered by using the customer ID. But I am not getting the items ordered in my collection. Please help.



     $objectManager = MagentoFrameworkAppObjectManager::getInstance();
    $order = $objectManager->create('MagentoSalesModelOrder')->getCollection()->addAttributeToFilter('customer_id', $captinId)->setOrder('entity_id',$direction)->setPageSize($pageSize)->setCurPage($currentPage);
    $orderResult = $order->getData();
    return $orderResult;









    share|improve this question
























      0












      0








      0








      I need to get the collection of orders with the the items ordered by using the customer ID. But I am not getting the items ordered in my collection. Please help.



       $objectManager = MagentoFrameworkAppObjectManager::getInstance();
      $order = $objectManager->create('MagentoSalesModelOrder')->getCollection()->addAttributeToFilter('customer_id', $captinId)->setOrder('entity_id',$direction)->setPageSize($pageSize)->setCurPage($currentPage);
      $orderResult = $order->getData();
      return $orderResult;









      share|improve this question














      I need to get the collection of orders with the the items ordered by using the customer ID. But I am not getting the items ordered in my collection. Please help.



       $objectManager = MagentoFrameworkAppObjectManager::getInstance();
      $order = $objectManager->create('MagentoSalesModelOrder')->getCollection()->addAttributeToFilter('customer_id', $captinId)->setOrder('entity_id',$direction)->setPageSize($pageSize)->setCurPage($currentPage);
      $orderResult = $order->getData();
      return $orderResult;






      magento2.2 sales-order order-collection






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Apr 18 at 6:45









      Meetali GuptaMeetali Gupta

      677




      677




















          2 Answers
          2






          active

          oldest

          votes


















          1














          Try the following way:



          $captinId = 2;
          $direction = 'ASC';
          $pageSize = 20;
          $currentPage = 1;
          $objectManager = MagentoFrameworkAppObjectManager::getInstance();
          $orderItemCollection = $objectManager->create('MagentoSalesModelResourceModelOrderItemCollection')
          ->setOrder('entity_id', $direction)
          ->setPageSize($pageSize)
          ->setCurPage($currentPage);

          $orderItemCollection->getSelect()->joinLeft(
          'sales_order',
          'sales_order.entity_id=main_table.order_id',
          ['increment_id']
          )->where('sales_order.customer_id=?', $captinId);
          $orderResult = $orderItemCollection->getData();


          Note: Avoid to use MagentoFrameworkAppObjectManager::getInstance()






          share|improve this answer























          • Thanks for the reponse, now I am getting the products but I want to get them as an array of items. Please help me.

            – Meetali Gupta
            Apr 18 at 9:08


















          0














          Please try the code below.



          $objectManager = MagentoFrameworkAppObjectManager::getInstance();
          $lastyear = date('Y-m-d', strtotime("-1 year"));
          $orderCollection = $objectManager->create('MagentoSalesModelResourceModelOrderCollection');
          $orderCollection->addAttributeToFilter('customer_id',123456)
          ->addAttributeToFilter('status','complete')
          ->addAttributeToFilter('created_at', array('gteq' => $lastyear))->load();

          echo "<pre>";print_r($orderCollection->getData()); exit;


          Then you need to load the order items by order ID.



          <?php
          $orderid = 2;

          $objectManager = MagentoFrameworkAppObjectManager::getInstance();
          $order = $objectManager->create('MagentoSalesApiDataOrderInterface')->load($orderid);

          //Loop through each item and fetch data
          foreach ($order->getAllItems() as $item)

          //fetch whole item information
          print_r($item->getData());

          //Or fetch specific item information
          echo $item->getId();
          echo $item->getProductType();
          echo $item->getQtyOrdered();
          echo $item->getPrice();


          ?>





          share|improve this answer

























          • But this also does not get the order items in my response.

            – Meetali Gupta
            Apr 18 at 7:01












          • I have updated the answer.

            – Sudhanshu Bajaj
            Apr 18 at 7:07











          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%2f270585%2fhow-to-get-the-items-orders-by-the-customer-in-the-order-collection%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









          1














          Try the following way:



          $captinId = 2;
          $direction = 'ASC';
          $pageSize = 20;
          $currentPage = 1;
          $objectManager = MagentoFrameworkAppObjectManager::getInstance();
          $orderItemCollection = $objectManager->create('MagentoSalesModelResourceModelOrderItemCollection')
          ->setOrder('entity_id', $direction)
          ->setPageSize($pageSize)
          ->setCurPage($currentPage);

          $orderItemCollection->getSelect()->joinLeft(
          'sales_order',
          'sales_order.entity_id=main_table.order_id',
          ['increment_id']
          )->where('sales_order.customer_id=?', $captinId);
          $orderResult = $orderItemCollection->getData();


          Note: Avoid to use MagentoFrameworkAppObjectManager::getInstance()






          share|improve this answer























          • Thanks for the reponse, now I am getting the products but I want to get them as an array of items. Please help me.

            – Meetali Gupta
            Apr 18 at 9:08















          1














          Try the following way:



          $captinId = 2;
          $direction = 'ASC';
          $pageSize = 20;
          $currentPage = 1;
          $objectManager = MagentoFrameworkAppObjectManager::getInstance();
          $orderItemCollection = $objectManager->create('MagentoSalesModelResourceModelOrderItemCollection')
          ->setOrder('entity_id', $direction)
          ->setPageSize($pageSize)
          ->setCurPage($currentPage);

          $orderItemCollection->getSelect()->joinLeft(
          'sales_order',
          'sales_order.entity_id=main_table.order_id',
          ['increment_id']
          )->where('sales_order.customer_id=?', $captinId);
          $orderResult = $orderItemCollection->getData();


          Note: Avoid to use MagentoFrameworkAppObjectManager::getInstance()






          share|improve this answer























          • Thanks for the reponse, now I am getting the products but I want to get them as an array of items. Please help me.

            – Meetali Gupta
            Apr 18 at 9:08













          1












          1








          1







          Try the following way:



          $captinId = 2;
          $direction = 'ASC';
          $pageSize = 20;
          $currentPage = 1;
          $objectManager = MagentoFrameworkAppObjectManager::getInstance();
          $orderItemCollection = $objectManager->create('MagentoSalesModelResourceModelOrderItemCollection')
          ->setOrder('entity_id', $direction)
          ->setPageSize($pageSize)
          ->setCurPage($currentPage);

          $orderItemCollection->getSelect()->joinLeft(
          'sales_order',
          'sales_order.entity_id=main_table.order_id',
          ['increment_id']
          )->where('sales_order.customer_id=?', $captinId);
          $orderResult = $orderItemCollection->getData();


          Note: Avoid to use MagentoFrameworkAppObjectManager::getInstance()






          share|improve this answer













          Try the following way:



          $captinId = 2;
          $direction = 'ASC';
          $pageSize = 20;
          $currentPage = 1;
          $objectManager = MagentoFrameworkAppObjectManager::getInstance();
          $orderItemCollection = $objectManager->create('MagentoSalesModelResourceModelOrderItemCollection')
          ->setOrder('entity_id', $direction)
          ->setPageSize($pageSize)
          ->setCurPage($currentPage);

          $orderItemCollection->getSelect()->joinLeft(
          'sales_order',
          'sales_order.entity_id=main_table.order_id',
          ['increment_id']
          )->where('sales_order.customer_id=?', $captinId);
          $orderResult = $orderItemCollection->getData();


          Note: Avoid to use MagentoFrameworkAppObjectManager::getInstance()







          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Apr 18 at 7:36









          Sohel RanaSohel Rana

          23.4k34461




          23.4k34461












          • Thanks for the reponse, now I am getting the products but I want to get them as an array of items. Please help me.

            – Meetali Gupta
            Apr 18 at 9:08

















          • Thanks for the reponse, now I am getting the products but I want to get them as an array of items. Please help me.

            – Meetali Gupta
            Apr 18 at 9:08
















          Thanks for the reponse, now I am getting the products but I want to get them as an array of items. Please help me.

          – Meetali Gupta
          Apr 18 at 9:08





          Thanks for the reponse, now I am getting the products but I want to get them as an array of items. Please help me.

          – Meetali Gupta
          Apr 18 at 9:08













          0














          Please try the code below.



          $objectManager = MagentoFrameworkAppObjectManager::getInstance();
          $lastyear = date('Y-m-d', strtotime("-1 year"));
          $orderCollection = $objectManager->create('MagentoSalesModelResourceModelOrderCollection');
          $orderCollection->addAttributeToFilter('customer_id',123456)
          ->addAttributeToFilter('status','complete')
          ->addAttributeToFilter('created_at', array('gteq' => $lastyear))->load();

          echo "<pre>";print_r($orderCollection->getData()); exit;


          Then you need to load the order items by order ID.



          <?php
          $orderid = 2;

          $objectManager = MagentoFrameworkAppObjectManager::getInstance();
          $order = $objectManager->create('MagentoSalesApiDataOrderInterface')->load($orderid);

          //Loop through each item and fetch data
          foreach ($order->getAllItems() as $item)

          //fetch whole item information
          print_r($item->getData());

          //Or fetch specific item information
          echo $item->getId();
          echo $item->getProductType();
          echo $item->getQtyOrdered();
          echo $item->getPrice();


          ?>





          share|improve this answer

























          • But this also does not get the order items in my response.

            – Meetali Gupta
            Apr 18 at 7:01












          • I have updated the answer.

            – Sudhanshu Bajaj
            Apr 18 at 7:07















          0














          Please try the code below.



          $objectManager = MagentoFrameworkAppObjectManager::getInstance();
          $lastyear = date('Y-m-d', strtotime("-1 year"));
          $orderCollection = $objectManager->create('MagentoSalesModelResourceModelOrderCollection');
          $orderCollection->addAttributeToFilter('customer_id',123456)
          ->addAttributeToFilter('status','complete')
          ->addAttributeToFilter('created_at', array('gteq' => $lastyear))->load();

          echo "<pre>";print_r($orderCollection->getData()); exit;


          Then you need to load the order items by order ID.



          <?php
          $orderid = 2;

          $objectManager = MagentoFrameworkAppObjectManager::getInstance();
          $order = $objectManager->create('MagentoSalesApiDataOrderInterface')->load($orderid);

          //Loop through each item and fetch data
          foreach ($order->getAllItems() as $item)

          //fetch whole item information
          print_r($item->getData());

          //Or fetch specific item information
          echo $item->getId();
          echo $item->getProductType();
          echo $item->getQtyOrdered();
          echo $item->getPrice();


          ?>





          share|improve this answer

























          • But this also does not get the order items in my response.

            – Meetali Gupta
            Apr 18 at 7:01












          • I have updated the answer.

            – Sudhanshu Bajaj
            Apr 18 at 7:07













          0












          0








          0







          Please try the code below.



          $objectManager = MagentoFrameworkAppObjectManager::getInstance();
          $lastyear = date('Y-m-d', strtotime("-1 year"));
          $orderCollection = $objectManager->create('MagentoSalesModelResourceModelOrderCollection');
          $orderCollection->addAttributeToFilter('customer_id',123456)
          ->addAttributeToFilter('status','complete')
          ->addAttributeToFilter('created_at', array('gteq' => $lastyear))->load();

          echo "<pre>";print_r($orderCollection->getData()); exit;


          Then you need to load the order items by order ID.



          <?php
          $orderid = 2;

          $objectManager = MagentoFrameworkAppObjectManager::getInstance();
          $order = $objectManager->create('MagentoSalesApiDataOrderInterface')->load($orderid);

          //Loop through each item and fetch data
          foreach ($order->getAllItems() as $item)

          //fetch whole item information
          print_r($item->getData());

          //Or fetch specific item information
          echo $item->getId();
          echo $item->getProductType();
          echo $item->getQtyOrdered();
          echo $item->getPrice();


          ?>





          share|improve this answer















          Please try the code below.



          $objectManager = MagentoFrameworkAppObjectManager::getInstance();
          $lastyear = date('Y-m-d', strtotime("-1 year"));
          $orderCollection = $objectManager->create('MagentoSalesModelResourceModelOrderCollection');
          $orderCollection->addAttributeToFilter('customer_id',123456)
          ->addAttributeToFilter('status','complete')
          ->addAttributeToFilter('created_at', array('gteq' => $lastyear))->load();

          echo "<pre>";print_r($orderCollection->getData()); exit;


          Then you need to load the order items by order ID.



          <?php
          $orderid = 2;

          $objectManager = MagentoFrameworkAppObjectManager::getInstance();
          $order = $objectManager->create('MagentoSalesApiDataOrderInterface')->load($orderid);

          //Loop through each item and fetch data
          foreach ($order->getAllItems() as $item)

          //fetch whole item information
          print_r($item->getData());

          //Or fetch specific item information
          echo $item->getId();
          echo $item->getProductType();
          echo $item->getQtyOrdered();
          echo $item->getPrice();


          ?>






          share|improve this answer














          share|improve this answer



          share|improve this answer








          edited Apr 18 at 7:07

























          answered Apr 18 at 6:52









          Sudhanshu BajajSudhanshu Bajaj

          232




          232












          • But this also does not get the order items in my response.

            – Meetali Gupta
            Apr 18 at 7:01












          • I have updated the answer.

            – Sudhanshu Bajaj
            Apr 18 at 7:07

















          • But this also does not get the order items in my response.

            – Meetali Gupta
            Apr 18 at 7:01












          • I have updated the answer.

            – Sudhanshu Bajaj
            Apr 18 at 7:07
















          But this also does not get the order items in my response.

          – Meetali Gupta
          Apr 18 at 7:01






          But this also does not get the order items in my response.

          – Meetali Gupta
          Apr 18 at 7:01














          I have updated the answer.

          – Sudhanshu Bajaj
          Apr 18 at 7:07





          I have updated the answer.

          – Sudhanshu Bajaj
          Apr 18 at 7:07

















          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%2f270585%2fhow-to-get-the-items-orders-by-the-customer-in-the-order-collection%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

          Bulk add to cart function issuecart vs. mini cart issue … rwd themeRedirect Add to cart button to cart pageAdd to cart issue - Magento 2.1The requested Payment Method is not available When creating an orderM2: reason add-to-cart might not function in production modeAdd to cart issue in some android devicesMagento 2 - custom price can not add to subtotal and grand total after add to cartAdd to cart codeIssue with my cart module on pdp and cart pages, just keeps spinningBulk price and quantity update using rest api

          БиармияSxpst500bh2ntaf! 3h2r