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

@@ -7,6 +7,14 @@ use App\Domains\Event\Models\EventDate;
class EffectiveEventDateResolver
{
public function resolve(EventDate $eventDate): ?EventDate
{
$date = $this->resolveLatest($eventDate);
return $date !== null && $date->suspended_at === null ? $date : null;
}
/** Sigue las reprogramaciones para presentación, incluso si el destino está suspendido. */
public function resolveLatest(EventDate $eventDate): ?EventDate
{
$current = $eventDate;
$visited = [];
@@ -23,7 +31,7 @@ class EffectiveEventDateResolver
$visited[$identity] = true;
if ($current->rescheduled_to_event_date_id === null) {
return $current->suspended_at === null ? $current : null;
return $current;
}
$current->loadMissing('rescheduledTo');

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(', ');