feat: hide unavailable ski passes from selection in create flow

This commit is contained in:
Björn Fromme
2026-08-06 13:08:46 +02:00
parent b82e017f73
commit 6ee00f2bee
6 changed files with 329 additions and 30 deletions
@@ -471,11 +471,9 @@ class ParticipantFieldOptionsProvider extends AbstractFieldOptionsProvider
return $attributes;
}
// Make readonly if service is unavailable (intelligently handles edit mode)
if ($this->shouldMakeServiceReadonly($service, $bookingDto, $participantIndex, 'skiPass')) {
$attributes['readonly'] = true;
$attributes['data-tooltip'] = 'ausgebucht';
}
// No availability readonly state here: unavailable ski passes are removed from
// the choices by filterSkiPassChoices(), and the ones that survive as protected
// selections have to stay selectable
return $attributes;
},
@@ -998,8 +996,13 @@ class ParticipantFieldOptionsProvider extends AbstractFieldOptionsProvider
* Filters ski pass choices for display.
*
* Ski passes follow the same age evaluation rules as the rest of the booking flow.
* Participants only see passes that match their age or birth year. In edit mode,
* the currently booked ski pass is preserved even if it would otherwise be filtered
* Participants only see passes that match their age or birth year. Unlike the other
* service categories, unavailable ski passes - sold out or on Buchungsstop - are not
* rendered read-only but removed from the choices entirely, because a short-term,
* special-priced pass that is gone is no longer an offer worth showing.
*
* Passes the participant already holds are protected from that removal, and in edit
* mode the currently booked ski pass is preserved even if age rules would filter it
* out, so existing bookings remain renderable and editable.
*
* @param Service[] $services Array of ski pass Service objects to filter
@@ -1017,20 +1020,77 @@ class ParticipantFieldOptionsProvider extends AbstractFieldOptionsProvider
return [];
}
$filteredServices = $this->filterServicesByAgeConstraints($services, $bookingDto, $participantIndex);
$isEditMode = BookingDto::MODE_EDIT === $bookingDto->getMode();
$ageFilteredServices = $this->filterServicesByAgeConstraints($services, $bookingDto, $participantIndex);
if (BookingDto::MODE_EDIT !== $bookingDto->getMode() || null === $participant->skiPass?->id) {
return $filteredServices;
}
$filteredServices = $this->serviceAvailabilityCalculator->filterAvailableServices(
$ageFilteredServices,
$bookingDto,
$participantIndex
);
$currentSkiPassId = $participant->skiPass->id;
if (false === isset($filteredServices[$currentSkiPassId])) {
$filteredServices[$currentSkiPassId] = $services[$currentSkiPassId] ?? $participant->skiPass;
foreach ($this->getProtectedSkiPassIds($bookingDto, $participantIndex) as $protectedId) {
if (true === isset($filteredServices[$protectedId])) {
continue;
}
$protectedService = $ageFilteredServices[$protectedId] ?? null;
// Age rules are only bypassed in edit mode, where a booked pass has to stay renderable
if (null === $protectedService && true === $isEditMode) {
$protectedService = $services[$protectedId] ?? null;
if (null === $protectedService && $participant->skiPass?->id === $protectedId) {
$protectedService = $participant->skiPass;
}
}
if (null !== $protectedService) {
$filteredServices[$protectedId] = $protectedService;
}
}
return $filteredServices;
}
/**
* Collects the ski pass IDs that have to stay selectable regardless of availability.
*
* Both the current selection and - in edit mode - the pass of the underlying booking are
* protected. Without this, a participant holding a pass that sold out or went on
* Buchungsstop meanwhile would lose it on the next refresh, and switching to another pass
* would be a one-way decision.
*
* @param BookingDto $bookingDto The booking DTO containing participant and booking data
* @param int $participantIndex Index of the participant to evaluate
*
* @return int[] Ski pass service IDs that must not be filtered out
*/
private function getProtectedSkiPassIds(BookingDto $bookingDto, int $participantIndex): array
{
$protectedIds = [];
$currentSkiPassId = $bookingDto->getParticipant($participantIndex)?->skiPass?->id;
if (null !== $currentSkiPassId) {
$protectedIds[] = $currentSkiPassId;
}
if (BookingDto::MODE_EDIT === $bookingDto->getMode() && null !== $bookingDto->booking) {
$bookedSkiPasses = $bookingDto->booking->getAdditionalServicesForParticipantByGroup(
$participantIndex,
Constants::TOKEN_SKI_PASS
);
foreach ($bookedSkiPasses as $bookedSkiPass) {
if (null !== $bookedSkiPass->id) {
$protectedIds[] = $bookedSkiPass->id;
}
}
}
return array_values(array_unique($protectedIds));
}
/**
* Generates a German tooltip explaining age restrictions for a service.
*