feat: improved promotional and purchase vouchers

This commit is contained in:
Björn Fromme committed 2025-11-21 12:43:51 +01:00
1 parent aaa7e9f4c3
commit 9d28d2f102
15 files changed
+357 -137

No files matched your search

@@ -76,6 +76,34 @@ trait ParticipantCardFlowTrait
return $this->createForm(BookingParticipantType::class, $wrapper, $formOptions);
}
/**
* Collects notifications from all participants and clears them from DTOs.
*
* This is important for scenarios where field handlers add notifications
* during form processing (e.g., voucher validation, auto-unassignment).
* Notifications from ALL participants are collected, not just the current one,
* because cross-participant logic may add notifications to multiple participants.
*
* Note: ParticipantDto stores notifications with MD5 keys to prevent duplicates,
* but the JavaScript toast controller expects a simple indexed array. We use
* array_values() to convert the associative array to an indexed array.
*
* @return array<array{type: string, message: string}> Array of notification messages
*/
private function collectAndClearNotifications(BookingDto $bookingDto): array
{
$notifications = [];
foreach ($bookingDto->participants as $participant) {
if (false === empty($participant->notifications)) {
$notifications = array_merge($notifications, $participant->notifications);
$participant->notifications = [];
}
}
// Convert MD5-keyed associative array to simple indexed array
return array_values($notifications);
}
/**
* Process single participant form refresh.
*
@@ -95,16 +123,8 @@ trait ParticipantCardFlowTrait
$form->handleRequest($request);
// Collect notifications from ALL participants (not just current one)
// This is important for auto-unassignment scenarios where other participants
// may receive notifications when the current participant takes an action
$notifications = [];
foreach ($bookingDto->participants as $participant) {
if (false === empty($participant->notifications)) {
$notifications = array_merge($notifications, $participant->notifications);
$participant->notifications = [];
}
}
// Collect notifications from field handlers
$notifications = $this->collectAndClearNotifications($bookingDto);
// Save updated booking data to session (after collecting & clearing notifications)
$this->bookingService->saveBookingDto($request, $bookingDto, $bookingDto->getMode());