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

Has any spacecraft ever had the ability to directly communicate with civilian air traffic control?

Survey Confirmation - Emphasize the question or the answer?

How to avoid grep command finding commented out strings in the source file?

How can I close a gap between my fence and my neighbor's that's on his side of the property line?

Junior developer struggles: how to communicate with management?

How to get SEEK accessing converted ID via view

You look catfish vs You look like a catfish?

Pressure to defend the relevance of one's area of mathematics

Is there a QGIS plugin that reclassify raster symbology based on current extent?

How did Arya get back her dagger from Sansa?

Transfer over $10k

Can a cyclic Amine form an Amide?

Map one pandas column using two dictionaries

Is this homebrew race based on the Draco Volans lizard species balanced?

What happens if I start too many background jobs?

I’ve officially counted to infinity!

Why do computer-science majors learn calculus?

Field Length Validation for Desktop Application which has maximum 1000 characters

How long can a 35mm film be used/stored before it starts to lose its quality after expiry?

Why is Arya visibly scared in the library in S8E3?

Is balancing necessary on a full-wheel change?

Is Cola "probably the best-known" Latin word in the world? If not, which might it be?

The barbers paradox first order logic formalization

Applying a function to a nested list



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 Apr 26 at 11:25









      Prathap Gunasekaran

      2,1191619




      2,1191619










      asked Apr 26 at 11:02









      sanni kalariyasanni kalariya

      1109




      1109




















          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
            Apr 26 at 12:48











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

            – Prathap Gunasekaran
            Apr 26 at 13:00











          • Exception #0 (MagentoFrameworkConfigDomValidationException): Element 'block', attribute 'class': [facet 'pattern'] The value 'WdsCoreoverrideBlockorders' is not accepted by the pattern '[A-Z][_a-zA-Zd]*([A-Z][_a-zA-Zd]*)*'. Line: 713Prathap Gunasekaran I am facing this error

            – sanni kalariya
            17 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);
          return $orderCollection;








          share|improve this answer

























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

            – sanni kalariya
            Apr 26 at 11:23











          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
            Apr 26 at 12:48











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

            – Prathap Gunasekaran
            Apr 26 at 13:00











          • Exception #0 (MagentoFrameworkConfigDomValidationException): Element 'block', attribute 'class': [facet 'pattern'] The value 'WdsCoreoverrideBlockorders' is not accepted by the pattern '[A-Z][_a-zA-Zd]*([A-Z][_a-zA-Zd]*)*'. Line: 713Prathap Gunasekaran I am facing this error

            – sanni kalariya
            17 hours 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
            Apr 26 at 12:48











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

            – Prathap Gunasekaran
            Apr 26 at 13:00











          • Exception #0 (MagentoFrameworkConfigDomValidationException): Element 'block', attribute 'class': [facet 'pattern'] The value 'WdsCoreoverrideBlockorders' is not accepted by the pattern '[A-Z][_a-zA-Zd]*([A-Z][_a-zA-Zd]*)*'. Line: 713Prathap Gunasekaran I am facing this error

            – sanni kalariya
            17 hours 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 Apr 26 at 13:00

























          answered Apr 26 at 11:19









          Prathap GunasekaranPrathap Gunasekaran

          2,1191619




          2,1191619












          • 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
            Apr 26 at 12:48











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

            – Prathap Gunasekaran
            Apr 26 at 13:00











          • Exception #0 (MagentoFrameworkConfigDomValidationException): Element 'block', attribute 'class': [facet 'pattern'] The value 'WdsCoreoverrideBlockorders' is not accepted by the pattern '[A-Z][_a-zA-Zd]*([A-Z][_a-zA-Zd]*)*'. Line: 713Prathap Gunasekaran I am facing this error

            – sanni kalariya
            17 hours 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
            Apr 26 at 12:48











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

            – Prathap Gunasekaran
            Apr 26 at 13:00











          • Exception #0 (MagentoFrameworkConfigDomValidationException): Element 'block', attribute 'class': [facet 'pattern'] The value 'WdsCoreoverrideBlockorders' is not accepted by the pattern '[A-Z][_a-zA-Zd]*([A-Z][_a-zA-Zd]*)*'. Line: 713Prathap Gunasekaran I am facing this error

            – sanni kalariya
            17 hours 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
          Apr 26 at 12:48





          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
          Apr 26 at 12:48













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

          – Prathap Gunasekaran
          Apr 26 at 13:00





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

          – Prathap Gunasekaran
          Apr 26 at 13:00













          Exception #0 (MagentoFrameworkConfigDomValidationException): Element 'block', attribute 'class': [facet 'pattern'] The value 'WdsCoreoverrideBlockorders' is not accepted by the pattern '[A-Z][_a-zA-Zd]*([A-Z][_a-zA-Zd]*)*'. Line: 713Prathap Gunasekaran I am facing this error

          – sanni kalariya
          17 hours ago





          Exception #0 (MagentoFrameworkConfigDomValidationException): Element 'block', attribute 'class': [facet 'pattern'] The value 'WdsCoreoverrideBlockorders' is not accepted by the pattern '[A-Z][_a-zA-Zd]*([A-Z][_a-zA-Zd]*)*'. Line: 713Prathap Gunasekaran I am facing this error

          – sanni kalariya
          17 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);
          return $orderCollection;








          share|improve this answer

























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

            – sanni kalariya
            Apr 26 at 11:23















          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);
          return $orderCollection;








          share|improve this answer

























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

            – sanni kalariya
            Apr 26 at 11:23













          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);
          return $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);
          return $orderCollection;









          share|improve this answer














          share|improve this answer



          share|improve this answer








          edited 19 hours ago

























          answered Apr 26 at 11:09









          TusharTushar

          1598




          1598












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

            – sanni kalariya
            Apr 26 at 11:23

















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

            – sanni kalariya
            Apr 26 at 11:23
















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

          – sanni kalariya
          Apr 26 at 11:23





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

          – sanni kalariya
          Apr 26 at 11:23

















          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

          Grendel Contents Story Scholarship Depictions Notes References Navigation menu10.1093/notesj/gjn112Berserkeree

          Area configuration aggregation error after install Porto themeMagento 2.1 CE Installed but front/backend not loading/workingCSS not loading on page within Magento 2 pageCannot install module in Magento 2no commands defined in the “setup” namespace. in Magento2Magento 2: Static files are present but shows 404Why do i have to always run the commands to clean cache in Magento 2.1.8?Failure reason: 'Unable to unserialize value.'Error 500 after magento migrationIn production mode the site does not loadMagento 2 : Error 500 after installing

          Middle Expansion Olielle Resaix Definition: Uttering songs of triumph shouting with joy triumphant exulting Sejunction Journal 붙다 달 고급 품목 외출 The stretch trades the screeching tin. Definition: The act of speaking with a drawl a drawl Cough Sand Definition: An uproar a quarrel a noisy outbreak Shake Iron Publicize Horse House Baby 사과 Resaix Flaggy Jelly Temporary Unequaled Puppet A drop in the bucket Shrew 성격 회원 성질 미팅 The burn frames the tacky quality. Materialistic The smoke reduces the way. Yammoe Nondescript Cheek 얼굴 배 약하다 날리다 타다 The illegal country shows the iron. Help Rule Drearien Smoke Teaching Meaty Wasp Abraham Lincoln Jaws 진심 수리하다 Size Cork Idea Convert Think Lark John Lennon 거울 청소 군 추천하다 아이스크림