wip: submit booking to api
This commit is contained in:
@@ -85,8 +85,9 @@ class ParticipantBulkInsuranceFieldHandler extends AbstractParticipantFieldHandl
|
||||
$this->applyBulkInsuranceToAllParticipants($bookingDto, $participant->insurance);
|
||||
}
|
||||
|
||||
// If bulk insurance is disabled, clear dependent participants' insurances
|
||||
if (false === $isBulkEnabled) {
|
||||
// If bulk insurance was CHANGED from enabled to disabled, clear dependent participants' insurances
|
||||
// Don't clear if it was never enabled (to allow independent insurance selection)
|
||||
if (false === $isBulkEnabled && $this->wasBulkInsurancePreviouslyEnabled($bookingDto)) {
|
||||
$this->clearDependentParticipantsInsurance($bookingDto);
|
||||
}
|
||||
}
|
||||
@@ -97,8 +98,8 @@ class ParticipantBulkInsuranceFieldHandler extends AbstractParticipantFieldHandl
|
||||
* Uses InsuranceMatchingService to find the appropriate price tier for each participant
|
||||
* based on their individual travel price and eligibility criteria.
|
||||
*
|
||||
* @param BookingCreateDto $bookingDto The booking DTO with all participants
|
||||
* @param object $applicantInsurance The insurance selected by the applicant
|
||||
* @param BookingCreateDto $bookingDto The booking DTO with all participants
|
||||
* @param object $applicantInsurance The insurance selected by the applicant
|
||||
*/
|
||||
private function applyBulkInsuranceToAllParticipants(BookingCreateDto $bookingDto, object $applicantInsurance): void
|
||||
{
|
||||
@@ -139,4 +140,38 @@ class ParticipantBulkInsuranceFieldHandler extends AbstractParticipantFieldHandl
|
||||
$participant->insurance = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if bulk insurance was previously enabled by checking if dependent participants
|
||||
* have the same insurance type as the applicant.
|
||||
*
|
||||
* This prevents clearing independent insurance selections when the checkbox is simply unchecked
|
||||
* without ever having been enabled.
|
||||
*
|
||||
* @param BookingCreateDto $bookingDto The booking DTO with all participants
|
||||
*
|
||||
* @return bool True if bulk was previously active (dependent participants have matching insurance)
|
||||
*/
|
||||
private function wasBulkInsurancePreviouslyEnabled(BookingCreateDto $bookingDto): bool
|
||||
{
|
||||
$applicant = $bookingDto->participants[0] ?? null;
|
||||
if (null === $applicant || null === $applicant->insurance) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Check if any dependent participant has insurance that matches the applicant
|
||||
// If so, bulk was likely previously enabled
|
||||
foreach ($bookingDto->participants as $index => $participant) {
|
||||
if (0 === $index) {
|
||||
continue; // Skip applicant
|
||||
}
|
||||
|
||||
if (null !== $participant->insurance) {
|
||||
// If any dependent has insurance, assume bulk was previously enabled
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user