233 lines
9.2 KiB
PHP
233 lines
9.2 KiB
PHP
<?php
|
|
|
|
namespace Database\Seeders;
|
|
|
|
use App\Domains\Catalog\Enums\CatalogItemType;
|
|
use App\Domains\Catalog\Enums\EventProductType;
|
|
use App\Domains\Catalog\Enums\FeaturedGroupSource;
|
|
use App\Domains\Catalog\Enums\GroupLayout;
|
|
use App\Domains\Catalog\Enums\InventoryPolicy;
|
|
use App\Domains\Catalog\Enums\ProductLayout;
|
|
use App\Domains\Catalog\Models\CatalogItem;
|
|
use App\Domains\Catalog\Models\Category;
|
|
use App\Domains\Catalog\Models\FeaturedGroup;
|
|
use App\Domains\Catalog\Services\CatalogService;
|
|
use App\Domains\Event\Models\Event;
|
|
use App\Domains\Tenant\Models\Tenant;
|
|
use Illuminate\Database\Seeder;
|
|
use RuntimeException;
|
|
|
|
class FiestaFutbolInfantilProductSeeder extends Seeder
|
|
{
|
|
public function __construct(private readonly CatalogService $catalogService) {}
|
|
|
|
public function run(): void
|
|
{
|
|
$tenant = Tenant::query()->where('codigo', 'fiesta_futbol_infantil')->first();
|
|
|
|
if (! $tenant) {
|
|
throw new RuntimeException("Tenant 'fiesta_futbol_infantil' no encontrado.");
|
|
}
|
|
|
|
$this->deleteExistingCatalog($tenant);
|
|
|
|
$event = Event::query()->updateOrCreate(
|
|
[
|
|
'tenant_code' => $tenant->codigo,
|
|
'name' => 'Fiesta Nacional del Fútbol Infantil',
|
|
],
|
|
['address' => 'Sunchales, Santa Fe'],
|
|
);
|
|
$event->dates()->delete();
|
|
|
|
$eventDates = collect(['2026-10-09', '2026-10-10', '2026-10-11', '2026-10-12'])
|
|
->mapWithKeys(function (string $date) use ($event): array {
|
|
$eventDate = $event->dates()->create([
|
|
'date' => $date,
|
|
'time_start' => '00:00:00',
|
|
'time_end' => '23:59:59',
|
|
]);
|
|
|
|
return [$date => $eventDate];
|
|
});
|
|
|
|
$tenant->active_event_id = $event->id;
|
|
$tenant->save();
|
|
|
|
$ticketCategory = Category::query()->firstOrCreate([
|
|
'nombre' => 'Entradas',
|
|
'tenant_code' => $tenant->codigo,
|
|
]);
|
|
$foodCategory = Category::query()->firstOrCreate([
|
|
'nombre' => 'Gastronomía',
|
|
'tenant_code' => $tenant->codigo,
|
|
]);
|
|
$mealCategory = Category::query()->updateOrCreate([
|
|
'nombre' => 'Comidas',
|
|
'tenant_code' => $tenant->codigo,
|
|
], [
|
|
'categoria_id' => $foodCategory->id,
|
|
]);
|
|
$drinkCategory = Category::query()->updateOrCreate([
|
|
'nombre' => 'Bebidas',
|
|
'tenant_code' => $tenant->codigo,
|
|
], [
|
|
'categoria_id' => $foodCategory->id,
|
|
]);
|
|
$parkingCategory = Category::query()->firstOrCreate([
|
|
'nombre' => 'Estacionamiento',
|
|
'tenant_code' => $tenant->codigo,
|
|
]);
|
|
|
|
$dates = $eventDates->keys()->all();
|
|
$minimumUseDate = $dates[0].' 00:00:00';
|
|
$maximumUseDate = $dates[array_key_last($dates)].' 23:59:59';
|
|
|
|
$generalAdmission = $this->catalogService->create([
|
|
'tenant_code' => $tenant->codigo,
|
|
'event_id' => $event->id,
|
|
'event_product_type' => EventProductType::Entry->value,
|
|
'category_id' => $ticketCategory->id,
|
|
'slug' => 'entrada-general',
|
|
'nombre' => 'Entrada General',
|
|
'descripcion' => 'Acceso total al predio. No incluye acceso a estacionamiento. Niños menores de 5 años ingresan gratis.',
|
|
'precio' => 10000,
|
|
'inventory_policy' => InventoryPolicy::Unlimited->value,
|
|
'has_tickets' => true,
|
|
'minimum_use_date' => $minimumUseDate,
|
|
'maximum_use_date' => $maximumUseDate,
|
|
'variants' => array_map(
|
|
fn (string $date): array => [
|
|
'real_stock' => 0,
|
|
'event_date_id' => $eventDates->get($date)->id,
|
|
],
|
|
$dates,
|
|
),
|
|
]);
|
|
|
|
$items = [
|
|
['slug' => 'hamburguesa-papa-frita', 'nombre' => 'Hamburguesa con papa frita', 'precio' => 8000, 'category_id' => $mealCategory->id],
|
|
['slug' => 'pancho', 'nombre' => 'Pancho', 'precio' => 4000, 'category_id' => $mealCategory->id],
|
|
['slug' => 'coca-cola-500ml', 'nombre' => 'Coca Cola 500ml', 'precio' => 3000, 'category_id' => $drinkCategory->id],
|
|
['slug' => 'agua-mineral-1l', 'nombre' => 'Agua Mineral 1L', 'precio' => 2500, 'category_id' => $drinkCategory->id],
|
|
['slug' => 'estacionamiento-auto', 'nombre' => 'Estacionamiento Auto', 'precio' => 5000, 'category_id' => $parkingCategory->id],
|
|
['slug' => 'estacionamiento-moto', 'nombre' => 'Estacionamiento Moto', 'precio' => 2000, 'category_id' => $parkingCategory->id],
|
|
];
|
|
|
|
$createdItems = [];
|
|
foreach ($items as $item) {
|
|
$createdItems[$item['slug']] = $this->catalogService->create([
|
|
'tenant_code' => $tenant->codigo,
|
|
'event_id' => $event->id,
|
|
'event_product_type' => EventProductType::Product->value,
|
|
'descripcion' => $item['descripcion'] ?? $item['nombre'],
|
|
'inventory_policy' => InventoryPolicy::Unlimited->value,
|
|
'real_stock' => 0,
|
|
'minimum_use_date' => $minimumUseDate,
|
|
'maximum_use_date' => $maximumUseDate,
|
|
...$item,
|
|
]);
|
|
}
|
|
|
|
$this->catalogService->create([
|
|
'tenant_code' => $tenant->codigo,
|
|
'event_id' => $event->id,
|
|
'event_product_type' => EventProductType::Entry->value,
|
|
'type' => CatalogItemType::Bundle->value,
|
|
'slug' => 'entrada-general-todos-los-dias',
|
|
'nombre' => 'Entrada General - Todos los días',
|
|
'descripcion' => 'Incluye una entrada para cada día de la Fiesta Nacional del Fútbol Infantil.',
|
|
'precio' => 40000,
|
|
'category_id' => $ticketCategory->id,
|
|
'components' => $generalAdmission->variants
|
|
->map(fn ($variant): array => [
|
|
'catalog_item_id' => $generalAdmission->id,
|
|
'variant_id' => $variant->id,
|
|
'quantity' => 1,
|
|
])
|
|
->all(),
|
|
]);
|
|
|
|
$this->catalogService->create([
|
|
'tenant_code' => $tenant->codigo,
|
|
'event_id' => $event->id,
|
|
'event_product_type' => EventProductType::Product->value,
|
|
'type' => CatalogItemType::Bundle->value,
|
|
'slug' => 'combo-2-panchos-2-hamburguesas',
|
|
'nombre' => 'Combo 2 Panchos + 2 Hamburguesas',
|
|
'descripcion' => 'Incluye 2 panchos y 2 hamburguesas con papa frita.',
|
|
'precio' => 24000,
|
|
'category_id' => $mealCategory->id,
|
|
'components' => [
|
|
[
|
|
'catalog_item_id' => $createdItems['pancho']->id,
|
|
'quantity' => 2,
|
|
],
|
|
[
|
|
'catalog_item_id' => $createdItems['hamburguesa-papa-frita']->id,
|
|
'quantity' => 2,
|
|
],
|
|
],
|
|
]);
|
|
|
|
$this->seedFeaturedGroups($tenant, [
|
|
'Entradas' => $ticketCategory,
|
|
'Estacionamiento' => $parkingCategory,
|
|
'Comidas' => $mealCategory,
|
|
'Bebidas' => $drinkCategory,
|
|
]);
|
|
}
|
|
|
|
private function deleteExistingCatalog(Tenant $tenant): void
|
|
{
|
|
CatalogItem::query()
|
|
->where('tenant_code', $tenant->codigo)
|
|
->where('type', CatalogItemType::Bundle->value)
|
|
->each(fn (CatalogItem $item) => $this->catalogService->delete($item));
|
|
|
|
CatalogItem::query()
|
|
->where('tenant_code', $tenant->codigo)
|
|
->where('type', CatalogItemType::Standard->value)
|
|
->each(fn (CatalogItem $item) => $this->catalogService->delete($item));
|
|
}
|
|
|
|
/** @param array<string, Category> $categories */
|
|
private function seedFeaturedGroups(Tenant $tenant, array $categories): void
|
|
{
|
|
FeaturedGroup::query()->where('tenant_code', $tenant->codigo)->delete();
|
|
|
|
$groups = [
|
|
'Entradas' => [
|
|
'product_layout' => ProductLayout::Row,
|
|
'group_layout' => GroupLayout::SimpleVertical,
|
|
],
|
|
'Estacionamiento' => [
|
|
'product_layout' => ProductLayout::ColumnWithCart,
|
|
'group_layout' => GroupLayout::Simple,
|
|
],
|
|
'Comidas' => [
|
|
'product_layout' => ProductLayout::ColumnWithCart,
|
|
'group_layout' => GroupLayout::Simple,
|
|
],
|
|
'Bebidas' => [
|
|
'product_layout' => ProductLayout::ColumnWithCart,
|
|
'group_layout' => GroupLayout::Simple,
|
|
],
|
|
];
|
|
|
|
$groupOrder = 0;
|
|
foreach ($groups as $groupName => $config) {
|
|
FeaturedGroup::query()->create([
|
|
'tenant_code' => $tenant->codigo,
|
|
'source_type' => FeaturedGroupSource::Category,
|
|
'category_id' => $categories[$groupName]->id,
|
|
'product_layout' => $config['product_layout'],
|
|
'group_layout' => $config['group_layout'],
|
|
'group_name' => $groupName,
|
|
'group_order' => $groupOrder++,
|
|
]);
|
|
|
|
}
|
|
}
|
|
}
|