2

I've added one step in checkout after Review & payment step. Now i want to get last order id in this step. Can anyone help me?

Actually added the last step at the checkout page and that step I want to show just like checkout sucess page, but i dont know how to get the last order id at the my custom step in .html file

3
  • show us what you tried Commented Dec 21, 2018 at 10:49
  • last order id means previously placed order ID?
    – Keyur Shah
    Commented Dec 21, 2018 at 10:49
  • yes previously placed id Commented Dec 21, 2018 at 10:52

2 Answers 2

2
   use Magento\Checkout\Model\Session as checkoutSession;

    /**
     * @var checkoutSession
     */
    private $checkoutSession;


    /**
     * @param checkoutSession $checkoutSession
     */
    public function __construct(
        checkoutSession $checkoutSession
    ) {
        $this->checkoutSession = $checkoutSession;
    }

Now you can use like,

$previousOrderId = $this->checkoutSession->getLastOrderId();
7
  • this will display the entity_id which is quite useless for the customer. Commented Dec 21, 2018 at 11:01
  • Actually i get the orderId in js adn that id bind into .html dynamic Commented Dec 21, 2018 at 11:01
  • He did not mention which kind of id he wants @PhilippSander that's why I added getLastOrderId()
    – Keyur Shah
    Commented Dec 21, 2018 at 11:03
  • get the order id in JS means ? @RasikMiyani please update your exact requirenment otherwise someone will close your question ,
    – Keyur Shah
    Commented Dec 21, 2018 at 11:04
  • Actually added the last step at the checkout page and that step i want to show just like checkout sucess page, but i dont know how to get the last order id at the my custom step in .html file Commented Dec 21, 2018 at 11:24
0
\Magento\Checkout\Model\Session::getLastRealOrder

this method does what you want on PHP side

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.