how to get session value, Order_id and order_amount, order_currency, customer_receipt_email in Magento 2.2
Can I show this in a external php file? / Or how I can test it ?
Hi @bbbmishucs
You can use this code in your controller / Block and fetch your data like this :
protected $_order;
protected $_checkoutSession;
public function __construct(
....
\Magento\Sales\Model\Order $order,
\Magento\Checkout\Model\Session $checkoutSession,
....
){
....
$this->_order = $order;
$this->_customerSession = $customerSession;
....
}
public fuction execute()
{
....
$order = $this->_order->load($this->_customerSession->getLastOrderId());
$order_id = $order->getId(); //order ID
$order_amount = $order->getGrandTotal(); //Order amount
$order_currency = $order->getBaseCurrenyCode(); //order currency code
$customer_email = $order->getCustomerEmail(); //customer email ID
$checkout_session_data = $this->_customerSession->getQuote()->getData(); //checkout session data
....
}
It may be works.
If issue solved , Click Kudos & Accept as Solution
Thanks for your kind reply @rohanhapani
But can you help in that:
How to submit additional data to the place order function in magento 2.2 and show that in a plain php file?
that means when I clicked place order button it will redirect me a page (which I;ve built) and in that page I wanna show the information
You can set custom data and pass it by checkout_onepage_controller_success_action event and set your custom code in observer.
For take reference , you can see this link :
https://magento.stackexchange.com/a/170044/17154
It may be works.
If issue solved , Click Kudos & Accept as Solution
Hello @bbbmishucs,
Please create external file and add following code for it
<?php
ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
error_reporting(E_ALL);
require 'app/bootstrap.php';
$bootstrap = \Magento\Framework\App\Bootstrap::create(BP, $_SERVER);
$app = $bootstrap->createApplication('Magento\Framework\App\Http');
$objectManager = \Magento\Framework\App\ObjectManager::getInstance();
$objectManager->get('Magento\Framework\App\State')->setAreaCode('frontend'); // adminhtml
// $bootstrap->run($app);
$orderId = 1000001;
$order = $objectManager->create('Magento\Sales\Model\Order')->loadByIncrementId($lid);
$order->getOrderId();
--
If you've found one of my answers useful, please give "Kudos" or "Accept as Solution"