feat: add support for multiple event dates in variants

- Updated the FeaturedGroupService to include 'variants.eventDates' in the items query.
- Introduced a BelongsToMany relationship in EventDate for selected variants.
- Modified PurchaseItemResource and PurchaseItemSnapshotFactory to handle multiple event dates for variants.
- Enhanced StartCheckoutService to load event dates for variants.
- Updated TicketGeneratorService to accommodate event dates in ticket generation.
- Created migrations to support multi-value event dates and allow multiple variant values per attribute.
- Adjusted seeders to reflect new event date handling and added new attributes.
- Added tests to ensure correct functionality for multi-date variants and their integration with ticket generation.
This commit is contained in:
2026-08-07 11:57:38 -03:00
parent 91af233941
commit 21b70777f2
22 changed files with 516 additions and 413 deletions

View File

@@ -136,6 +136,42 @@ class CatalogServiceTest extends TestCase
);
}
public function test_it_creates_a_variant_with_multiple_event_dates(): void
{
$eventDateAttribute = $this->createAttribute('event_date', FieldType::EventDate);
$firstDate = $this->tenant->eventDates()->create([
'date' => '2026-10-09',
'time_start' => '00:00:00',
'time_end' => '23:59:59',
]);
$secondDate = $this->tenant->eventDates()->create([
'date' => '2026-10-10',
'time_start' => '00:00:00',
'time_end' => '23:59:59',
]);
$item = $this->service->create([
'tenant_code' => $this->tenant->codigo,
'slug' => 'multi-date-pass',
'nombre' => 'Multi-date pass',
'precio' => 100,
'attribute_codes' => [$eventDateAttribute->codigo],
'multi_select_attribute_codes' => ['event_date'],
'variants' => [[
'real_stock' => 5,
'event_date_ids' => [$secondDate->id, $firstDate->id],
]],
]);
$variant = $item->variants->sole();
$this->assertNull($variant->event_date_id);
$this->assertSame([$firstDate->id, $secondDate->id], $variant->eventDates->pluck('id')->all());
$this->assertSame(
[(string) $firstDate->id, (string) $secondDate->id],
$variant->selectionValues()->get('event_date'),
);
}
public function test_it_rejects_duplicate_variant_combinations(): void
{
$sector = $this->createAttribute('sector');