2

I am trying to create order pragmatically using

$quote = $this->_checkoutSession->getQuote();
$this->_checkoutSession->setLastQuoteId($quote->getId())
                       ->setLastSuccessQuoteId($quote->getId())
                       ->clearHelperData();

$quote->collectTotals();

$order =  $this->_quoteManagement->submit($quote);
$this->_checkoutSession->setLastOrderId($order->getId())
                        ->setLastRealOrderId($order->getIncrementId())
                        ->setLastOrderStatus($order->getStatus());

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()) ) {
                        $this->_checkoutSession->setLastSuccessQuoteId($quote->getId());
                        $this->_checkoutSession->setLastQuoteId($quote->getId());   
                        $this->_checkoutSession->setLastOrderId($order->getId());                               
                                   
}

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?

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

2 Answers 2

1

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.

0

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.

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.