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();
5
  • In which page you are trying to pass data Jun 23, 2018 at 10:20
  • custom template file Jun 23, 2018 at 10:20
  • in phtml file i have written code for product information and call this template under email template file. Jun 23, 2018 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? Jun 24, 2018 at 5:22
  • i got solutions Jun 24, 2018 at 7:34

1 Answer 1

1

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();
}
12
  • 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 Jun 23, 2018 at 10:24
  • I am talking about magento core session. Jun 23, 2018 at 10:24
  • can you help me how .. Jun 23, 2018 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. Jun 23, 2018 at 10:27
  • you can get the value using objectmanaget into phtml file. Jun 23, 2018 at 10:30

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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