Hi guys , how can i use getLastRealOrder()->getEntityId(); in .phtml file.
can any one guide me ?
Solved! Go to Solution.
You can use this way by Creating Block file,
<?php namespace Rbj\Checkout\Block; class Success extends \Magento\Framework\View\Element\Template { public function __construct( \Magento\Framework\View\Element\Template\Context $context, \Magento\Checkout\Model\Session $checkoutSession, array $data = [] ) { $this->checkoutSession = $checkoutSession; parent::__construct($context, $data); public function getLastOrder() { return $this->_checkoutSession->getLastRealOrder()->getEntityId(); } }
Call Block function in a template file,
echo $block->getLastOrder();
Directly template file, Check using below file, I am not sure its working or not,
$objectManager = \Magento\Framework\App\ObjectManager::getInstance(); echo $lastOrderId = $objectManager->get('Magento\Checkout\Model\Session')->getLastRealOrder()->getEntityId();
Hello @bharath553
In which module phtml file you want to call?
You can use this way by Creating Block file,
<?php namespace Rbj\Checkout\Block; class Success extends \Magento\Framework\View\Element\Template { public function __construct( \Magento\Framework\View\Element\Template\Context $context, \Magento\Checkout\Model\Session $checkoutSession, array $data = [] ) { $this->checkoutSession = $checkoutSession; parent::__construct($context, $data); public function getLastOrder() { return $this->_checkoutSession->getLastRealOrder()->getEntityId(); } }
Call Block function in a template file,
echo $block->getLastOrder();
Directly template file, Check using below file, I am not sure its working or not,
$objectManager = \Magento\Framework\App\ObjectManager::getInstance(); echo $lastOrderId = $objectManager->get('Magento\Checkout\Model\Session')->getLastRealOrder()->getEntityId();