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'),
];