fix: correctly determine number of participants

This commit is contained in:
Björn Fromme
2025-11-25 16:42:13 +01:00
parent ecc4741f56
commit c1364a458b
+25 -1
View File
@@ -75,9 +75,12 @@ class BookingSummaryDataService
// Fetch CMS data (images, etc.)
$cmsData = $this->getCmsData($bookingDto);
// Calculate participant count from room capacity (source of truth)
$participantCount = $this->calculateParticipantCountFromRooms($bookingDto);
return [
'selectedRooms' => $selectedRooms,
'participantCount' => count($bookingDto->participants),
'participantCount' => $participantCount,
'totalPrice' => number_format($totalPrice, 2, ',', '.').' €',
'groupedSelectedRooms' => $groupedSelectedRooms,
'assignmentCounts' => $roomCounts,
@@ -86,6 +89,27 @@ class BookingSummaryDataService
];
}
/**
* Calculates participant count from room selections.
*
* This is the source of truth for participant count, calculated by
* multiplying each selected room's quantity by its maximum capacity (maxPax).
*/
private function calculateParticipantCountFromRooms(BookingDto $bookingDto): int
{
$totalCapacity = 0;
$availableRooms = $bookingDto->travel->getAvailableRooms();
foreach ($bookingDto->roomSelections as $selection) {
if ($selection->quantity > 0 && isset($availableRooms[$selection->roomId])) {
$room = $availableRooms[$selection->roomId];
$totalCapacity += $selection->quantity * ($room->maxPax ?? 0);
}
}
return $totalCapacity;
}
/**
* Fetches CMS data for the product and hotel in the booking.
*