fix: restore room occupancy lost to case-sensitive xml attribute lookup
This commit is contained in:
@@ -9,15 +9,6 @@ abstract class AbstractParser
|
||||
{
|
||||
use TypeConversionTrait;
|
||||
|
||||
protected function getIntOrNullAttribute(?string $value): ?int
|
||||
{
|
||||
if (null === $value || '' === $value) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return (int) $value;
|
||||
}
|
||||
|
||||
protected function getStringOrNullValue(Crawler $node): ?string
|
||||
{
|
||||
return 0 < $node->count() ? $node->text() : null;
|
||||
@@ -64,7 +55,27 @@ abstract class AbstractParser
|
||||
return null;
|
||||
}
|
||||
|
||||
return $node->attr($attribute);
|
||||
$value = $node->attr($attribute);
|
||||
if (null !== $value) {
|
||||
return $value;
|
||||
}
|
||||
|
||||
// BusPro mixes casing (MinPax in the travel export, minpax in booking
|
||||
// responses) and addXmlContent() makes attr() case-sensitive.
|
||||
foreach ($node->getNode(0)->attributes ?? [] as $candidate) {
|
||||
if (0 === strcasecmp($candidate->name, $attribute)) {
|
||||
return $candidate->value;
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
protected function getIntAttrOrNullValue(Crawler $node, string $attribute): ?int
|
||||
{
|
||||
$value = $this->getAttrOrNullValue($node, $attribute);
|
||||
|
||||
return null !== $value && '' !== $value ? (int) $value : null;
|
||||
}
|
||||
|
||||
protected function getRequiredAttrValue(Crawler $node, string $attribute, string $context): string
|
||||
|
||||
@@ -381,8 +381,8 @@ class TravelParser extends AbstractParser
|
||||
$room->category = $this->getAttrOrNullValue($roomNode, 'kat');
|
||||
$room->boardId = (int) $this->getAttrOrNullValue($roomNode, 'idbuspro_vp');
|
||||
$room->label = $this->getAttrOrNullValue($roomNode, 'zimmertext');
|
||||
$room->minPax = (int) $this->getAttrOrNullValue($roomNode, 'minpax');
|
||||
$room->maxPax = (int) $this->getAttrOrNullValue($roomNode, 'maxpax');
|
||||
$room->minPax = $this->getIntAttrOrNullValue($roomNode, 'minpax');
|
||||
$room->maxPax = $this->getIntAttrOrNullValue($roomNode, 'maxpax');
|
||||
$room->nights = (int) $this->getAttrOrNullValue($roomNode, 'naechte');
|
||||
$roomPrice = $this->getAttrOrNullValue($roomNode, 'preis');
|
||||
$room->price = null !== $roomPrice && '' !== $roomPrice
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -24,12 +24,17 @@ class RoomSelectType extends AbstractType
|
||||
$data = $event->getData();
|
||||
$form = $event->getForm();
|
||||
|
||||
$choices = ['-' => 0];
|
||||
if (0 < $data->maxQuantity) {
|
||||
$choices += array_combine(range(1, $data->maxQuantity), range(1, $data->maxQuantity));
|
||||
}
|
||||
|
||||
$form->add('quantity', StepSelectChoiceType::class, [
|
||||
'label' => false,
|
||||
'required' => true,
|
||||
'min_value' => 0,
|
||||
'max_value' => $data->maxQuantity,
|
||||
'choices' => ['-' => 0] + array_combine(range(1, $data->maxQuantity), range(1, $data->maxQuantity)),
|
||||
'choices' => $choices,
|
||||
]);
|
||||
});
|
||||
}
|
||||
|
||||
@@ -110,7 +110,7 @@ class BookingConfigurator
|
||||
$selection->price = $room->price;
|
||||
$selection->status = $room->status;
|
||||
$selection->maxQuantity = $room->available;
|
||||
$selection->capacity = $room->minPax;
|
||||
$selection->capacity = $room->minPax ?? 1;
|
||||
$selection->quantity = $roomsIdsAndQuantities[$room->id] ?? 0;
|
||||
|
||||
return $selection;
|
||||
|
||||
Reference in New Issue
Block a user