- Introduced Event and EventDate models with relationships to Tenant and CatalogItem. - Added active_event_id to Tenant model to track the currently active event. - Updated TenantResource to include active event details in the response. - Enhanced Ticket model to link to CatalogItem and Variant, allowing for event-specific ticketing. - Implemented migrations to create events and link them to catalog items and variants. - Updated seeders to populate events and their associated dates for the Fiesta Futbol Infantil tenant. - Modified Ticket generation logic to respect event dates over standard ticket dates. - Added tests for event and ticket functionalities, ensuring proper relationships and date handling.
131 lines
4.5 KiB
PHP
131 lines
4.5 KiB
PHP
<?php
|
|
|
|
namespace Database\Seeders;
|
|
|
|
use App\Domains\Catalog\Models\Attribute;
|
|
use App\Domains\Shared\Enums\FieldType;
|
|
use App\Domains\Tenant\Models\Tenant;
|
|
use Illuminate\Database\Seeder;
|
|
|
|
class AttributeSeeder extends Seeder
|
|
{
|
|
/**
|
|
* Run the database seeds.
|
|
*/
|
|
public function run(): void
|
|
{
|
|
$tenants = Tenant::all();
|
|
|
|
foreach ($tenants as $tenant) {
|
|
// Event dates replace catalog attributes for Fiesta Futbol Infantil.
|
|
if ($tenant->codigo === 'fiesta_futbol_infantil') {
|
|
Attribute::query()
|
|
->where('tenant_codigo', $tenant->codigo)
|
|
->whereIn('codigo', ['color', 'talle', 'talle_numerico', 'fecha'])
|
|
->delete();
|
|
|
|
continue;
|
|
}
|
|
|
|
$this->seedAttribute($tenant, [
|
|
'codigo' => 'color',
|
|
'nombre' => 'Color',
|
|
'type' => FieldType::Select->value,
|
|
'is_required' => true,
|
|
'metadata_schema' => [
|
|
'hex' => ['type' => 'string'],
|
|
],
|
|
'options' => [
|
|
[
|
|
'value' => 'Negro',
|
|
'label' => 'Negro',
|
|
'sort_order' => 1,
|
|
'metadata' => ['hex' => '#000000'],
|
|
],
|
|
[
|
|
'value' => 'Gris',
|
|
'label' => 'Gris',
|
|
'sort_order' => 2,
|
|
'metadata' => ['hex' => '#808080'],
|
|
],
|
|
[
|
|
'value' => 'Blanco',
|
|
'label' => 'Blanco',
|
|
'sort_order' => 3,
|
|
'metadata' => ['hex' => '#FFFFFF'],
|
|
],
|
|
[
|
|
'value' => 'Azul',
|
|
'label' => 'Azul',
|
|
'sort_order' => 4,
|
|
'metadata' => ['hex' => '#0000FF'],
|
|
],
|
|
],
|
|
]);
|
|
|
|
// Seed Talle (Size - Text options) attribute
|
|
$this->seedAttribute($tenant, [
|
|
'codigo' => 'talle',
|
|
'nombre' => 'Talle',
|
|
'type' => FieldType::Select->value,
|
|
'is_required' => true,
|
|
'options' => [
|
|
['value' => 'S', 'label' => 'S', 'sort_order' => 1],
|
|
['value' => 'M', 'label' => 'M', 'sort_order' => 2],
|
|
['value' => 'L', 'label' => 'L', 'sort_order' => 3],
|
|
['value' => 'XL', 'label' => 'XL', 'sort_order' => 4],
|
|
],
|
|
]);
|
|
|
|
// Seed Talle Numérico (Numeric Size options) attribute
|
|
$this->seedAttribute($tenant, [
|
|
'codigo' => 'talle_numerico',
|
|
'nombre' => 'Talle Numérico',
|
|
'type' => FieldType::Select->value,
|
|
'is_required' => true,
|
|
'options' => [
|
|
['value' => '38', 'label' => '38', 'sort_order' => 1],
|
|
['value' => '40', 'label' => '40', 'sort_order' => 2],
|
|
['value' => '42', 'label' => '42', 'sort_order' => 3],
|
|
['value' => '44', 'label' => '44', 'sort_order' => 4],
|
|
],
|
|
]);
|
|
|
|
// Seed Fecha attribute
|
|
$this->seedAttribute($tenant, [
|
|
'codigo' => 'fecha',
|
|
'nombre' => 'Fecha',
|
|
'type' => FieldType::Select->value,
|
|
'is_required' => true,
|
|
'options' => [
|
|
['value' => '2026-10-09', 'label' => '09/10/2026', 'sort_order' => 1],
|
|
['value' => '2026-10-10', 'label' => '10/10/2026', 'sort_order' => 2],
|
|
['value' => '2026-10-11', 'label' => '11/10/2026', 'sort_order' => 3],
|
|
['value' => '2026-10-12', 'label' => '12/10/2026', 'sort_order' => 4],
|
|
],
|
|
]);
|
|
|
|
}
|
|
}
|
|
|
|
/**
|
|
* @param array<string, mixed> $data
|
|
*/
|
|
private function seedAttribute(Tenant $tenant, array $data): void
|
|
{
|
|
$options = $data['options'] ?? [];
|
|
unset($data['options']);
|
|
|
|
$attribute = Attribute::query()->updateOrCreate(
|
|
[
|
|
'tenant_codigo' => $tenant->codigo,
|
|
'codigo' => $data['codigo'],
|
|
],
|
|
$data,
|
|
);
|
|
|
|
$attribute->options()->delete();
|
|
$attribute->options()->createMany($options);
|
|
}
|
|
}
|