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;
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
add a comment |
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
add a comment |
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
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
magento2 magento-2.1 magento2.3
edited 2 hours ago
Prathap Gunasekaran
2,0491619
2,0491619
asked 2 hours ago
sanni kalariyasanni kalariya
1089
1089
add a comment |
add a comment |
2 Answers
2
active
oldest
votes
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.
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
add a comment |
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();
<?php $orderCollection = $this->orderCollection(); ?> in phtml file this way call
– sanni kalariya
2 hours ago
add a comment |
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
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
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.
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
add a comment |
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.
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
add a comment |
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.
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.
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
add a comment |
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
add a comment |
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();
<?php $orderCollection = $this->orderCollection(); ?> in phtml file this way call
– sanni kalariya
2 hours ago
add a comment |
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();
<?php $orderCollection = $this->orderCollection(); ?> in phtml file this way call
– sanni kalariya
2 hours ago
add a comment |
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();
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();
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
add a comment |
<?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
add a comment |
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.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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