1

I am getting order id from order success event, I want to pass order into phtml page. I tried with checkout session but I did not get order id in phtml page. anyone can help me regarding this. i am getting order from bellow code

$order_ids = $observer->getEvent()->getOrderIds()[0];
           $order = $this->orderRepository->get($order_ids);
           $orderId  = $order->getIncrementId();

set session and now getting session value in phtml page

$observer_session = $objectManager->get('Magento\Framework\Session\SessionManagerInterface');
$order = $observer_session->getValue();
  • In which page you are trying to pass data – Prashant Valanda Jun 23 '18 at 10:20
  • custom template file – Sarvesh Tiwari Jun 23 '18 at 10:20
  • in phtml file i have written code for product information and call this template under email template file. – Sarvesh Tiwari Jun 23 '18 at 10:21
  • A custom template file is not a page. Can you state which page(s) or layout handle(s) you are trying to access the data on? – Shawn Abramson Jun 24 '18 at 5:22
  • i got solutions – Sarvesh Tiwari Jun 24 '18 at 7:34
0

You need to do like this.

  1. From your observer, set the order value into custom session variable.

  2. On phtml file, get those value from session variable.

Here are the demo code.

protected $_coreSession;

public function __construct(
    -----
    \Magento\Framework\Session\SessionManagerInterface $coreSession
    ){
    $this->_coreSession = $coreSession;
    ----
}

public function setValue(){
    $this->_coreSession->start();
    $this->_coreSession->setMessage('YOUR_CUSTOM_VALUE');
}

public function getValue(){
    $this->_coreSession->start();
    return $this->_coreSession->getMessage();
}

public function unSetValue(){
    $this->_coreSession->start();
    return $this->_coreSession->unsMessage();
}
  • i have set order id with session $data['order']= $order->getIncrementId(); and call in template $orderId = this->getData('order');. but its not working for me – Sarvesh Tiwari Jun 23 '18 at 10:24
  • I am talking about magento core session. – Dhiren Vasoya Jun 23 '18 at 10:24
  • can you help me how .. – Sarvesh Tiwari Jun 23 '18 at 10:25
  • I update my answer with code. Kindly check. And if it help, please accept as soluiton, so it will help other in community as well. – Dhiren Vasoya Jun 23 '18 at 10:27
  • you can get the value using objectmanaget into phtml file. – Dhiren Vasoya Jun 23 '18 at 10:30

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.