feat: optional return url

This commit is contained in:
Björn Fromme
2025-12-07 18:47:18 +01:00
parent 233748a6c5
commit 20a67e9b96
7 changed files with 75 additions and 24 deletions
@@ -59,6 +59,9 @@ class IndexController extends AbstractController
// Determine agency ID from optional query parameter
$agencyId = $this->resolveAgencyId($request->query->get('agency'));
// Store optional return URL in session (defaults to main EP site)
$this->bookingService->storeReturnUrl($request, $request->query->get('r'));
// Create fresh booking session with the provided parameters
$this->bookingService->startFreshBooking($request, $dateId, $hotelId, $agencyId);
@@ -110,13 +113,17 @@ class IndexController extends AbstractController
* Cancels the active booking session and returns to the appropriate page.
*
* This endpoint allows users to exit the booking flow at any time by
* clearing the booking session data and redirecting them to the account
* dashboard (if logged in) or login page (if guest).
* clearing the booking session data and redirecting them appropriately:
* - Logged-in users: redirected to account dashboard
* - Guest users: redirected to the return URL (stored during booking init)
*/
#[Route('/bookings/cancel', name: 'app_booking_cancel')]
public function cancel(Request $request): Response
{
if (Request::METHOD_POST === $request->getMethod()) {
// Get return URL before clearing session (for guest users)
$returnUrl = $this->bookingService->getReturnUrl($request);
// Clear the booking session
$this->bookingService->clearBookingSession($request);
@@ -124,13 +131,14 @@ class IndexController extends AbstractController
// Without this, logging in after cancel would redirect back to a stale booking URL
$request->getSession()->remove('_security.main.target_path');
// Add a flash message to inform the user
$this->addFlash('info', 'Buchung abgebrochen.');
// Redirect to account dashboard if logged in, otherwise to return URL
if (null !== $this->getUser()) {
$this->addFlash('info', 'Buchung abgebrochen.');
// Redirect to account dashboard if logged in, otherwise to login page
$targetRoute = null !== $this->getUser() ? 'app_account' : 'app_login';
return $this->redirectToRoute('app_account');
}
return $this->redirectToRoute($targetRoute);
return $this->redirect($returnUrl);
}
return $this->render('booking/modal_cancel.html.twig');
@@ -145,6 +153,8 @@ class IndexController extends AbstractController
#[Route('/bookings/create/error', name: 'app_booking_create_error')]
public function error(Request $request): Response
{
return $this->render('booking/create/error.html.twig');
return $this->render('booking/create/error.html.twig', [
'returnUrl' => $this->bookingService->getReturnUrl($request),
]);
}
}