fix: incorrect rules around family insurances

addresses #869dr80qj
This commit is contained in:
Björn Fromme committed 2026-08-05 15:11:37 +02:00
1 parent 736128476b
commit 8a46908856
15 files changed
+859 -50

No files matched your search

@@ -301,8 +301,8 @@ class BookingDataProcessor
*/
public function createUpdateRequestPayload(?BookingDto $formData): array
{
// Apply bulk insurance if enabled (modifies DTO in place)
$this->applyBulkInsuranceIfActive($formData);
// Apply bulk or family insurance if applicable (modifies DTO in place)
$this->applyApplicantInsuranceToParticipants($formData);
$bookingData = $formData->booking;
$travelData = $formData->travel;
@@ -362,33 +362,46 @@ class BookingDataProcessor
*/
public function createBookingRequestPayload(BookingDto $bookingDto, string $bookingType): array
{
// Apply bulk insurance if enabled (modifies DTO in place)
$this->applyBulkInsuranceIfActive($bookingDto);
// Apply bulk or family insurance if applicable (modifies DTO in place)
$this->applyApplicantInsuranceToParticipants($bookingDto);
return $this->payloadBuilder->buildCreatePayload($bookingDto, $bookingType);
}
/**
* Applies bulk insurance assignment if the applicant has enabled it.
* Applies the applicant's insurance to other participants if their selection requires it.
*
* When bulk insurance is active (applicant's bulkInsuranceBooking = true), this method
* assigns the applicant's insurance TYPE to all dependent participants with automatic
* price tier adjustment based on each participant's total cost.
* Runs when either:
* - Bulk insurance is active (applicant's bulkInsuranceBooking = true): assigns the
* applicant's insurance TYPE to all dependent participants with automatic price tier
* adjustment based on each participant's individual cost.
* - The applicant selected a family insurance: family insurance covers the whole family
* under a single policy, so dependents must never hold their own insurance, regardless
* of whether the bulk checkbox was checked.
*
* IMPORTANT: In edit mode, bulk insurance only applies to participants who:
* IMPORTANT: In edit mode, non-family bulk insurance only applies to participants who:
* 1. Currently have NO insurance assigned (insurance === null)
* 2. OR whose insurance was already assigned via previous bulk operation
*
* This prevents overriding individually selected insurances that are locked.
* This prevents overriding individually selected insurances that are locked. Family
* insurance is exempt from this protection: dependents can never legitimately hold
* their own policy alongside it, so their insurance is always cleared, in edit mode too.
*
* @param BookingDto $bookingDto The booking DTO (create or edit flow)
*/
private function applyBulkInsuranceIfActive(BookingDto $bookingDto): void
private function applyApplicantInsuranceToParticipants(BookingDto $bookingDto): void
{
$applicant = $bookingDto->getParticipant(0);
// Check if bulk insurance is enabled and applicant has selected an insurance
if (null === $applicant || false === $applicant->bulkInsuranceBooking || null === $applicant->insurance) {
if (null === $applicant || null === $applicant->insurance) {
return;
}
$isFamilyInsurance = true === $applicant->insurance->familyInsurance;
// Check if bulk insurance is enabled OR the applicant's selection is a family
// insurance (which always applies to dependents, independent of the bulk checkbox)
if (false === $applicant->bulkInsuranceBooking && false === $isFamilyInsurance) {
return;
}
@@ -409,10 +422,11 @@ class BookingDataProcessor
$participantPrices
);
// Apply assignments to dependent participants (skip applicant at index 0)
// Apply assignments to all participants; for non-family insurance skip the applicant
// (they already hold the insurance they selected themselves)
foreach ($assignments as $index => $insurance) {
if (0 === $index) {
continue; // Skip applicant
if (0 === $index && false === $isFamilyInsurance) {
continue;
}
$participant = $bookingDto->getParticipant($index);
@@ -420,9 +434,10 @@ class BookingDataProcessor
continue;
}
// In edit mode: only apply bulk insurance if participant has no insurance
// This respects the rule that once assigned, insurance cannot be changed
if (BookingDto::MODE_EDIT === $bookingDto->getMode() && null !== $participant->insurance) {
// In edit mode: non-family bulk assignment must not overwrite an individually
// locked insurance. Family insurance always overrides, since dependents can
// never legitimately keep their own policy alongside it.
if (BookingDto::MODE_EDIT === $bookingDto->getMode() && false === $isFamilyInsurance && null !== $participant->insurance) {
continue; // Skip participants with existing insurance assignment
}