feat(ticket): append variant properties to ticket name in generation process; add corresponding test case

This commit is contained in:
2026-08-10 17:10:46 -03:00
parent 69320c54d4
commit 6354e26620
2 changed files with 91 additions and 1 deletions

View File

@@ -57,7 +57,7 @@ class TicketGeneratorService
return Ticket::query()->create([
'tenant_code' => $item->tenant_code,
'ticket' => (string) Str::uuid(),
'name' => $item->nombre,
'name' => $this->ticketName($item, $variant, $eventDate),
'description' => (string) ($item->descripcion ?? ''),
'source_purchase_id' => $sourcePurchaseId,
'source_catalog_item_id' => $item->getKey(),
@@ -206,6 +206,46 @@ class TicketGeneratorService
return $validityTimes->first();
}
private function ticketName(
CatalogItem $catalogItem,
?Variant $variant,
?EventDate $eventDate,
): string {
if ($variant === null) {
return $catalogItem->nombre;
}
$options = $variant->selectionOptions();
if ($eventDate !== null) {
$options->put('event_date', [
'value' => (string) $eventDate->getKey(),
'label' => $eventDate->date->format('d/m/Y'),
]);
}
$properties = $options
->flatMap(function (array $option): array {
if (array_is_list($option)) {
return collect($option)
->pluck('label')
->filter(fn ($label): bool => is_string($label) && $label !== '')
->all();
}
$label = $option['label'] ?? null;
return is_string($label) && $label !== '' ? [$label] : [];
})
->values();
if ($properties->isEmpty()) {
return $catalogItem->nombre;
}
return $catalogItem->nombre.' ('.$properties->implode(', ').')';
}
/**
* Convert a recurring time window into the fixed date and time purchased by
* the customer. Equal tickets generated together share the same snapshot.