feat: merge draft data with api response for selected fields

This commit is contained in:
Björn Fromme
2026-01-12 18:25:51 +01:00
parent 7636ee41af
commit 5221cea53b
2 changed files with 135 additions and 27 deletions
@@ -1080,9 +1080,19 @@ class ParticipantFieldOptionsProvider extends AbstractFieldOptionsProvider
if (null !== $discountedPkw && null !== $regularPkw) {
$participant = $bookingDto->getParticipant($participantIndex);
// In edit mode, always preserve the participant's current selection in the choices
// This ensures the form can render the selected value even if filtering would hide it
$currentOutboundId = $participant?->transportationOutbound?->id;
$preserveDiscounted = $currentOutboundId === $discountedPkw->id;
$preserveRegular = $currentOutboundId === $regularPkw->id;
// Baby participants always get regular PKW (no discounts)
$age = $participant?->getAge($bookingDto->travel->dateFrom);
if (null !== $age && $age <= Constants::BABY_MAX_AGE) {
if ($preserveDiscounted) {
return [...$otherServices, $discountedPkw, $regularPkw];
}
return [...$otherServices, $regularPkw];
}
@@ -1092,6 +1102,10 @@ class ParticipantFieldOptionsProvider extends AbstractFieldOptionsProvider
// If inbound is BUS, always show regular PKW (not discounted)
if ($inboundIsBus) {
if ($preserveDiscounted) {
return [...$otherServices, $discountedPkw, $regularPkw];
}
return [...$otherServices, $regularPkw];
}
@@ -1104,9 +1118,19 @@ class ParticipantFieldOptionsProvider extends AbstractFieldOptionsProvider
if ($discountedIsUnavailable) {
// Discounted is sold out within this booking, show only regular
// But preserve discounted if participant already has it selected
if ($preserveDiscounted) {
return [...$otherServices, $discountedPkw, $regularPkw];
}
return [...$otherServices, $regularPkw];
} else {
// Discounted has availability, show only discounted (hide regular)
// But preserve regular if participant already has it selected
if ($preserveRegular) {
return [...$otherServices, $discountedPkw, $regularPkw];
}
return [...$otherServices, $discountedPkw];
}
}