8

I know how to retrieve last order id by this code,

$this->_checkoutSession->getQuote()->getReservedOrderId();

Where _checkoutSession is obtained with the injection,

\Magento\Checkout\Model\Session $checkoutSession

I want to know how to get the current order ID in magento 2.

  • At which place you want current order id? – Nalin Savaliya Apr 12 '17 at 5:06
  • After the order is placed @Nalin. I am observing order placed after event. – Mrunmay Deswandikar Apr 12 '17 at 5:07
10

below code will give you last order id

protected $_checkoutSession;


public function __construct(
 .....
\Magento\Checkout\Model\Session $checkoutSession,

.....
) {

        $this->_checkoutSession = $checkoutSession;


    }

 $order = $this->_checkoutSession->getLastRealOrder();
 $orderId=$order->getEntityId();
 $order->getIncrementId();

Reference

  • ++1 from me, and how to get the increment id, insted of entity id ? – Mrunmay Deswandikar Apr 12 '17 at 5:09
  • 2
    ummm.. ! i guess $order->getIncrementId() should work – magento noob Apr 12 '17 at 5:12
  • Okay saif I will check.. – Mrunmay Deswandikar Apr 12 '17 at 5:12
  • 1
    @DishaSingh i updated the code.. – Qaisar Satti Apr 12 '17 at 5:15

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.