feat: optional return url
This commit is contained in:
@@ -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),
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,6 +4,7 @@ declare(strict_types=1);
|
||||
|
||||
namespace App\Controller\Booking\Create;
|
||||
|
||||
use App\Service\BookingService;
|
||||
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
@@ -14,18 +15,25 @@ use Symfony\Component\Routing\Attribute\Route;
|
||||
*/
|
||||
class SuccessController extends AbstractController
|
||||
{
|
||||
public function __construct(
|
||||
private readonly BookingService $bookingService,
|
||||
) {
|
||||
}
|
||||
|
||||
#[Route('/bookings/create/success', name: 'app_booking_create_success')]
|
||||
public function success(Request $request): Response
|
||||
{
|
||||
$bookingNumber = $request->getSession()->getFlashBag()->get('booking_number')[0] ?? null;
|
||||
$returnUrl = $this->bookingService->getReturnUrl($request);
|
||||
|
||||
// Redirect to homepage if no booking number (direct access or refresh)
|
||||
// Redirect to return URL if no booking number (direct access or refresh)
|
||||
if (null === $bookingNumber) {
|
||||
return $this->redirect('https://www.ep-reisen.de');
|
||||
return $this->redirect($returnUrl);
|
||||
}
|
||||
|
||||
return $this->render('booking/create/success.html.twig', [
|
||||
'bookingNumber' => $bookingNumber,
|
||||
'returnUrl' => $returnUrl,
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user