feat: offer only free rooms in booking step 1
This commit is contained in:
1 parent
980e378a7b
commit
2b27b9809d
6 files changed
+17
-119
No files matched your search
@@ -278,10 +278,10 @@ class Travel
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves all bookable rooms (both regular and inquiry).
|
||||
* Retrieves all bookable rooms.
|
||||
*
|
||||
* Returns rooms that have availability greater than zero and a bookable status
|
||||
* (either 'Frei' for regular booking or 'Anfrage' for inquiry booking).
|
||||
* 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.
|
||||
*
|
||||
* @return array<int, Room> The filtered array of bookable rooms, indexed by room ID
|
||||
*/
|
||||
@@ -289,7 +289,7 @@ class Travel
|
||||
{
|
||||
$result = [];
|
||||
foreach ($this->rooms as $room) {
|
||||
if ($room->available > 0 && $this->isBookableRoomStatus($room->status)) {
|
||||
if ($room->available > 0 && Constants::STATUS_AVAILABLE === $room->status) {
|
||||
$result[$room->id] = $room;
|
||||
}
|
||||
}
|
||||
@@ -307,40 +307,6 @@ class Travel
|
||||
return [] !== $this->getAvailableRooms();
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if all bookable rooms require inquiry booking.
|
||||
*
|
||||
* Returns true if there are bookable rooms but none with 'Frei' status.
|
||||
* This indicates the booking must be submitted as an inquiry.
|
||||
*
|
||||
* @return bool True if only inquiry rooms are available
|
||||
*/
|
||||
public function requiresInquiryBooking(): bool
|
||||
{
|
||||
$bookableRooms = $this->getAvailableRooms();
|
||||
|
||||
if ([] === $bookableRooms) {
|
||||
return false;
|
||||
}
|
||||
|
||||
foreach ($bookableRooms as $room) {
|
||||
if (Constants::STATUS_AVAILABLE === $room->status) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if a room status allows booking.
|
||||
*/
|
||||
private function isBookableRoomStatus(?string $status): bool
|
||||
{
|
||||
return Constants::STATUS_AVAILABLE === $status
|
||||
|| Constants::STATUS_ON_REQUEST === $status;
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves a room by its ID.
|
||||
*
|
||||
|
||||
@@ -66,7 +66,6 @@ class Step1Controller extends AbstractBookingCreateController
|
||||
$bookingCreateDto->resetParticipantAssignments();
|
||||
}
|
||||
|
||||
// Check if room selection forces inquiry mode
|
||||
$this->bookingService->updateBookingStatusFromRoomSelection($bookingCreateDto);
|
||||
|
||||
$bookingCreateDto->currentStep = 2;
|
||||
|
||||
@@ -2,7 +2,6 @@
|
||||
|
||||
namespace App\Form;
|
||||
|
||||
use App\BusProNet\Constants;
|
||||
use App\Form\Model\RoomSelectionDto;
|
||||
use Symfony\Component\Form\AbstractType;
|
||||
use Symfony\Component\Form\Extension\Core\Type\HiddenType;
|
||||
@@ -45,7 +44,6 @@ class RoomSelectType extends AbstractType
|
||||
|
||||
$view->vars['label_room'] = $data->label;
|
||||
$view->vars['label_price_amount'] = null;
|
||||
$view->vars['is_inquiry'] = Constants::STATUS_ON_REQUEST === $data->status;
|
||||
|
||||
if (null !== $data->price) {
|
||||
$view->vars['label_price_amount'] = (float) $data->price;
|
||||
|
||||
@@ -611,10 +611,6 @@ class BookingConfigurator
|
||||
/**
|
||||
* Determines the initial booking status based on travel configuration and API restrictions.
|
||||
*
|
||||
* This method implements a multi-stage check to determine the appropriate booking status:
|
||||
* 1. Checks API restrictions via buchungstatusmoeglich attribute
|
||||
* 2. Checks if only inquiry rooms are available (no Frei rooms with available > 0)
|
||||
*
|
||||
* When API provides allowed status restrictions, the method respects them by selecting
|
||||
* the best available status in order of preference: configured default → 'F' → 'O' → 'A'.
|
||||
*
|
||||
@@ -627,13 +623,7 @@ class BookingConfigurator
|
||||
*/
|
||||
private function determineInitialBookingStatus(Travel $travelData): string
|
||||
{
|
||||
// Check 1: Only inquiry rooms available (all rooms with available > 0 have status 'Anfrage')
|
||||
// This takes precedence as it's a business rule independent of API restrictions
|
||||
if ($travelData->requiresInquiryBooking()) {
|
||||
return Constants::BOOKING_STATUS_INQUIRY;
|
||||
}
|
||||
|
||||
// Check 2: If API provided allowed status restrictions, respect them
|
||||
// If API provided allowed status restrictions, respect them
|
||||
if ([] !== $travelData->allowedBookingStatus) {
|
||||
// Prefer configured default status if allowed
|
||||
if ($travelData->isBookingStatusAllowed($this->defaultBookingStatus)) {
|
||||
@@ -658,24 +648,16 @@ class BookingConfigurator
|
||||
}
|
||||
|
||||
/**
|
||||
* Updates booking status based on selected room requirements.
|
||||
* Resets the booking status after the room selection in Step 1.
|
||||
*
|
||||
* If ANY selected room is only bookable on request, 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, so a customer who swaps an on-request room for a
|
||||
* free one in Step 1 is no longer submitted as an inquiry. An 'A' from the Step 3 BusPro
|
||||
* fallback is cleared the same way; Step 3 validates again and re-applies it if needed.
|
||||
* 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 (true === $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;
|
||||
@@ -685,20 +667,6 @@ 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
|
||||
&& $room->available > 0) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Applies booking-level status rules in create flow.
|
||||
*
|
||||
|
||||
Reference in new issue
Block a user