From 201b2238135858c06bfe0b358349135eda9d20eb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B6rn=20Fromme?= Date: Thu, 2 Oct 2025 14:42:04 +0200 Subject: [PATCH] fix: filter rentals by skipass duration --- .../ParticipantRentalsFieldHandler.php | 38 ++++++++++++++++++- 1 file changed, 37 insertions(+), 1 deletion(-) diff --git a/src/Form/Service/ParticipantRentalsFieldHandler.php b/src/Form/Service/ParticipantRentalsFieldHandler.php index 71bdd2a..a247690 100644 --- a/src/Form/Service/ParticipantRentalsFieldHandler.php +++ b/src/Form/Service/ParticipantRentalsFieldHandler.php @@ -75,9 +75,12 @@ class ParticipantRentalsFieldHandler extends AbstractParticipantFieldHandler $selectedRentals = $this->getFieldValue($submittedData, $this->getFieldName()) ?? []; $availableRentals = $bookingDto->travel->getAdditionalServicesBySubTypes(Constants::TOKEN_RENTALS, true, true); + // Filter rentals by skipass duration to ensure only matching rentals are available + $durationFilteredRentals = $this->filterRentalsBySkiPassDuration($availableRentals, $participant); + $validSelections = $this->filterValidServiceSelections( $selectedRentals, - $availableRentals, + $durationFilteredRentals, $bookingDto, $participantIndex ); @@ -157,4 +160,37 @@ class ParticipantRentalsFieldHandler extends AbstractParticipantFieldHandler return false; } + + /** + * Filters rentals to only include those matching the skipass duration. + * + * Rentals must have exact date matching with the selected skipass: + * - rental.dateFrom === skipass.dateFrom + * - rental.dateTo === skipass.dateTo + * + * @param array $rentals All available rental services + * @param \App\Form\Model\ParticipantDto $participant The participant with skipass selection + * + * @return array Filtered rentals matching the skipass duration + */ + private function filterRentalsBySkiPassDuration(array $rentals, $participant): array + { + $selectedSkiPass = $participant->skiPass; + + // If skipass has no valid dates, return empty rentals + if (null === $selectedSkiPass->dateFrom || null === $selectedSkiPass->dateTo) { + return []; + } + + return array_filter($rentals, function (Service $rental) use ($selectedSkiPass) { + // Rental must have valid dates to be considered + if (null === $rental->dateFrom || null === $rental->dateTo) { + return false; + } + + // Exact date matching: rental dates must match skipass dates exactly + return $rental->dateFrom == $selectedSkiPass->dateFrom + && $rental->dateTo == $selectedSkiPass->dateTo; + }); + } }