feat(ticket): enhance ticket name resolution to follow event date reschedules

This commit is contained in:
2026-09-14 11:33:20 -03:00
parent 9c14153199
commit a62e989bb4
3 changed files with 92 additions and 3 deletions

View File

@@ -2,10 +2,14 @@
namespace App\Domains\Ticket\Services;
use App\Domains\Event\Models\EventDate;
use App\Domains\Event\Services\EffectiveEventDateResolver;
use App\Domains\Ticket\Models\Ticket;
class TicketPresentationResolver
{
public function __construct(private readonly EffectiveEventDateResolver $effectiveEventDateResolver) {}
/** Relaciones necesarias para calcular nombre y descripción sin consultas N+1. */
public const RELATIONS = [
'sourceCatalogItem',
@@ -30,9 +34,15 @@ class TicketPresentationResolver
}
$itemAttributes = $variant->catalogItem->itemAttributes;
$eventDateLabels = $variant->selectedEventDates()
->map(fn (EventDate $date): EventDate => $this->effectiveEventDateResolver->resolveLatest($date) ?? $date)
->unique(fn (EventDate $date): int => $date->getKey())
->map(fn (EventDate $date): string => $date->date->format('d/m/Y'))
->implode(', ');
$properties = $variant->selectionOptions($itemAttributes)
->map(function (array $option, string $attributeCode) use ($itemAttributes): ?string {
$labels = collect(array_is_list($option) ? $option : [$option])
->map(function (array $option, string $attributeCode) use ($itemAttributes, $eventDateLabels): ?string {
$labels = $attributeCode === 'event_date' ? $eventDateLabels : collect(array_is_list($option) ? $option : [$option])
->pluck('label')
->filter(fn ($label): bool => is_string($label) && $label !== '')
->implode(', ');