fix: filter rentals by skipass duration
This commit is contained in:
@@ -75,9 +75,12 @@ class ParticipantRentalsFieldHandler extends AbstractParticipantFieldHandler
|
|||||||
$selectedRentals = $this->getFieldValue($submittedData, $this->getFieldName()) ?? [];
|
$selectedRentals = $this->getFieldValue($submittedData, $this->getFieldName()) ?? [];
|
||||||
$availableRentals = $bookingDto->travel->getAdditionalServicesBySubTypes(Constants::TOKEN_RENTALS, true, true);
|
$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(
|
$validSelections = $this->filterValidServiceSelections(
|
||||||
$selectedRentals,
|
$selectedRentals,
|
||||||
$availableRentals,
|
$durationFilteredRentals,
|
||||||
$bookingDto,
|
$bookingDto,
|
||||||
$participantIndex
|
$participantIndex
|
||||||
);
|
);
|
||||||
@@ -157,4 +160,37 @@ class ParticipantRentalsFieldHandler extends AbstractParticipantFieldHandler
|
|||||||
|
|
||||||
return false;
|
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;
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user