Skip to content

Commit

Permalink
[TASK] Fix isBookable() condition, use redirect instead of forward
Browse files Browse the repository at this point in the history
Related caching issue: #74
  • Loading branch information
pascal20997 committed Mar 10, 2022
1 parent db041f8 commit 952ed9c
Showing 1 changed file with 18 additions and 10 deletions.
28 changes: 18 additions & 10 deletions Classes/Controller/CheckoutController.php
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,12 @@ public function __construct(FacilityRepository $facilityRepository, PeriodReposi

public function listAction(): void
{
// Uncached list action used for redirects with flash messages as they are cached otherwise!
// See: https://forge.typo3.org/issues/72703
if ($this->controllerContext->getFlashMessageQueue()->count()) {
$GLOBALS['TSFE']->no_cache = true;
}

$this->view->assign('jsConf', [
'datatables' => GeneralUtility::makeInstance(DataTablesService::class)->getConfiguration()
+ ['searching' => false, 'columnDefs' => [['targets' => 4, 'orderable' => false]], 'order' => [[1, 'asc']]]
Expand All @@ -98,7 +104,7 @@ public function formAction(Period $period)
'',
AbstractMessage::INFO
);
return $this->forward('list');
$this->redirect('list');
}
/** @var Order $order */
$order = GeneralUtility::makeInstance(Order::class);
Expand All @@ -113,16 +119,18 @@ public function formAction(Period $period)
*/
public function createAction(Order $order, int $furtherParticipants = 0)
{
if (
!$order->_isNew()
|| $order->getBookedPeriod()->isBookable()
|| !OrderSessionUtility::isUserAllowedToOrder($order->getBookedPeriod()->getFacility()->getUid())
) {
if (!(
$order->_isNew()
&& $order->getBookedPeriod()->isBookable()
&& OrderSessionUtility::isUserAllowedToOrder($order->getBookedPeriod()->getFacility()->getUid())
)) {
$this->addFlashMessage('You are not allowed to order right now.', '', AbstractMessage::ERROR);
return $this->forward('list');
$this->redirect('list');
}
if ($this->checkoutService->checkout($order, (int)$this->settings['orderPid'], $furtherParticipants)) {
$this->checkoutService->sendConfirmationMail($order);
$this->addFlashMessage(LocalizationUtility::translate('reservation.created', 'reserve'));
$this->redirect('list');
} else {
$this->addFlashMessage(
LocalizationUtility::translate('list.alerts.wrongAmountOfReservations', 'reserve'),
Expand All @@ -148,7 +156,7 @@ public function confirmAction(string $email, string $activationCode)
'',
AbstractMessage::INFO
);
return $this->forward('list');
$this->redirect('list');
}
$this->checkoutService->confirm($order);
$this->view->assign('order', $order);
Expand Down Expand Up @@ -215,15 +223,15 @@ public function cancelAction(string $email, string $activationCode, bool $confir
}
if ($redirect) {
CacheUtility::clearPageCachesForPagesWithCurrentFacility($order->getBookedPeriod()->getFacility()->getUid());
return $this->forward('list');
return $this->redirect('list');
}
} else {
$this->addFlashMessage(
'Could not find any order with current combination of email and activation code.',
'',
AbstractMessage::ERROR
);
return $this->forward('list');
return $this->redirect('list');
}
}
}

0 comments on commit 952ed9c

Please sign in to comment.