From c1364a458b847f6f3c6956f5c54dcfffb6f872ea Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B6rn=20Fromme?= Date: Tue, 25 Nov 2025 16:42:13 +0100 Subject: [PATCH] fix: correctly determine number of participants --- src/Service/BookingSummaryDataService.php | 26 ++++++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) diff --git a/src/Service/BookingSummaryDataService.php b/src/Service/BookingSummaryDataService.php index 15e34b7..04db820 100644 --- a/src/Service/BookingSummaryDataService.php +++ b/src/Service/BookingSummaryDataService.php @@ -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. *