diff --git a/Controller/Checkout/Finish.php b/Controller/Checkout/Finish.php index 8e924fe0..b2b08380 100644 --- a/Controller/Checkout/Finish.php +++ b/Controller/Checkout/Finish.php @@ -6,6 +6,7 @@ use Magento\Framework\App\Action\Action; use Magento\Framework\App\Action\Context; use Magento\Framework\Event\ManagerInterface; +use Magento\Quote\Model\QuoteFactory; use Magento\Quote\Model\QuoteRepository; use Magento\Sales\Model\Order; use Magento\Sales\Model\OrderRepository; @@ -52,6 +53,11 @@ class Finish extends PayAction */ private $eventManager; + /** + * @var QuoteFactory + */ + private $quoteFactory; + /** * Index constructor. * @param Context $context @@ -61,6 +67,7 @@ class Finish extends PayAction * @param QuoteRepository $quoteRepository * @param PayHelper $payHelper * @param ManagerInterface $eventManager + * @param QuoteFactory $quoteFactory */ public function __construct( Context $context, @@ -69,7 +76,8 @@ public function __construct( OrderRepository $orderRepository, QuoteRepository $quoteRepository, PayHelper $payHelper, - ManagerInterface $eventManager + ManagerInterface $eventManager, + QuoteFactory $quoteFactory ) { $this->config = $config; $this->checkoutSession = $checkoutSession; @@ -77,6 +85,7 @@ public function __construct( $this->quoteRepository = $quoteRepository; $this->payHelper = $payHelper; $this->eventManager = $eventManager; + $this->quoteFactory = $quoteFactory; parent::__construct($context); } @@ -202,6 +211,15 @@ public function execute() } else { $cancelMessage = $bDenied ? __('Payment denied') : __('Payment canceled'); $this->messageManager->addNoticeMessage($cancelMessage); + if ($multiShipFinish) { + $session = $this->checkoutSession; + $sessionId = $session->getLastQuoteId(); + $quote = $this->quoteFactory->create()->loadByIdWithoutStore($sessionId); + if (!empty($quote->getId())) { + $quote->setIsActive(true)->setReservedOrderId(null)->save(); + $session->replaceQuote($quote); + } + } $resultRedirect->setPath($payment->getMethod() == 'paynl_payment_paylink' ? Config::CANCEL_PAY : $this->config->getCancelURL()); } } catch (\Exception $e) {