Magento 2 : Get last five order information using DI on homepage?In magento 2 How to get all customer data without using object manager?Magento 2 - Get order PayPal information programmaticallyGet Total Order by a customerMagento 2 product image custom resizeHow to get last ordered product details in Magento 2.2?Magento 2: Sort Product collection by Last update ProductHow to get last order id in Magento 2.3?Get Additional information in the order view payment information sectionMagento 2 : pagination using knockoutHow to get 5 latest order in home page in Magento 2?how to get orders in table form? in magento 2 table form is Order #,Order Date,Order Total,Total Item,Action

What happens to the Infinity Stones?

Thesis on avalanche prediction using One Class SVM

Authenticating an internal API with Flask

Magical attacks and overcoming damage resistance

Initiative: Do I lose my attack/action if my target moves or dies before my turn in combat?

What does "function" actually mean in music?

How exactly does Hawking radiation decrease the mass of black holes?

Why did C use the -> operator instead of reusing the . operator?

Is there an implicit type promotion in "float = float - float"?

Could moose/elk survive in the Amazon forest?

How did Captain America use this in Avengers: Endgame?

How do I reattach a shelf to the wall when it ripped out of the wall?

Who was the lone kid in the line of people at the lake at the end of Avengers: Endgame?

'It addicted me, with one taste.' Can 'addict' be used transitively?

"The cow" OR "a cow" OR "cows" in this context

Ergodic without atoms implies completely conservative?

Philosophical question on logistic regression: why isn't the optimal threshold value trained?

Does a large simulator bay have standard public address announcements?

Elements that can bond to themselves?

As an international instructor, should I openly talk about my accent?

Can I criticise the more senior developers around me for not writing clean code?

What is the optimal strategy for the Dictionary Game?

Mistake in years of experience in resume?

How to have a sharp product image?



Magento 2 : Get last five order information using DI on homepage?


In magento 2 How to get all customer data without using object manager?Magento 2 - Get order PayPal information programmaticallyGet Total Order by a customerMagento 2 product image custom resizeHow to get last ordered product details in Magento 2.2?Magento 2: Sort Product collection by Last update ProductHow to get last order id in Magento 2.3?Get Additional information in the order view payment information sectionMagento 2 : pagination using knockoutHow to get 5 latest order in home page in Magento 2?how to get orders in table form? in magento 2 table form is Order #,Order Date,Order Total,Total Item,Action






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








1















I want to get last 5 order information on home page.




Question : How to get last five order collection information on homepage?




NOTE : Avoid giving answers using object manager.



Any help would be appreciated.










