How to get 5 latest order in home page in Magento 2? Planned maintenance scheduled April 23, 2019 at 00:00UTC (8:00pm US/Eastern) Announcing the arrival of Valued Associate #679: Cesar Manara Unicorn Meta Zoo #1: Why another podcast?Magento 2 get product details in product review list phtml?Magento 2: How to load admin login on home page?Get Latest Products REST APIHow to show Hamburger icon on magento2 home pageHow to get order data in magento2Magento 2.2.4 : Cart Subtotal, Shipping, Tax and Order Total not showing on checkout order summary sectionMagento 2 - how to get customer entity_id when order is placed rest apiGet customers latest order?How to used brands attribute set on top reating product on show home page?How to get feature product on home page in magento 2 customization?

Putting class ranking in CV, but against dept guidelines

Converted a Scalar function to a TVF function for parallel execution-Still running in Serial mode

What is the difference between globalisation and imperialism?

Should I use a zero-interest credit card for a large one-time purchase?

Why is Nikon 1.4g better when Nikon 1.8g is sharper?

Disembodied hand growing fangs

Why does the remaining Rebel fleet at the end of Rogue One seem dramatically larger than the one in A New Hope?

Drawing without replacement: why is the order of draw irrelevant?

A term for a woman complaining about things/begging in a cute/childish way

Effects on objects due to a brief relocation of massive amounts of mass

Can the Great Weapon Master feat's damage bonus and accuracy penalty apply to attacks from the Spiritual Weapon spell?

Project Euler #1 in C++

What's the meaning of "fortified infraction restraint"?

What is "gratricide"?

Why is it faster to reheat something than it is to cook it?

How to write the following sign?

What is a fractional matching?

SF book about people trapped in a series of worlds they imagine

How to play a character with a disability or mental disorder without being offensive?

Maximum summed subsequences with non-adjacent items

Is there any word for a place full of confusion?

How come Sam didn't become Lord of Horn Hill?

How often does castling occur in grandmaster games?

Can a new player join a group only when a new campaign starts?



How to get 5 latest order in home page in Magento 2?



Planned maintenance scheduled April 23, 2019 at 00:00UTC (8:00pm US/Eastern)
Announcing the arrival of Valued Associate #679: Cesar Manara
Unicorn Meta Zoo #1: Why another podcast?Magento 2 get product details in product review list phtml?Magento 2: How to load admin login on home page?Get Latest Products REST APIHow to show Hamburger icon on magento2 home pageHow to get order data in magento2Magento 2.2.4 : Cart Subtotal, Shipping, Tax and Order Total not showing on checkout order summary sectionMagento 2 - how to get customer entity_id when order is placed rest apiGet customers latest order?How to used brands attribute set on top reating product on show home page?How to get feature product on home page in magento 2 customization?



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








0















How to Get the latest 5 order in home page in Magento2 with all order details?



Any help would be appreciated.










