where('codigo', 'fiesta_futbol_infantil')->first(); if (! $tenant) { throw new RuntimeException("Tenant 'fiesta_futbol_infantil' no encontrado."); } $this->deleteExistingCatalog($tenant); FeaturedGroup::query()->where('tenant_code', $tenant->codigo)->delete(); Category::query()->where('tenant_code', $tenant->codigo)->update(['categoria_id' => null]); Category::query()->where('tenant_code', $tenant->codigo)->delete(); $tenant->update([ 'event_title' => 'Fiesta Nacional del FĂștbol Infantil', 'event_location' => 'Sunchales, Santa Fe', ]); $tenant->eventDates()->delete(); $eventDates = collect(['2026-10-09', '2026-10-10', '2026-10-11', '2026-10-12']) ->map(fn (string $date) => $tenant->eventDates()->create([ 'date' => $date, 'time_start' => '00:00:00', 'time_end' => '23:59:59', ])); $dateIds = $eventDates->pluck('id')->map(fn ($id): int => (int) $id)->values(); $this->createProduct($tenant, [ 'slug' => 'camiseta', 'nombre' => 'Camiseta', 'precio' => 18000, 'attribute_codes' => ['color', 'talle'], 'variants' => collect(['Verde', 'Blanco']) ->crossJoin(['14', 'S', 'M', 'L', 'XL', 'XXL']) ->map(fn (array $values): array => [ 'real_stock' => 0, 'values' => ['color' => $values[0], 'talle' => $values[1]], ])->all(), ]); $this->createProduct($tenant, [ 'slug' => 'alojamiento', 'nombre' => 'Alojamiento', 'precio' => 35000, 'attribute_codes' => ['tipo_alojamiento'], 'variants' => collect(['Carpa', 'Motorhome'])->map(fn (string $type): array => [ 'real_stock' => 0, 'values' => ['tipo_alojamiento' => $type], ])->all(), ]); $this->createProduct($tenant, [ 'slug' => 'comida', 'nombre' => 'Comida', 'precio' => 8000, 'attribute_codes' => ['event_date', 'horario', 'servicio'], 'variants' => $dateIds ->crossJoin(['Desayuno', 'Almuerzo', 'Cena'], ['Comedor', 'Vianda']) ->map(fn (array $values): array => [ 'real_stock' => 0, 'event_date_ids' => [(int) $values[0]], 'values' => ['horario' => $values[1], 'servicio' => $values[2]], ])->all(), ]); $this->createProduct($tenant, [ 'slug' => 'abono', 'nombre' => 'Abono', 'precio' => 40000, 'event_product_type' => EventProductType::Entry->value, 'has_tickets' => true, 'attribute_codes' => ['event_date'], 'multi_select_attribute_codes' => ['event_date'], 'variants' => $this->nonEmptySubsets($dateIds) ->map(fn (array $ids): array => ['real_stock' => 0, 'event_date_ids' => $ids]) ->all(), ]); FeaturedGroup::query()->create([ 'tenant_code' => $tenant->codigo, 'source_type' => FeaturedGroupSource::All, 'category_id' => null, 'product_layout' => ProductLayout::ColumnWithCart, 'group_layout' => GroupLayout::Simple, 'group_name' => 'Productos', 'group_order' => 0, ]); } private function deleteExistingCatalog(Tenant $tenant): void { CatalogItem::query() ->where('tenant_code', $tenant->codigo) ->orderByRaw("CASE WHEN type = 'bundle' THEN 0 ELSE 1 END") ->each(fn (CatalogItem $item) => $this->catalogService->delete($item)); } /** @param array $data */ private function createProduct(Tenant $tenant, array $data): CatalogItem { return $this->catalogService->create([ 'tenant_code' => $tenant->codigo, 'event_product_type' => EventProductType::Product->value, 'descripcion' => $data['nombre'], 'inventory_policy' => InventoryPolicy::Unlimited->value, ...$data, ]); } /** @return Collection> */ private function nonEmptySubsets(Collection $values): Collection { $items = $values->all(); $subsets = collect(); for ($mask = 1; $mask < (1 << count($items)); $mask++) { $subset = []; foreach ($items as $index => $item) { if (($mask & (1 << $index)) !== 0) { $subset[] = $item; } } $subsets->push($subset); } return $subsets ->sortBy(fn (array $subset): string => count($subset).':'.implode(',', $subset)) ->values(); } }