0

I have canceled the current order like

use Magento\Sales\Model\OrderFactory;
$order = $this->orderFactory->create()->loadByIncrementId($order->getIncrementId());
$order->cancel()->save();

After that, create a new quote and assign the quote item using this link.

https://webkul.com/blog/programmatically-add-more-product-to-an-existing-quote-in-magento-2/

It's working fine. But when the ordered product has 1 qty, it returned the "product is out of stock" message.

How to resolve that.

How to restore the quote for payment failure.

Thanks.

1 Answer 1

0

You need to debug the $cartItem->setQty($qty) Function, May be this function is not getting 1 qty when you entered.

Please check once function parameter Value or set $cartItem->setQty($qty = 1) default value as one.

Restore the quote for payment failure.

in YourIcancelAction() Or failureAction();

Add below code:

if (\Magento\Checkout\Model\Session::restoreQuote()->getLastRealOrderId()) {
    if ($lastQuoteId = \Magento\Checkout\Model\Session::restoreQuote()->getLastQuoteId()) {
        $quote = \Magento\Quote\Model\ResourceModel\Quote\Item->load($lastQuoteId);
        $quote->setIsActive(true)->save();
    }
}
2
  • Mage::getSingleton is for Magento 1
    – Greg
    Commented Sep 12, 2019 at 11:04
  • 1
    use \Magento\Checkout\Model\Session::restoreQuote() Commented Sep 12, 2019 at 11:15

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.