share|improve this question






























    1















    I want to get last 5 order information on home page.




    Question : How to get last five order collection information on homepage?




    NOTE : Avoid giving answers using object manager.



    Any help would be appreciated.










    share|improve this question


























      1












      1








      1








      I want to get last 5 order information on home page.




      Question : How to get last five order collection information on homepage?




      NOTE : Avoid giving answers using object manager.



      Any help would be appreciated.










      share|improve this question
















      I want to get last 5 order information on home page.




      Question : How to get last five order collection information on homepage?




      NOTE : Avoid giving answers using object manager.



      Any help would be appreciated.







      magento2 magento-2.1 magento2.3






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited 2 hours ago









      Prathap Gunasekaran

      2,0491619




      2,0491619










      asked 2 hours ago









      sanni kalariyasanni kalariya

      1089




      1089




















          2 Answers
          2






          active

          oldest

          votes


















          0














          Try this,



          Create a block and add the below code to it,



          Block path be like




          app/code/Vendor/Module/Block/Orders.php




          <?php
          namespace VendorModuleBlock;
          class Orders extends MagentoFrameworkViewElementTemplate

          public function __construct(
          MagentoSalesModelOrderFactory $orderFactory
          )

          $this->orderFactory = $orderFactory;


          public function getCollection()

          $collection = $this->orderFactory->create()->getCollection()->addFieldToSelect('*')->setOrder('created_at','desc');
          $collection->setPageSize(5);
          return $collection;




          then in your phtml you can call like below



           $order_collection = $block->getCollection();
          foreach($order_collection as $items)
          $items->getId();
          $items->getName(); // like this you can get any data from sales_order table information



          you can call any of the phtml in the home page to get this information.



          To call a phtml only on home page follow the below steps



          create a cms_index_index.xml in the below path




          app/code/Vendor/Module/view/frontend/layout/cms_index_index.xml




          then add the below code to it



          <?xml version="1.0"?>
          <page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
          <body>
          <referenceContainer name="content">
          <block class="MagentoFrameworkViewElementTemplate" name="sales_total" template="Vendor_Module::order_total.phtml">
          </block>
          </referenceContainer>
          </body>
          </page>


          Vendor_Module - this should you namespace_modulename



          And also place order_total.phtml in the below path




          app/code/Vendor/Module/view/frontend/templates/order_total.phtml




          Hope this helps.






          share|improve this answer

























          • hello Prathap I have recevice orders but I have used block folder and in this one file create and call phtml this way I have get any solution for this?

            – sanni kalariya
            50 mins ago











          • updated for block, you can simple follow the above instruction and hope that will work if not please let me know

            – Prathap Gunasekaran
            38 mins ago


















          0














          Please Use below code



           <?php
          namespace VendorModuleBlock;

          class order extends MagentoFrameworkViewElementTemplate

          protected $OrderFactory;

          public function __construct(
          ...
          MagentoSalesModelOrderFactory $OrderFactory
          ...
          )
          ...
          $this->OrderFactory = $OrderFactory;
          ...


          public function orderCollection()

          $orderCollection = $this->OrderFactory->create()->getCollection();
          $orderCollection->getSelect()->limit(5);
          foreach ($orderCollection as $key => $orderID)
          $order = $this->OrderFactory->create()->load($orderID->getId());
          $orderItems = $order->getAllItems();
          foreach ($orderItems as $item)
          $product_name = $item->getName();
          $product_id = $item->getProductId();
          echo $productName . "







          ->'orderCollection' Method call in your phtml.
          -> like $this->orderCollection();





          share|improve this answer

























          • <?php $orderCollection = $this->orderCollection(); ?> in phtml file this way call

            – sanni kalariya
            2 hours ago











          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%2f272574%2fmagento-2-get-last-five-order-information-using-di-on-homepage%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









          0














          Try this,



          Create a block and add the below code to it,



          Block path be like




          app/code/Vendor/Module/Block/Orders.php




          <?php
          namespace VendorModuleBlock;
          class Orders extends MagentoFrameworkViewElementTemplate

          public function __construct(
          MagentoSalesModelOrderFactory $orderFactory
          )

          $this->orderFactory = $orderFactory;


          public function getCollection()

          $collection = $this->orderFactory->create()->getCollection()->addFieldToSelect('*')->setOrder('created_at','desc');
          $collection->setPageSize(5);
          return $collection;




          then in your phtml you can call like below



           $order_collection = $block->getCollection();
          foreach($order_collection as $items)
          $items->getId();
          $items->getName(); // like this you can get any data from sales_order table information



          you can call any of the phtml in the home page to get this information.



          To call a phtml only on home page follow the below steps



          create a cms_index_index.xml in the below path




          app/code/Vendor/Module/view/frontend/layout/cms_index_index.xml




          then add the below code to it



          <?xml version="1.0"?>
          <page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
          <body>
          <referenceContainer name="content">
          <block class="MagentoFrameworkViewElementTemplate" name="sales_total" template="Vendor_Module::order_total.phtml">
          </block>
          </referenceContainer>
          </body>
          </page>


          Vendor_Module - this should you namespace_modulename



          And also place order_total.phtml in the below path




          app/code/Vendor/Module/view/frontend/templates/order_total.phtml




          Hope this helps.






          share|improve this answer

























          • hello Prathap I have recevice orders but I have used block folder and in this one file create and call phtml this way I have get any solution for this?

            – sanni kalariya
            50 mins ago











          • updated for block, you can simple follow the above instruction and hope that will work if not please let me know

            – Prathap Gunasekaran
            38 mins ago















          0














          Try this,



          Create a block and add the below code to it,



          Block path be like




          app/code/Vendor/Module/Block/Orders.php




          <?php
          namespace VendorModuleBlock;
          class Orders extends MagentoFrameworkViewElementTemplate

          public function __construct(
          MagentoSalesModelOrderFactory $orderFactory
          )

          $this->orderFactory = $orderFactory;


          public function getCollection()

          $collection = $this->orderFactory->create()->getCollection()->addFieldToSelect('*')->setOrder('created_at','desc');
          $collection->setPageSize(5);
          return $collection;




          then in your phtml you can call like below



           $order_collection = $block->getCollection();
          foreach($order_collection as $items)
          $items->getId();
          $items->getName(); // like this you can get any data from sales_order table information



          you can call any of the phtml in the home page to get this information.



          To call a phtml only on home page follow the below steps



          create a cms_index_index.xml in the below path




          app/code/Vendor/Module/view/frontend/layout/cms_index_index.xml




          then add the below code to it



          <?xml version="1.0"?>
          <page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
          <body>
          <referenceContainer name="content">
          <block class="MagentoFrameworkViewElementTemplate" name="sales_total" template="Vendor_Module::order_total.phtml">
          </block>
          </referenceContainer>
          </body>
          </page>


          Vendor_Module - this should you namespace_modulename



          And also place order_total.phtml in the below path




          app/code/Vendor/Module/view/frontend/templates/order_total.phtml




          Hope this helps.






          share|improve this answer

























          • hello Prathap I have recevice orders but I have used block folder and in this one file create and call phtml this way I have get any solution for this?

            – sanni kalariya
            50 mins ago











          • updated for block, you can simple follow the above instruction and hope that will work if not please let me know

            – Prathap Gunasekaran
            38 mins ago













          0












          0








          0







          Try this,



          Create a block and add the below code to it,



          Block path be like




          app/code/Vendor/Module/Block/Orders.php




          <?php
          namespace VendorModuleBlock;
          class Orders extends MagentoFrameworkViewElementTemplate

          public function __construct(
          MagentoSalesModelOrderFactory $orderFactory
          )

          $this->orderFactory = $orderFactory;


          public function getCollection()

          $collection = $this->orderFactory->create()->getCollection()->addFieldToSelect('*')->setOrder('created_at','desc');
          $collection->setPageSize(5);
          return $collection;




          then in your phtml you can call like below



           $order_collection = $block->getCollection();
          foreach($order_collection as $items)
          $items->getId();
          $items->getName(); // like this you can get any data from sales_order table information



          you can call any of the phtml in the home page to get this information.



          To call a phtml only on home page follow the below steps



          create a cms_index_index.xml in the below path




          app/code/Vendor/Module/view/frontend/layout/cms_index_index.xml




          then add the below code to it



          <?xml version="1.0"?>
          <page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
          <body>
          <referenceContainer name="content">
          <block class="MagentoFrameworkViewElementTemplate" name="sales_total" template="Vendor_Module::order_total.phtml">
          </block>
          </referenceContainer>
          </body>
          </page>


          Vendor_Module - this should you namespace_modulename



          And also place order_total.phtml in the below path




          app/code/Vendor/Module/view/frontend/templates/order_total.phtml




          Hope this helps.






          share|improve this answer















          Try this,



          Create a block and add the below code to it,



          Block path be like




          app/code/Vendor/Module/Block/Orders.php




          <?php
          namespace VendorModuleBlock;
          class Orders extends MagentoFrameworkViewElementTemplate

          public function __construct(
          MagentoSalesModelOrderFactory $orderFactory
          )

          $this->orderFactory = $orderFactory;


          public function getCollection()

          $collection = $this->orderFactory->create()->getCollection()->addFieldToSelect('*')->setOrder('created_at','desc');
          $collection->setPageSize(5);
          return $collection;




          then in your phtml you can call like below



           $order_collection = $block->getCollection();
          foreach($order_collection as $items)
          $items->getId();
          $items->getName(); // like this you can get any data from sales_order table information



          you can call any of the phtml in the home page to get this information.



          To call a phtml only on home page follow the below steps



          create a cms_index_index.xml in the below path




          app/code/Vendor/Module/view/frontend/layout/cms_index_index.xml




          then add the below code to it



          <?xml version="1.0"?>
          <page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
          <body>
          <referenceContainer name="content">
          <block class="MagentoFrameworkViewElementTemplate" name="sales_total" template="Vendor_Module::order_total.phtml">
          </block>
          </referenceContainer>
          </body>
          </page>


          Vendor_Module - this should you namespace_modulename



          And also place order_total.phtml in the below path




          app/code/Vendor/Module/view/frontend/templates/order_total.phtml




          Hope this helps.







          share|improve this answer














          share|improve this answer



          share|improve this answer








          edited 38 mins ago

























          answered 2 hours ago









          Prathap GunasekaranPrathap Gunasekaran

          2,0491619




          2,0491619












          • hello Prathap I have recevice orders but I have used block folder and in this one file create and call phtml this way I have get any solution for this?

            – sanni kalariya
            50 mins ago











          • updated for block, you can simple follow the above instruction and hope that will work if not please let me know

            – Prathap Gunasekaran
            38 mins ago

















          • hello Prathap I have recevice orders but I have used block folder and in this one file create and call phtml this way I have get any solution for this?

            – sanni kalariya
            50 mins ago











          • updated for block, you can simple follow the above instruction and hope that will work if not please let me know

            – Prathap Gunasekaran
            38 mins ago
















          hello Prathap I have recevice orders but I have used block folder and in this one file create and call phtml this way I have get any solution for this?

          – sanni kalariya
          50 mins ago





          hello Prathap I have recevice orders but I have used block folder and in this one file create and call phtml this way I have get any solution for this?

          – sanni kalariya
          50 mins ago













          updated for block, you can simple follow the above instruction and hope that will work if not please let me know

          – Prathap Gunasekaran
          38 mins ago





          updated for block, you can simple follow the above instruction and hope that will work if not please let me know

          – Prathap Gunasekaran
          38 mins ago













          0














          Please Use below code



           <?php
          namespace VendorModuleBlock;

          class order extends MagentoFrameworkViewElementTemplate

          protected $OrderFactory;

          public function __construct(
          ...
          MagentoSalesModelOrderFactory $OrderFactory
          ...
          )
          ...
          $this->OrderFactory = $OrderFactory;
          ...


          public function orderCollection()

          $orderCollection = $this->OrderFactory->create()->getCollection();
          $orderCollection->getSelect()->limit(5);
          foreach ($orderCollection as $key => $orderID)
          $order = $this->OrderFactory->create()->load($orderID->getId());
          $orderItems = $order->getAllItems();
          foreach ($orderItems as $item)
          $product_name = $item->getName();
          $product_id = $item->getProductId();
          echo $productName . "







          ->'orderCollection' Method call in your phtml.
          -> like $this->orderCollection();





          share|improve this answer

























          • <?php $orderCollection = $this->orderCollection(); ?> in phtml file this way call

            – sanni kalariya
            2 hours ago















          0














          Please Use below code



           <?php
          namespace VendorModuleBlock;

          class order extends MagentoFrameworkViewElementTemplate

          protected $OrderFactory;

          public function __construct(
          ...
          MagentoSalesModelOrderFactory $OrderFactory
          ...
          )
          ...
          $this->OrderFactory = $OrderFactory;
          ...


          public function orderCollection()

          $orderCollection = $this->OrderFactory->create()->getCollection();
          $orderCollection->getSelect()->limit(5);
          foreach ($orderCollection as $key => $orderID)
          $order = $this->OrderFactory->create()->load($orderID->getId());
          $orderItems = $order->getAllItems();
          foreach ($orderItems as $item)
          $product_name = $item->getName();
          $product_id = $item->getProductId();
          echo $productName . "







          ->'orderCollection' Method call in your phtml.
          -> like $this->orderCollection();





          share|improve this answer

























          • <?php $orderCollection = $this->orderCollection(); ?> in phtml file this way call

            – sanni kalariya
            2 hours ago













          0












          0








          0







          Please Use below code



           <?php
          namespace VendorModuleBlock;

          class order extends MagentoFrameworkViewElementTemplate

          protected $OrderFactory;

          public function __construct(
          ...
          MagentoSalesModelOrderFactory $OrderFactory
          ...
          )
          ...
          $this->OrderFactory = $OrderFactory;
          ...


          public function orderCollection()

          $orderCollection = $this->OrderFactory->create()->getCollection();
          $orderCollection->getSelect()->limit(5);
          foreach ($orderCollection as $key => $orderID)
          $order = $this->OrderFactory->create()->load($orderID->getId());
          $orderItems = $order->getAllItems();
          foreach ($orderItems as $item)
          $product_name = $item->getName();
          $product_id = $item->getProductId();
          echo $productName . "







          ->'orderCollection' Method call in your phtml.
          -> like $this->orderCollection();





          share|improve this answer















          Please Use below code



           <?php
          namespace VendorModuleBlock;

          class order extends MagentoFrameworkViewElementTemplate

          protected $OrderFactory;

          public function __construct(
          ...
          MagentoSalesModelOrderFactory $OrderFactory
          ...
          )
          ...
          $this->OrderFactory = $OrderFactory;
          ...


          public function orderCollection()

          $orderCollection = $this->OrderFactory->create()->getCollection();
          $orderCollection->getSelect()->limit(5);
          foreach ($orderCollection as $key => $orderID)
          $order = $this->OrderFactory->create()->load($orderID->getId());
          $orderItems = $order->getAllItems();
          foreach ($orderItems as $item)
          $product_name = $item->getName();
          $product_id = $item->getProductId();
          echo $productName . "







          ->'orderCollection' Method call in your phtml.
          -> like $this->orderCollection();






          share|improve this answer














          share|improve this answer



          share|improve this answer








          edited 2 hours ago









          Manoj Deswal

          4,38791744




          4,38791744










          answered 2 hours ago









          TusharTushar

          1598




          1598












          • <?php $orderCollection = $this->orderCollection(); ?> in phtml file this way call

            – sanni kalariya
            2 hours ago

















          • <?php $orderCollection = $this->orderCollection(); ?> in phtml file this way call

            – sanni kalariya
            2 hours ago
















          <?php $orderCollection = $this->orderCollection(); ?> in phtml file this way call

          – sanni kalariya
          2 hours ago





          <?php $orderCollection = $this->orderCollection(); ?> in phtml file this way call

          – sanni kalariya
          2 hours ago

















          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%2f272574%2fmagento-2-get-last-five-order-information-using-di-on-homepage%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

          کانن (شرکت) محتویات تاریخچه[ویرایش] بخشی از تولیدات موفق این شرکت[ویرایش] در رده APS-C[ویرایش] گزارش محیط زیست[ویرایش] رده‌بندی محصولات[ویرایش] منابع[ویرایش] پانویس[ویرایش] پیوند به بیرون[ویرایش] منوی ناوبریwww.canon.comموزه آنلاین دوربین‌های کانننمودار تاریخچه سهام کاننوبگاه رسمی شرکت کاننوووووIDC Worldwide Hardcopy 2013

          Rest API with Magento using PHP with example. Planned maintenance scheduled April 17/18, 2019 at 00:00UTC (8:00pm US/Eastern) Announcing the arrival of Valued Associate #679: Cesar Manara Unicorn Meta Zoo #1: Why another podcast?How to update product using magento client library for PHP?Oauth Error while extending Magento Rest APINot showing my custom api in wsdl(url) and web service list?Using Magento API(REST) via IXMLHTTPRequest COM ObjectHow to login in Magento website using REST APIREST api call for Guest userMagento API calling using HTML and javascriptUse API rest media management by storeView code (admin)Magento REST API Example ErrorsHow to log all rest api calls in magento2?How to update product using magento client library for PHP?

          Magento 2 - Auto login with specific URL 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?Customer can't login - Page refreshes but nothing happensCustom Login page redirectURL to login with redirect URL after completionCustomer login is case sensitiveLogin with phone number or email address - Magento 1.9Magento 2: Set Customer Account Confirmation StatusCustomer auto connect from URLHow to call customer login form in the custom module action magento 2?Change of customer login error message magento2Referrer URL in modal login form