1

This question already has an answer here:

i created an own module for a new block in success.phtml and created a Plugin in my own module. Read my old post here: How to get an order id in success.phtml block?

In my success.phtml file i have the following code:

$order = $block->getCurrentOrder();
$orderId= $order->getId();

On the successpage i get the following error: Call to a member function getId() on null in

app/code/Meta/Orderpage/view/frontend/templates/order/success.phtml

Why its not possible to access the function?? Any error on the Code?

marked as duplicate by Amit Bera, Siarhey Uchukhlebau, Prince Patel, liyakat, Giel Berkers Oct 3 '17 at 20:05

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

  • Have you tried: $block->getOrderId(); – harri Oct 2 '17 at 15:23
  • Are you sure that your checkout success page phtml file location is app/code/Meta/Orderpage/view/frontend/templates/order/success.phtml? – Amit Bera Oct 2 '17 at 15:40
  • Also, don't the as same question,Please comment on your previous question or update the question? – Amit Bera Oct 2 '17 at 15:42
0

This is what I did in my success.phtml file to get an order ID, and it works everytime:

$orderID = $this->getOrderId();

Then of course, if you want to show it, simply do something like this:

echo "Order ID: " . $orderID;

Perhaps it is the "$this" part that makes the difference.

If it is any help, the path to my module and the success.phtml file is similar to this:

/app/code/company_name/myModule/view/frontend/templates/checkout/success.phtl

I hope this helps and answers your question.

  • This return the order Increment ID not the Order ID – Hassan Al-Jeshi Mar 25 '18 at 7:08

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