Skip to content

Commit

Permalink
[BUGFIX] Use PRG pattern for multistep checkout
Browse files Browse the repository at this point in the history
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
  • Loading branch information
rintisch committed Jun 3, 2024
1 parent 6aefce0 commit 1b36d60
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions Classes/Controller/Cart/CartController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 1b36d60

Please sign in to comment.