Handling of event addons

This commit is contained in:
2026-08-12 17:18:45 +02:00
parent 085299336e
commit 6e4e6b645c
74 changed files with 3072 additions and 95 deletions
@@ -27,6 +27,14 @@ class SignUpCommand {
return $response;
}
// Teilnahmeoptionen (event-spezifische Pflicht-Auswahl) gegen die Event-Definition absichern.
$participationOptionRows = $this->buildParticipationOptionRows();
if ($participationOptionRows === null) {
$response->success = false;
$response->message = 'Bitte alle Auswahlfelder ausfüllen.';
return $response;
}
$eatingHabit = match ($this->request->eating_habit) {
'vegan' => EatingHabit::EATING_HABIT_VEGAN,
'vegetarian' => EatingHabit::EATING_HABIT_VEGETARIAN,
@@ -80,8 +88,89 @@ class SignUpCommand {
]
);
$this->persistParticipationOptions($response->participant, $participationOptionRows);
$this->persistAddons($response->participant);
$response->success = true;
return $response;
}
/**
* Speichert die gewählten Zusätze (Event-Addons) als Snapshot-Zeilen (Titel/Preis/Betrag) für die spätere
* Rechnung. Die Beträge sind bereits in der Controller-Auflösung (`resolveAddons`) berechnet, inkl. USt.
*/
private function persistAddons(\App\Models\EventParticipant $participant): void
{
foreach ($this->request->addonItems as $item) {
$participant->selectedAddons()->create([
'tenant' => $this->request->event->tenant,
'event_id' => $this->request->event->id,
'addon_key' => $item['key'],
'title' => $item['title'],
'price' => $item['price'] ?? 0,
'flat' => (bool)($item['flat'] ?? false),
'days' => $item['days'] ?? 0,
'amount' => $item['amount'] ?? 0,
]);
}
}
/**
* Validiert die Antworten gegen die am Event definierten Teilnahmeoptionen und erzeugt die zu speichernden
* Zeilen mit Label-Snapshots. Gibt null zurück, wenn eine Pflicht-Frage unbeantwortet oder eine Antwort
* ungültig ist (Absicherung gegen manipulierte Payloads).
*
* @return array<int, array{question_key: string, question_label: string, value: string, value_label: string}>|null
*/
private function buildParticipationOptionRows(): ?array
{
$rows = [];
foreach ($this->request->event->participation_options ?? [] as $question) {
$key = $question['key'] ?? null;
if ($key === null) {
continue;
}
$value = $this->request->participationOptions[$key] ?? null;
if ($value === null || $value === '') {
return null;
}
$option = null;
foreach ($question['options'] ?? [] as $candidate) {
if (($candidate['value'] ?? null) === $value) {
$option = $candidate;
break;
}
}
if ($option === null) {
return null;
}
$rows[] = [
'question_key' => $key,
'question_label' => $question['label'] ?? $key,
'value' => $value,
'value_label' => $option['label'] ?? $value,
];
}
return $rows;
}
/**
* @param array<int, array{question_key: string, question_label: string, value: string, value_label: string}> $rows
*/
private function persistParticipationOptions(\App\Models\EventParticipant $participant, array $rows): void
{
foreach ($rows as $row) {
$participant->selectedOptions()->create(array_merge($row, [
'tenant' => $this->request->event->tenant,
'event_id' => $this->request->event->id,
]));
}
}
}
@@ -46,6 +46,10 @@ class SignUpRequest {
public Amount $amount,
public ?string $paymentMethod,
public array $paymentOptions = [],
/** Antworten auf die Teilnahmeoptionen: [ question_key => value ]. */
public array $participationOptions = [],
/** Aufgelöste Zusätze (Event-Addons): je Eintrag [ key, title, price, flat, days, amount ]. */
public array $addonItems = [],
) {
}
}