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?