I am trying to create order pragmatically using

$quote = $this->_checkoutSession->getQuote();


$order =  $this->_quoteManagement->submit($quote);

but when I var_dump $this->_checkoutSession->getLastSuccessQuoteId() , $this->_checkoutSession->getLastQuoteId()) and $this->_checkoutSession->getLastOrderId() . I am getting null. Before $this->_quoteManagement->submit($quote); I can get quote values in checkout session.

Because of this session reset I am redirecting to shopping cart page instead of Thank you (checkout/onepage/success/)page after checkout.

If i try to reset those values by

if (empty($this->_checkoutSession->getLastSuccessQuoteId()) || empty($this->_checkoutSession->getLastQuoteId()) || empty($this->_checkoutSession->getLastOrderId()) ) {

It still redirect to cart page.

Also, the issue is occurring for existing customer purchase only.

The Magento version is used 2.2.6.

Is this issue related to Magento version? how can I fix this?

  • so the problem is you are not able to create order programatically right?? – Pramod Jun 29 '20 at 9:22
  • No, it is creating order but redirecting to cart page not thank you page. – urvi Jun 29 '20 at 23:22

The issue occurs due to {{block}} used in customized email template. Using a block in email template destroys the customer session when the new order email is sent and that's the reason it's redirecting to cart page.


Instead of loading the quote via customer session, send the Quote ID in the RequestDataBuilder that you send to the payment gateway. You will be able to get the same in the response and you try to load the quote for that Quote ID.

I think this will solve your issue.

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.