share|improve this question






























    0















    How to Get the latest 5 order in home page in Magento2 with all order details?



    Any help would be appreciated.










    share|improve this question


























      0












      0








      0








      How to Get the latest 5 order in home page in Magento2 with all order details?



      Any help would be appreciated.










      share|improve this question
















      How to Get the latest 5 order in home page in Magento2 with all order details?



      Any help would be appreciated.







      magento2 magento2.3.0 magento2.3.1






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Apr 15 at 7:24









      Sanjay Gohil

      534215




      534215










      asked Apr 15 at 7:04









      sanni kalariyasanni kalariya

      1019




      1019




















          2 Answers
          2






          active

          oldest

          votes


















          0














          Try this,



          Create a helper and add the below code to it,



          Helper path be like




          app/code/Vendor/Module/Helper/Data.php




          <?php
          namespace VendorModuleHelper;
          class Data extends MagentoFrameworkAppHelperAbstractHelper

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

          public function getCollection()

          $collection = $this->orderFactory->create()->getCollection()->setOrder('entity_id', 'DESC');
          $collection->setPageSize(5)->setCurPage(1);
          return $collection;




          then in your phtml you can call like below



          $order = $this->helper('VendorModuleHelperData')->getCollection();
          foreach($order as $items)
          echo "Entity Id :". $items->getEntityId();
          echo "Order Status :". $items->getStatus();



          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::total.phtml">
          </block>
          </referenceContainer>
          </body>
          </page>


          Vendor_Module - this should you namespace_modulename



          And also place total.phtml in the below path




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




          Hope this helps.






          share|improve this answer























          • Thanks help to me Prathap .. but I have add echo "Price : ".$items->getPrice(); not show me price ?

            – sanni kalariya
            Apr 15 at 7:53











          • You can use it like $items->getSubtotal(); and for more information about attributes see sales_order table and you can get all the information from that table using above method

            – Prathap Gunasekaran
            Apr 15 at 7:59











          • If you want a link in for order status means do it like this <a href="order detail page url"><?php echo "Order Status :". $items->getStatus(); ?></a> inside foreach and for more information create a separte question and let others answer to it

            – Prathap Gunasekaran
            Apr 15 at 8:41











          • ok fine details show but I have get only login customer details what to do ?using something y "MagentoCustomerModelSession" object and constructor define how to do?

            – sanni kalariya
            17 hours ago


















          1














          protected $_checkoutSession;
          protected $_orderFactory;
          protected $_scopeConfig;



          public function __construct(
          MagentoCheckoutModelSession $checkoutSession,
          MagentoSalesModelOrderFactory $orderFactory,
          MagentoFrameworkViewElementContext $context
          )
          $this->_checkoutSession = $checkoutSession;
          $this->_orderFactory = $orderFactory;
          $this->_scopeConfig = $context->getScopeConfig();



          // Use this method to get ID
          public function getRealOrderId()

          $lastorderId = $this->_checkoutSession->getLastOrderId();
          return $lastorderId;


          public function getOrder()

          if ($this->_checkoutSession->getLastRealOrderId())
          $order = $this->_orderFactory->create()->loadByIncrementId($this->_checkoutSession->getLastRealOrderId());
          return $order;

          return false;






          share|improve this answer























            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%2f270065%2fhow-to-get-5-latest-order-in-home-page-in-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









            0














            Try this,



            Create a helper and add the below code to it,



            Helper path be like




            app/code/Vendor/Module/Helper/Data.php




            <?php
            namespace VendorModuleHelper;
            class Data extends MagentoFrameworkAppHelperAbstractHelper

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

            public function getCollection()

            $collection = $this->orderFactory->create()->getCollection()->setOrder('entity_id', 'DESC');
            $collection->setPageSize(5)->setCurPage(1);
            return $collection;




            then in your phtml you can call like below



            $order = $this->helper('VendorModuleHelperData')->getCollection();
            foreach($order as $items)
            echo "Entity Id :". $items->getEntityId();
            echo "Order Status :". $items->getStatus();



            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::total.phtml">
            </block>
            </referenceContainer>
            </body>
            </page>


            Vendor_Module - this should you namespace_modulename



            And also place total.phtml in the below path




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




            Hope this helps.






            share|improve this answer























            • Thanks help to me Prathap .. but I have add echo "Price : ".$items->getPrice(); not show me price ?

              – sanni kalariya
              Apr 15 at 7:53











            • You can use it like $items->getSubtotal(); and for more information about attributes see sales_order table and you can get all the information from that table using above method

              – Prathap Gunasekaran
              Apr 15 at 7:59











            • If you want a link in for order status means do it like this <a href="order detail page url"><?php echo "Order Status :". $items->getStatus(); ?></a> inside foreach and for more information create a separte question and let others answer to it

              – Prathap Gunasekaran
              Apr 15 at 8:41











            • ok fine details show but I have get only login customer details what to do ?using something y "MagentoCustomerModelSession" object and constructor define how to do?

              – sanni kalariya
              17 hours ago















            0














            Try this,



            Create a helper and add the below code to it,



            Helper path be like




            app/code/Vendor/Module/Helper/Data.php




            <?php
            namespace VendorModuleHelper;
            class Data extends MagentoFrameworkAppHelperAbstractHelper

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

            public function getCollection()

            $collection = $this->orderFactory->create()->getCollection()->setOrder('entity_id', 'DESC');
            $collection->setPageSize(5)->setCurPage(1);
            return $collection;




            then in your phtml you can call like below



            $order = $this->helper('VendorModuleHelperData')->getCollection();
            foreach($order as $items)
            echo "Entity Id :". $items->getEntityId();
            echo "Order Status :". $items->getStatus();



            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::total.phtml">
            </block>
            </referenceContainer>
            </body>
            </page>


            Vendor_Module - this should you namespace_modulename



            And also place total.phtml in the below path




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




            Hope this helps.






            share|improve this answer























            • Thanks help to me Prathap .. but I have add echo "Price : ".$items->getPrice(); not show me price ?

              – sanni kalariya
              Apr 15 at 7:53











            • You can use it like $items->getSubtotal(); and for more information about attributes see sales_order table and you can get all the information from that table using above method

              – Prathap Gunasekaran
              Apr 15 at 7:59











            • If you want a link in for order status means do it like this <a href="order detail page url"><?php echo "Order Status :". $items->getStatus(); ?></a> inside foreach and for more information create a separte question and let others answer to it

              – Prathap Gunasekaran
              Apr 15 at 8:41











            • ok fine details show but I have get only login customer details what to do ?using something y "MagentoCustomerModelSession" object and constructor define how to do?

              – sanni kalariya
              17 hours ago













            0












            0








            0







            Try this,



            Create a helper and add the below code to it,



            Helper path be like




            app/code/Vendor/Module/Helper/Data.php




            <?php
            namespace VendorModuleHelper;
            class Data extends MagentoFrameworkAppHelperAbstractHelper

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

            public function getCollection()

            $collection = $this->orderFactory->create()->getCollection()->setOrder('entity_id', 'DESC');
            $collection->setPageSize(5)->setCurPage(1);
            return $collection;




            then in your phtml you can call like below



            $order = $this->helper('VendorModuleHelperData')->getCollection();
            foreach($order as $items)
            echo "Entity Id :". $items->getEntityId();
            echo "Order Status :". $items->getStatus();



            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::total.phtml">
            </block>
            </referenceContainer>
            </body>
            </page>


            Vendor_Module - this should you namespace_modulename



            And also place total.phtml in the below path




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




            Hope this helps.






            share|improve this answer













            Try this,



            Create a helper and add the below code to it,



            Helper path be like




            app/code/Vendor/Module/Helper/Data.php




            <?php
            namespace VendorModuleHelper;
            class Data extends MagentoFrameworkAppHelperAbstractHelper

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

            public function getCollection()

            $collection = $this->orderFactory->create()->getCollection()->setOrder('entity_id', 'DESC');
            $collection->setPageSize(5)->setCurPage(1);
            return $collection;




            then in your phtml you can call like below



            $order = $this->helper('VendorModuleHelperData')->getCollection();
            foreach($order as $items)
            echo "Entity Id :". $items->getEntityId();
            echo "Order Status :". $items->getStatus();



            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::total.phtml">
            </block>
            </referenceContainer>
            </body>
            </page>


            Vendor_Module - this should you namespace_modulename



            And also place total.phtml in the below path




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




            Hope this helps.







            share|improve this answer












            share|improve this answer



            share|improve this answer










            answered Apr 15 at 7:21









            Prathap GunasekaranPrathap Gunasekaran

            1,8921618




            1,8921618












            • Thanks help to me Prathap .. but I have add echo "Price : ".$items->getPrice(); not show me price ?

              – sanni kalariya
              Apr 15 at 7:53











            • You can use it like $items->getSubtotal(); and for more information about attributes see sales_order table and you can get all the information from that table using above method

              – Prathap Gunasekaran
              Apr 15 at 7:59











            • If you want a link in for order status means do it like this <a href="order detail page url"><?php echo "Order Status :". $items->getStatus(); ?></a> inside foreach and for more information create a separte question and let others answer to it

              – Prathap Gunasekaran
              Apr 15 at 8:41











            • ok fine details show but I have get only login customer details what to do ?using something y "MagentoCustomerModelSession" object and constructor define how to do?

              – sanni kalariya
              17 hours ago

















            • Thanks help to me Prathap .. but I have add echo "Price : ".$items->getPrice(); not show me price ?

              – sanni kalariya
              Apr 15 at 7:53











            • You can use it like $items->getSubtotal(); and for more information about attributes see sales_order table and you can get all the information from that table using above method

              – Prathap Gunasekaran
              Apr 15 at 7:59











            • If you want a link in for order status means do it like this <a href="order detail page url"><?php echo "Order Status :". $items->getStatus(); ?></a> inside foreach and for more information create a separte question and let others answer to it

              – Prathap Gunasekaran
              Apr 15 at 8:41











            • ok fine details show but I have get only login customer details what to do ?using something y "MagentoCustomerModelSession" object and constructor define how to do?

              – sanni kalariya
              17 hours ago
















            Thanks help to me Prathap .. but I have add echo "Price : ".$items->getPrice(); not show me price ?

            – sanni kalariya
            Apr 15 at 7:53





            Thanks help to me Prathap .. but I have add echo "Price : ".$items->getPrice(); not show me price ?

            – sanni kalariya
            Apr 15 at 7:53













            You can use it like $items->getSubtotal(); and for more information about attributes see sales_order table and you can get all the information from that table using above method

            – Prathap Gunasekaran
            Apr 15 at 7:59





            You can use it like $items->getSubtotal(); and for more information about attributes see sales_order table and you can get all the information from that table using above method

            – Prathap Gunasekaran
            Apr 15 at 7:59













            If you want a link in for order status means do it like this <a href="order detail page url"><?php echo "Order Status :". $items->getStatus(); ?></a> inside foreach and for more information create a separte question and let others answer to it

            – Prathap Gunasekaran
            Apr 15 at 8:41





            If you want a link in for order status means do it like this <a href="order detail page url"><?php echo "Order Status :". $items->getStatus(); ?></a> inside foreach and for more information create a separte question and let others answer to it

            – Prathap Gunasekaran
            Apr 15 at 8:41













            ok fine details show but I have get only login customer details what to do ?using something y "MagentoCustomerModelSession" object and constructor define how to do?

            – sanni kalariya
            17 hours ago





            ok fine details show but I have get only login customer details what to do ?using something y "MagentoCustomerModelSession" object and constructor define how to do?

            – sanni kalariya
            17 hours ago













            1














            protected $_checkoutSession;
            protected $_orderFactory;
            protected $_scopeConfig;



            public function __construct(
            MagentoCheckoutModelSession $checkoutSession,
            MagentoSalesModelOrderFactory $orderFactory,
            MagentoFrameworkViewElementContext $context
            )
            $this->_checkoutSession = $checkoutSession;
            $this->_orderFactory = $orderFactory;
            $this->_scopeConfig = $context->getScopeConfig();



            // Use this method to get ID
            public function getRealOrderId()

            $lastorderId = $this->_checkoutSession->getLastOrderId();
            return $lastorderId;


            public function getOrder()

            if ($this->_checkoutSession->getLastRealOrderId())
            $order = $this->_orderFactory->create()->loadByIncrementId($this->_checkoutSession->getLastRealOrderId());
            return $order;

            return false;






            share|improve this answer



























              1














              protected $_checkoutSession;
              protected $_orderFactory;
              protected $_scopeConfig;



              public function __construct(
              MagentoCheckoutModelSession $checkoutSession,
              MagentoSalesModelOrderFactory $orderFactory,
              MagentoFrameworkViewElementContext $context
              )
              $this->_checkoutSession = $checkoutSession;
              $this->_orderFactory = $orderFactory;
              $this->_scopeConfig = $context->getScopeConfig();



              // Use this method to get ID
              public function getRealOrderId()

              $lastorderId = $this->_checkoutSession->getLastOrderId();
              return $lastorderId;


              public function getOrder()

              if ($this->_checkoutSession->getLastRealOrderId())
              $order = $this->_orderFactory->create()->loadByIncrementId($this->_checkoutSession->getLastRealOrderId());
              return $order;

              return false;






              share|improve this answer

























                1












                1








                1







                protected $_checkoutSession;
                protected $_orderFactory;
                protected $_scopeConfig;



                public function __construct(
                MagentoCheckoutModelSession $checkoutSession,
                MagentoSalesModelOrderFactory $orderFactory,
                MagentoFrameworkViewElementContext $context
                )
                $this->_checkoutSession = $checkoutSession;
                $this->_orderFactory = $orderFactory;
                $this->_scopeConfig = $context->getScopeConfig();



                // Use this method to get ID
                public function getRealOrderId()

                $lastorderId = $this->_checkoutSession->getLastOrderId();
                return $lastorderId;


                public function getOrder()

                if ($this->_checkoutSession->getLastRealOrderId())
                $order = $this->_orderFactory->create()->loadByIncrementId($this->_checkoutSession->getLastRealOrderId());
                return $order;

                return false;






                share|improve this answer













                protected $_checkoutSession;
                protected $_orderFactory;
                protected $_scopeConfig;



                public function __construct(
                MagentoCheckoutModelSession $checkoutSession,
                MagentoSalesModelOrderFactory $orderFactory,
                MagentoFrameworkViewElementContext $context
                )
                $this->_checkoutSession = $checkoutSession;
                $this->_orderFactory = $orderFactory;
                $this->_scopeConfig = $context->getScopeConfig();



                // Use this method to get ID
                public function getRealOrderId()

                $lastorderId = $this->_checkoutSession->getLastOrderId();
                return $lastorderId;


                public function getOrder()

                if ($this->_checkoutSession->getLastRealOrderId())
                $order = $this->_orderFactory->create()->loadByIncrementId($this->_checkoutSession->getLastRealOrderId());
                return $order;

                return false;







                share|improve this answer












                share|improve this answer



                share|improve this answer










                answered Apr 15 at 9:49









                HelenHelen

                113




                113



























                    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%2f270065%2fhow-to-get-5-latest-order-in-home-page-in-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

                    Sum ergo cogito? 1 nng

                    三茅街道4182Guuntc Dn precexpngmageondP