feat: add migration to expand tenant_codigo in bundles and update related seeders and tests

This commit is contained in:
2026-07-17 16:07:33 -03:00
parent b8eb71896c
commit d3182fbd13
5 changed files with 233 additions and 61 deletions

View File

@@ -2,6 +2,7 @@
namespace Database\Seeders;
use App\Domains\Bundle\Models\Bundle;
use App\Domains\Catalog\Enums\InventoryPolicy;
use App\Domains\Catalog\Models\Attribute;
use App\Domains\Catalog\Models\Category;
@@ -24,6 +25,9 @@ class FiestaFutbolInfantilProductSeeder extends Seeder
throw new RuntimeException("Tenant 'fiesta_futbol_infantil' no encontrado.");
}
// Bundles reference product variants, so remove them before reseeding products.
Bundle::query()->where('tenant_codigo', $tenant->codigo)->delete();
// Delete existing products for this tenant
$existingProducts = Product::query()
->where('tenant_codigo', $tenant->codigo)
@@ -37,6 +41,7 @@ class FiestaFutbolInfantilProductSeeder extends Seeder
$category = Category::firstOrCreate(['nombre' => 'Entradas', 'tenant_code' => null]);
$dates = ['2026-10-09', '2026-10-10', '2026-10-11', '2026-10-12'];
$entradaVariants = [];
// 1. Entrada General
$entrada = $this->productService->create($tenant, [
@@ -51,7 +56,7 @@ class FiestaFutbolInfantilProductSeeder extends Seeder
]);
foreach ($dates as $date) {
$this->productService->createVariant($entrada, [
$entradaVariants[] = $this->productService->createVariant($entrada, [
'stock' => 0,
'inventory_policy' => InventoryPolicy::Unlimited->value,
'has_tickets' => true,
@@ -80,8 +85,10 @@ class FiestaFutbolInfantilProductSeeder extends Seeder
['slug' => 'estacionamiento-moto', 'nombre' => 'Estacionamiento Moto', 'precio' => 2000, 'cat' => $category->id],
];
$createdProducts = [];
foreach ($simpleProducts as $p) {
$this->productService->create($tenant, [
$createdProducts[$p['slug']] = $this->productService->create($tenant, [
'categoria_id' => $p['cat'],
'slug' => $p['slug'],
'nombre' => $p['nombre'],
@@ -91,5 +98,37 @@ class FiestaFutbolInfantilProductSeeder extends Seeder
'inventory_policy' => InventoryPolicy::Unlimited->value,
]);
}
$allDaysBundle = Bundle::query()->create([
'tenant_codigo' => $tenant->codigo,
'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,
]);
foreach ($entradaVariants as $variant) {
$allDaysBundle->items()->create([
'producto_variante_id' => $variant->id,
'cantidad' => 1,
]);
}
$foodBundle = Bundle::query()->create([
'tenant_codigo' => $tenant->codigo,
'nombre' => 'Combo 2 Panchos + 2 Hamburguesas',
'descripcion' => 'Incluye 2 panchos y 2 hamburguesas con papa frita.',
'precio' => 24000,
]);
$foodBundle->items()->createMany([
[
'producto_variante_id' => $createdProducts['pancho']->variants()->sole()->id,
'cantidad' => 2,
],
[
'producto_variante_id' => $createdProducts['hamburguesa-papa-frita']->variants()->sole()->id,
'cantidad' => 2,
],
]);
}
}