feat(ticket): append variant properties to ticket name in generation process; add corresponding test case
This commit is contained in:
@@ -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.
|
||||
|
||||
@@ -84,6 +84,52 @@ class TicketGeneratorServiceTest extends TestCase
|
||||
$this->service->generate($item->fresh(), $this->user);
|
||||
}
|
||||
|
||||
public function test_variant_properties_are_appended_to_the_ticket_name(): void
|
||||
{
|
||||
$item = $this->createTicketableItem('shirt');
|
||||
$color = Attribute::query()->create([
|
||||
'tenant_codigo' => $this->tenant->codigo,
|
||||
'codigo' => 'color',
|
||||
'nombre' => 'Color',
|
||||
'type' => FieldType::Select,
|
||||
]);
|
||||
$color->options()->create([
|
||||
'value' => 'black',
|
||||
'label' => 'Negro',
|
||||
]);
|
||||
$size = Attribute::query()->create([
|
||||
'tenant_codigo' => $this->tenant->codigo,
|
||||
'codigo' => 'size',
|
||||
'nombre' => 'Talle',
|
||||
'type' => FieldType::Select,
|
||||
]);
|
||||
$size->options()->create([
|
||||
'value' => 'xl',
|
||||
'label' => 'XL',
|
||||
]);
|
||||
$itemColor = $item->itemAttributes()->create([
|
||||
'attribute_id' => $color->id,
|
||||
'sort_order' => 1,
|
||||
]);
|
||||
$itemSize = $item->itemAttributes()->create([
|
||||
'attribute_id' => $size->id,
|
||||
'sort_order' => 2,
|
||||
]);
|
||||
$variant = $item->variants()->create([
|
||||
'inventory_id' => Inventory::query()->create()->id,
|
||||
]);
|
||||
$variant->definitions()->createMany([
|
||||
['item_attribute_id' => $itemColor->id, 'value' => 'black'],
|
||||
['item_attribute_id' => $itemSize->id, 'value' => 'xl'],
|
||||
]);
|
||||
|
||||
$ticket = $this->service
|
||||
->generate($item, $this->user, 1, $variant->id)
|
||||
->sole();
|
||||
|
||||
$this->assertSame('Shirt (Negro, XL)', $ticket->name);
|
||||
}
|
||||
|
||||
public function test_it_generates_tickets_for_every_bundle_component_and_quantity(): void
|
||||
{
|
||||
$first = $this->createTicketableItem('first');
|
||||
@@ -257,6 +303,10 @@ class TicketGeneratorServiceTest extends TestCase
|
||||
['2026-08-20 00:00:00', '2026-08-21 00:00:00'],
|
||||
$tickets->map(fn ($ticket): string => $ticket->validityTime->fixed_starts_at->format('Y-m-d H:i:s'))->all(),
|
||||
);
|
||||
$this->assertSame(
|
||||
['Multi-date-pass (20/08/2026)', 'Multi-date-pass (21/08/2026)'],
|
||||
$tickets->pluck('name')->all(),
|
||||
);
|
||||
$this->assertSame([$variant->id], $tickets->pluck('source_variant_id')->unique()->values()->all());
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user