From 2808794313afab13f8c3a066f3f8a3273c7459fe Mon Sep 17 00:00:00 2001 From: woutse Date: Sat, 22 Feb 2020 22:05:26 +0100 Subject: [PATCH] Redirect to checkout when no payment is linked to order --- Controller/Checkout/Redirect.php | 23 ++++++++++++----------- 1 file changed, 12 insertions(+), 11 deletions(-) diff --git a/Controller/Checkout/Redirect.php b/Controller/Checkout/Redirect.php index 8a930e5c..a60d31a9 100644 --- a/Controller/Checkout/Redirect.php +++ b/Controller/Checkout/Redirect.php @@ -81,20 +81,21 @@ public function execute() if(empty($order)){ throw new Error('No order found in session, please try again'); } - $payment = $order->getPayment(); - if(empty($payment)){ - throw new Error('No payment linked to order, please select a payment method'); - } + # Restore the quote + $quote = $this->quoteRepository->get($order->getQuoteId()); + $quote->setIsActive(true)->setReservedOrderId(null); + $this->checkoutSession->replaceQuote($quote); + $this->quoteRepository->save($quote); + + $payment = $order->getPayment(); - $method = $payment->getMethod(); - // restore the quote - $quote = $this->quoteRepository->get($order->getQuoteId()); - $quote->setIsActive(true)->setReservedOrderId(null); - $this->checkoutSession->replaceQuote($quote); - $this->quoteRepository->save($quote); + if (empty($payment)) { + $this->_redirect('checkout/cart'); + return; + } - $methodInstance = $this->paymentHelper->getMethodInstance($method); + $methodInstance = $this->paymentHelper->getMethodInstance($payment->getMethod()); if ($methodInstance instanceof \Paynl\Payment\Model\Paymentmethod\Paymentmethod) { $this->_logger->notice('PAY.: Start new payment for order ' . $order->getId()); $redirectUrl = $methodInstance->startTransaction($order);