fix: restore room occupancy lost to case-sensitive xml attribute lookup

This commit is contained in:
Björn Fromme
2026-08-31 14:15:21 +02:00
parent 24df764efb
commit e14d29f7d4
10 changed files with 223 additions and 16 deletions
@@ -19,6 +19,9 @@ use App\Service\BookingSessionManager;
use App\Service\ParticipantDataPrefiller;
use App\Service\RoomAssigner;
use App\Service\TravelDataProvider;
use Psr\Log\LoggerInterface;
use Symfony\Component\DependencyInjection\Attribute\Autowire;
use Symfony\Component\HttpFoundation\RedirectResponse;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Attribute\Route;
@@ -38,6 +41,8 @@ class Step2Controller extends AbstractBookingCreateController
private readonly TravelDataProvider $travelDataService,
private readonly RoomAssigner $roomAssignmentService,
private readonly ParticipantDataPrefiller $prepopulationService,
#[Autowire(service: 'monolog.logger.bpn')]
private readonly LoggerInterface $logger,
) {
}
@@ -62,6 +67,10 @@ class Step2Controller extends AbstractBookingCreateController
$this->travelDataService->enrichWithFreshAvailabilities($bookingCreateDto->travel);
// Ensure correct number of participants first, then prepopulate the applicant if needed.
if (null !== $redirect = $this->guardAgainstEmptyParticipantList($bookingCreateDto)) {
return $redirect;
}
$this->ensureCorrectNumberOfParticipants($bookingCreateDto);
$user = $this->getUser();
@@ -111,6 +120,49 @@ class Step2Controller extends AbstractBookingCreateController
return $this->render('booking/create/step_2.html.twig', $templateData);
}
/**
* Rejects a room selection that resolves to no participants at all.
*
* A selected room with a quantity always yields at least one participant, so a zero count means the
* travel data carries no room occupancy. Rendering step 2 anyway would show an empty participant list
* that still validates and lets the booking continue to step 3.
*/
private function guardAgainstEmptyParticipantList(BookingDto $bookingCreateDto): ?RedirectResponse
{
$selectedRooms = $bookingCreateDto->getSelectedRooms();
if ([] === $selectedRooms) {
return null;
}
if (0 < $this->calculateParticipantsCount($bookingCreateDto->roomSelections, $bookingCreateDto->travel)) {
return null;
}
$rooms = [];
foreach ($selectedRooms as $roomSelection) {
$rooms[] = [
'roomId' => $roomSelection->id,
'quantity' => $roomSelection->quantity,
'capacity' => $roomSelection->capacity,
];
}
$this->handleApiError(
$this->logger,
'Room selection resolves to zero participants; travel data carries no room occupancy.',
[
'travelId' => $bookingCreateDto->travel->id,
'travelCode' => $bookingCreateDto->travel->code,
'hotelId' => $bookingCreateDto->hotelId,
'rooms' => $rooms,
],
'Die Zimmerdaten dieser Reise sind unvollständig. Bitte wähle dein Zimmer erneut oder kontaktiere uns.'
);
return $this->redirectToRoute('app_booking_create_step_1');
}
/**
* Ensures the booking DTO has the expected number of participant objects based on room selections.
*/
@@ -139,7 +191,7 @@ class Step2Controller extends AbstractBookingCreateController
foreach ($roomSelections as $roomSelection) {
$room = $rooms[$roomSelection->id];
$participantsCount += $room->minPax * $roomSelection->quantity;
$participantsCount += ($room->minPax ?? 1) * $roomSelection->quantity;
}
return $participantsCount;