feat: add bookable flag to product export rooms

This commit is contained in:
fromme committed 2026-11-10 17:32:38 +01:00
1 parent 2b27b9809d
commit 0ff312c0c0
10 files changed
+126 -28

No files matched your search

+13
View File
@@ -4,6 +4,7 @@ declare(strict_types=1);
namespace App\BusProNet\Model;
use App\BusProNet\Constants;
use Symfony\Component\Serializer\Attribute\Context;
use Symfony\Component\Serializer\Attribute\Groups;
use Symfony\Component\Serializer\Normalizer\DateTimeNormalizer;
@@ -20,6 +21,18 @@ class Room
public const SELECTION_TYPE_BY_PAX = 'by_pax';
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.
*/
public static function isBookableState(?string $status, ?int $available): bool
{
return Constants::STATUS_AVAILABLE === $status && ($available ?? 0) > 0;
}
#[Groups(['api:list', 'api:single', 'snapshot'])]
public ?int $id = null;
+2 -4
View File
@@ -4,7 +4,6 @@ declare(strict_types=1);
namespace App\BusProNet\Model;
use App\BusProNet\Constants;
use App\BusProNet\Traits\SortByPriceTrait;
use Symfony\Component\Serializer\Attribute\Context;
use Symfony\Component\Serializer\Attribute\Groups;
@@ -280,8 +279,7 @@ class Travel
/**
* Retrieves all bookable rooms.
*
* Returns rooms with status 'Frei' and availability greater than zero. Rooms on request
* ('Anfrage') are not offered: they would turn the booking into an inquiry.
* Returns the rooms Room::isBookableState() accepts: status 'Frei' with rooms left.
*
* @return array<int, Room> The filtered array of bookable rooms, indexed by room ID
*/
@@ -289,7 +287,7 @@ class Travel
{
$result = [];
foreach ($this->rooms as $room) {
if ($room->available > 0 && Constants::STATUS_AVAILABLE === $room->status) {
if (Room::isBookableState($room->status, $room->available)) {
$result[$room->id] = $room;
}
}
@@ -5,6 +5,7 @@ declare(strict_types=1);
namespace App\BusProNet\XmlParser;
use App\BusProNet\Constants;
use App\BusProNet\Model\Room;
use Symfony\Component\DomCrawler\Crawler;
/**
@@ -61,7 +62,8 @@ class ProductExportParser extends AbstractParser
* The hotel's rooms, without the PDGS pseudo room.
*
* `available` is a count of rooms, not persons. Occupancy is read case-insensitively:
* the travel export writes `MinPax`/`MaxPax`.
* the travel export writes `MinPax`/`MaxPax`. `bookable` is the one derived field: whether
* the booking flow offers the room, so a consumer need not re-derive that rule.
*
* @return list<array<string, mixed>>
*/
@@ -76,6 +78,9 @@ class ProductExportParser extends AbstractParser
return;
}
$available = $this->getIntAttrOrNullValue($room, 'verfuegbar');
$status = $this->getAttrOrNullValue($room, 'status');
$rooms[] = [
'busProId' => $this->getIntAttrOrNullValue($room, 'idbuspro_zimmer'),
'code' => $code,
@@ -85,8 +90,9 @@ class ProductExportParser extends AbstractParser
'maxPax' => $this->getIntAttrOrNullValue($room, 'maxpax'),
'nights' => $this->getIntAttrOrNullValue($room, 'naechte'),
'price' => $this->stringToFloat($this->getAttrOrNullValue($room, 'preis')),
'available' => $this->getIntAttrOrNullValue($room, 'verfuegbar'),
'status' => $this->getAttrOrNullValue($room, 'status'),
'available' => $available,
'status' => $status,
'bookable' => Room::isBookableState($status, $available),
'boardCode' => $this->getAttrOrNullValue($room, 'vpcode'),
'boardBusProId' => $this->getIntAttrOrNullValue($room, 'idbuspro_vp'),
];
+3 -5
View File
@@ -40,8 +40,6 @@ class TripCatalog
/** The feed's only language for now; trips are joined in it. */
public const LANGUAGE = 'de';
private const STATUS_FREE = 'Frei';
private const DATES_WITH_PICKUPS = 3;
private const BODY_LIMIT = 20000;
private const HOTEL_BODY_LIMIT = 8000;
@@ -571,7 +569,7 @@ class TripCatalog
*/
private function matches(array $row, TravelDateFacts $facts, ?HotelType $hotelType, TripCriteria $criteria): bool
{
if (!$facts->isBookable()) {
if (!$facts->isListed()) {
return false;
}
@@ -696,7 +694,7 @@ class TripCatalog
'board' => $room['boardCode'] ?? null,
'nights' => $room['nights'] ?? null,
'price' => $room['price'] ?? null,
'availability' => self::STATUS_FREE === ($room['status'] ?? null) ? TravelDateFacts::AVAILABILITY_FREE : TravelDateFacts::AVAILABILITY_ON_REQUEST,
'availability' => TravelDateFacts::isBookableRoom($room) ? TravelDateFacts::AVAILABILITY_FREE : TravelDateFacts::AVAILABILITY_SOLD_OUT,
], static fn (mixed $value): bool => null !== $value);
}
@@ -712,7 +710,7 @@ class TripCatalog
'hotel' => $this->hotelName($catalog, $hotel, $row),
'hotelCode' => $row['hotel']['code'],
'rooms' => $rooms,
'bookable' => [] !== $rooms,
'bookable' => in_array(TravelDateFacts::AVAILABILITY_FREE, array_column($rooms, 'availability'), true),
];
}
+27 -12
View File
@@ -4,26 +4,28 @@ declare(strict_types=1);
namespace App\Model\Chatbot;
use App\BusProNet\Model\Room;
use App\Enum\RoomType;
/**
* What the website's travel search knows about one travel date at one hotel, derived from
* a product export row the way TYPO3's DateImportService derives it, with two deliberate
* differences: rooms in `Buchungsstop` are not bookable, and neither is the baby row.
* 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.
*
* - places: Σ available × maxPax over the bookable rooms (`available` counts rooms);
* - priceFrom ("ab" price): cheapest bookable room with places left, else cheapest bookable room;
* - minPax: the smallest group a bookable room takes;
* - priceFrom ("ab" price): cheapest bookable room, else cheapest listed room;
* - minPax: the smallest group a listed room takes;
* - inclusions from the selection groups (7 Skipass, 71 Verpflegung, 86 Programm, 87 Kurse,
* 89 Events) and the outbound bus service (a price of 0 means included).
*/
final readonly class TravelDateFacts
{
public const AVAILABILITY_FREE = 'frei';
public const AVAILABILITY_ON_REQUEST = 'auf Anfrage';
public const AVAILABILITY_SOLD_OUT = 'ausgebucht';
public const STATUS_BOOKING_STOP = 'Buchungsstop';
private const STATUS_FREE = 'Frei';
private const GROUP_SKIPASS = 7;
private const GROUP_BOARD = 71;
@@ -32,7 +34,7 @@ final readonly class TravelDateFacts
private const GROUP_EVENTS = 89;
/**
* @param list<RoomType> $roomTypes distinct, of the bookable rooms
* @param list<RoomType> $roomTypes distinct, of the listed rooms
* @param list<string> $boards included board labels
*/
private function __construct(
@@ -71,12 +73,14 @@ final readonly class TravelDateFacts
continue;
}
$available = (int) ($room['available'] ?? 0);
$places += $available * (int) ($room['maxPax'] ?? 0);
$bookable = self::isBookableRoom($room);
if ($bookable) {
$places += (int) $room['available'] * (int) ($room['maxPax'] ?? 0);
}
$roomTypes[$type->value] = $type;
$availability = self::STATUS_FREE === ($room['status'] ?? null) || self::AVAILABILITY_FREE === $availability
$availability = $bookable || self::AVAILABILITY_FREE === $availability
? self::AVAILABILITY_FREE
: self::AVAILABILITY_ON_REQUEST;
: self::AVAILABILITY_SOLD_OUT;
if (is_int($room['minPax'] ?? null) && (null === $minPax || $room['minPax'] < $minPax)) {
$minPax = $room['minPax'];
@@ -86,7 +90,7 @@ final readonly class TravelDateFacts
$price = (float) $room['price'];
$priceFrom = null === $priceFrom ? $price : min($priceFrom, $price);
if ($available > 0) {
if ($bookable) {
$priceFromWithPlaces = null === $priceFromWithPlaces ? $price : min($priceFromWithPlaces, $price);
}
}
@@ -131,11 +135,22 @@ final readonly class TravelDateFacts
);
}
public function isBookable(): bool
/**
* Whether the website search lists the date at all, sold out or not.
*/
public function isListed(): bool
{
return null !== $this->availability;
}
/**
* @param array<string, mixed> $room a room of a ProductExportBuilder row
*/
public static function isBookableRoom(array $room): bool
{
return Room::isBookableState($room['status'] ?? null, $room['available'] ?? null);
}
/**
* What the price includes, as the website lists it on a result.
*