fix: correctly determine number of participants
This commit is contained in:
@@ -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.
|
||||
*
|
||||
|
||||
Reference in New Issue
Block a user