From 1b36d60d631f56b42d183cd58812e9012378b477 Mon Sep 17 00:00:00 2001 From: rintisch Date: Mon, 3 Jun 2024 15:04:25 +0200 Subject: [PATCH] [BUGFIX] Use PRG pattern for multistep checkout Avoid errors when navigating in the multistep checkout between different steps with the browser navigation (back and forward buttons of the browser) by redirecting to the same page. To avoid that the customer can go back to the last step of the multistep checkout after sending the order we also redirect to the first page of the checkout if there are no products in the cart. Fixes: #518 --- Classes/Controller/Cart/CartController.php | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/Classes/Controller/Cart/CartController.php b/Classes/Controller/Cart/CartController.php index 60483402..9178169f 100755 --- a/Classes/Controller/Cart/CartController.php +++ b/Classes/Controller/Cart/CartController.php @@ -118,7 +118,22 @@ public function showAction( ] ); + // Use Post/Redirect/Get pattern for multistep checkout + + $currentStep = null; + if ($this->request->hasArgument('step')) { + $currentStep = (int)$this->request->getArgument('step'); + } + + if ($currentStep && $this->request->getMethod() === 'POST') { + return $this->redirect('show', null, null, ['step' => $currentStep])->withStatus(303); + } + // Redirect to step 1 if cart is empty. + if (count($this->cart->getProducts()) === 0 && $currentStep > 1) { + return $this->redirect('show', null, null, ['step' => 1])->withStatus(303); + } return $this->htmlResponse(); + } public function clearAction(): ResponseInterface