feat: offer rooms on request by Anf code suffix

This commit is contained in:
fromme committed 2026-11-11 11:35:38 +01:00
1 parent 2936d8947a
commit 0b0286787b
11 files changed
+204 -41

No files matched your search

+26 -7
View File
@@ -22,15 +22,34 @@ class Room
public const SELECTION_TYPE_BY_ROOM = 'by_room';
/**
* Whether a room with this status and availability is offered for new bookings.
*
* Only 'Frei' rooms with rooms left. A room on request ('Anfrage') would turn the booking
* into an inquiry, so it is treated as sold out. Static and taking the raw values so the
* product export and the chatbot, which hold rooms as arrays, apply the same rule.
* Room code suffix by which the office marks a room as deliberately sold on request.
*/
public static function isBookableState(?string $status, ?int $available): bool
public const ON_REQUEST_CODE_SUFFIX = 'Anf';
/**
* Whether a room with this status, availability and code is offered for new bookings.
*
* 'Frei' rooms with rooms left. A room on request ('Anfrage') would turn the booking into
* an inquiry, so it is treated as sold out, unless isOnRequestByCode() says the office
* sells it that way on purpose. Static and taking the raw values so the product export
* and the chatbot, which hold rooms as arrays, apply the same rule.
*/
public static function isBookableState(?string $status, ?int $available, ?string $code): bool
{
return Constants::STATUS_AVAILABLE === $status && ($available ?? 0) > 0;
if (($available ?? 0) <= 0) {
return false;
}
return Constants::STATUS_AVAILABLE === $status
|| (Constants::STATUS_ON_REQUEST === $status && self::isOnRequestByCode($code));
}
/**
* Whether the room code carries the on-request suffix (case-sensitive, e.g. `6erSDAnf`).
*/
public static function isOnRequestByCode(?string $code): bool
{
return null !== $code && str_ends_with($code, self::ON_REQUEST_CODE_SUFFIX);
}
#[Groups(['api:list', 'api:single', 'snapshot'])]
+3 -2
View File
@@ -279,7 +279,8 @@ class Travel
/**
* Retrieves all bookable rooms.
*
* Returns the rooms Room::isBookableState() accepts: status 'Frei' with rooms left.
* Returns the rooms Room::isBookableState() accepts: status 'Frei' with rooms left, or rooms
* the office sells on request on purpose, which turn the booking into an inquiry.
*
* @return array<int, Room> The filtered array of bookable rooms, indexed by room ID
*/
@@ -287,7 +288,7 @@ class Travel
{
$result = [];
foreach ($this->rooms as $room) {
if (Room::isBookableState($room->status, $room->available)) {
if (Room::isBookableState($room->status, $room->available, $room->code)) {
$result[$room->id] = $room;
}
}
@@ -92,7 +92,7 @@ class ProductExportParser extends AbstractParser
'price' => $this->stringToFloat($this->getAttrOrNullValue($room, 'preis')),
'available' => $available,
'status' => $status,
'bookable' => Room::isBookableState($status, $available),
'bookable' => Room::isBookableState($status, $available, $code),
'boardCode' => $this->getAttrOrNullValue($room, 'vpcode'),
'boardBusProId' => $this->getIntAttrOrNullValue($room, 'idbuspro_vp'),
];
+2 -2
View File
@@ -694,7 +694,7 @@ class TripCatalog
'board' => $room['boardCode'] ?? null,
'nights' => $room['nights'] ?? null,
'price' => $room['price'] ?? null,
'availability' => TravelDateFacts::isBookableRoom($room) ? TravelDateFacts::AVAILABILITY_FREE : TravelDateFacts::AVAILABILITY_SOLD_OUT,
'availability' => TravelDateFacts::roomAvailability($room),
], static fn (mixed $value): bool => null !== $value);
}
@@ -710,7 +710,7 @@ class TripCatalog
'hotel' => $this->hotelName($catalog, $hotel, $row),
'hotelCode' => $row['hotel']['code'],
'rooms' => $rooms,
'bookable' => in_array(TravelDateFacts::AVAILABILITY_FREE, array_column($rooms, 'availability'), true),
'bookable' => [] !== array_diff(array_column($rooms, 'availability'), [TravelDateFacts::AVAILABILITY_SOLD_OUT]),
];
}
+28 -7
View File
@@ -4,6 +4,7 @@ declare(strict_types=1);
namespace App\Model\Chatbot;
use App\BusProNet\Constants;
use App\BusProNet\Model\Room;
use App\Enum\RoomType;
@@ -12,7 +13,8 @@ use App\Enum\RoomType;
* a product export row the way TYPO3's DateImportService derives it, with two deliberate
* differences: rooms in `Buchungsstop` are not listed, and neither is the baby row. A listed
* room is bookable when Room::isBookableState() says so, as the booking flow offers it;
* the others are sold out, as the website shows them.
* the others are sold out, as the website shows them. A bookable room on request is reported
* as such, because booking it only produces an inquiry.
*
* - places: Σ available × maxPax over the bookable rooms (`available` counts rooms);
* - priceFrom ("ab" price): cheapest bookable room, else cheapest listed room;
@@ -23,8 +25,12 @@ use App\Enum\RoomType;
final readonly class TravelDateFacts
{
public const AVAILABILITY_FREE = 'frei';
public const AVAILABILITY_ON_REQUEST = 'auf Anfrage';
public const AVAILABILITY_SOLD_OUT = 'ausgebucht';
/** Best first: a date is as available as its best room. */
private const AVAILABILITY_RANK = [self::AVAILABILITY_FREE, self::AVAILABILITY_ON_REQUEST, self::AVAILABILITY_SOLD_OUT];
public const STATUS_BOOKING_STOP = 'Buchungsstop';
private const GROUP_SKIPASS = 7;
@@ -73,14 +79,13 @@ final readonly class TravelDateFacts
continue;
}
$bookable = self::isBookableRoom($room);
$roomAvailability = self::roomAvailability($room);
$bookable = self::AVAILABILITY_SOLD_OUT !== $roomAvailability;
if ($bookable) {
$places += (int) $room['available'] * (int) ($room['maxPax'] ?? 0);
}
$roomTypes[$type->value] = $type;
$availability = $bookable || self::AVAILABILITY_FREE === $availability
? self::AVAILABILITY_FREE
: self::AVAILABILITY_SOLD_OUT;
$availability = null === $availability ? $roomAvailability : self::better($availability, $roomAvailability);
if (is_int($room['minPax'] ?? null) && (null === $minPax || $room['minPax'] < $minPax)) {
$minPax = $room['minPax'];
@@ -144,11 +149,27 @@ final readonly class TravelDateFacts
}
/**
* One of the AVAILABILITY_* constants.
*
* @param array<string, mixed> $room a room of a ProductExportBuilder row
*/
public static function isBookableRoom(array $room): bool
public static function roomAvailability(array $room): string
{
return Room::isBookableState($room['status'] ?? null, $room['available'] ?? null);
if (!Room::isBookableState($room['status'] ?? null, $room['available'] ?? null, $room['code'] ?? null)) {
return self::AVAILABILITY_SOLD_OUT;
}
return Constants::STATUS_ON_REQUEST === ($room['status'] ?? null)
? self::AVAILABILITY_ON_REQUEST
: self::AVAILABILITY_FREE;
}
/**
* The better of two AVAILABILITY_* values.
*/
private static function better(string $a, string $b): string
{
return array_search($a, self::AVAILABILITY_RANK, true) <= array_search($b, self::AVAILABILITY_RANK, true) ? $a : $b;
}
/**
+24 -4
View File
@@ -648,16 +648,24 @@ class BookingConfigurator
}
/**
* Resets the booking status after the room selection in Step 1.
* Updates the booking status after the room selection in Step 1.
*
* The status returns to what the travel called for when the booking started, and the
* create-flow rules run again. An 'A' from the Step 3 BusPro fallback is cleared this way;
* Step 3 validates again with the new rooms and re-applies it if needed.
* If any selected room is on request, which Step 1 offers only for rooms the office sells
* that way on purpose (Room::isBookableState()), the whole booking becomes an inquiry.
* Otherwise the status returns to what the travel called for when the booking started,
* and the create-flow rules run again. An 'A' from the Step 3 BusPro fallback is cleared
* this way; Step 3 validates again with the new rooms and re-applies it if needed.
*
* @param BookingDto $bookingDto The booking DTO to update
*/
public function updateBookingStatusFromRoomSelection(BookingDto $bookingDto): void
{
if ($this->hasOnRequestRoomSelected($bookingDto)) {
$bookingDto->bookingStatus = Constants::BOOKING_STATUS_INQUIRY;
return;
}
// Sessions started before the initial status was recorded keep their current status
if (null === $bookingDto->initialBookingStatus) {
return;
@@ -667,6 +675,18 @@ class BookingConfigurator
$this->applyCreateBookingStatusRules($bookingDto);
}
private function hasOnRequestRoomSelected(BookingDto $bookingDto): bool
{
foreach ($bookingDto->getSelectedRooms() as $roomSelection) {
$room = $bookingDto->travel->getRoomById($roomSelection->id);
if (null !== $room && Constants::STATUS_ON_REQUEST === $room->status) {
return true;
}
}
return false;
}
/**
* Applies booking-level status rules in create flow.
*