feat: add Fecha attribute seeder and integrate FiestaFutbolInfantilProductSeeder
This commit is contained in:
parent
cababe1a43
commit
716d8e447c
|
|
@ -110,6 +110,29 @@ class AttributeSeeder extends Seeder
|
|||
],
|
||||
]);
|
||||
|
||||
// Seed Fecha attribute
|
||||
$existingFecha = Attribute::query()
|
||||
->where('tenant_codigo', $tenant->codigo)
|
||||
->where('codigo', 'fecha')
|
||||
->first();
|
||||
|
||||
if ($existingFecha) {
|
||||
Product::deleteAttribute($existingFecha);
|
||||
}
|
||||
|
||||
Product::createAttribute($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],
|
||||
],
|
||||
]);
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -28,6 +28,7 @@ class DatabaseSeeder extends Seeder
|
|||
CategorySeeder::class,
|
||||
BrandSeeder::class,
|
||||
ProductCatalogFromImagesSeeder::class,
|
||||
FiestaFutbolInfantilProductSeeder::class,
|
||||
TelepagosIntegrationSeeder::class,
|
||||
MenuSeeder::class,
|
||||
]);
|
||||
|
|
|
|||
|
|
@ -0,0 +1,102 @@
|
|||
<?php
|
||||
|
||||
namespace Database\Seeders;
|
||||
|
||||
use App\Domains\Catalog\Models\Category;
|
||||
use App\Domains\Catalog\Services\ProductService;
|
||||
use App\Domains\Tenant\Models\Tenant;
|
||||
use Illuminate\Database\Seeder;
|
||||
use RuntimeException;
|
||||
|
||||
class FiestaFutbolInfantilProductSeeder extends Seeder
|
||||
{
|
||||
public function __construct(private readonly ProductService $productService)
|
||||
{
|
||||
}
|
||||
|
||||
public function run(): void
|
||||
{
|
||||
$tenant = Tenant::query()->where('codigo', 'fiesta_futbol_infantil')->first();
|
||||
|
||||
if (!$tenant) {
|
||||
throw new RuntimeException("Tenant 'fiesta_futbol_infantil' no encontrado.");
|
||||
}
|
||||
|
||||
// Delete existing products for this tenant
|
||||
$existingProducts = \App\Domains\Catalog\Models\Product::query()
|
||||
->where('tenant_codigo', $tenant->codigo)
|
||||
->get();
|
||||
|
||||
foreach ($existingProducts as $product) {
|
||||
$this->productService->delete($product);
|
||||
}
|
||||
|
||||
// We need a category, let's just use 'Accesorios' or create an 'Entradas' category
|
||||
$category = Category::firstOrCreate(['nombre' => 'Entradas', 'tenant_code' => null]);
|
||||
|
||||
$dates = ['2026-10-09', '2026-10-10', '2026-10-11', '2026-10-12'];
|
||||
|
||||
// 1. Entrada General
|
||||
$entrada = $this->productService->create($tenant, [
|
||||
'categoria_id' => $category->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,
|
||||
'stock' => null,
|
||||
'attribute_ids' => [\App\Domains\Catalog\Models\Attribute::where('codigo', 'fecha')->where('tenant_codigo', $tenant->codigo)->first()?->id],
|
||||
]);
|
||||
|
||||
foreach ($dates as $date) {
|
||||
$this->productService->createVariant($entrada, [
|
||||
'stock' => null,
|
||||
'has_tickets' => true,
|
||||
'minimum_use_date' => $date . ' 00:00:00',
|
||||
'maximum_use_date' => $date . ' 23:59:59',
|
||||
'definitions' => [
|
||||
[
|
||||
'products_attribute_id' => \Illuminate\Support\Facades\DB::table('products_attributes')
|
||||
->where('product_id', $entrada->id)
|
||||
->first()?->id,
|
||||
'value' => $date,
|
||||
]
|
||||
],
|
||||
]);
|
||||
}
|
||||
|
||||
// Other products without variants
|
||||
$gastronomiaCategory = Category::firstOrCreate(['nombre' => 'Gastronomía', 'tenant_code' => null]);
|
||||
|
||||
$simpleProducts = [
|
||||
['slug' => 'hamburguesa-papa-frita', 'nombre' => 'Hamburguesa con papa frita', 'precio' => 8000, 'cat' => $gastronomiaCategory->id],
|
||||
['slug' => 'pancho', 'nombre' => 'Pancho', 'precio' => 4000, 'cat' => $gastronomiaCategory->id],
|
||||
['slug' => 'coca-cola-500ml', 'nombre' => 'Coca Cola 500ml', 'precio' => 3000, 'cat' => $gastronomiaCategory->id],
|
||||
['slug' => 'agua-mineral-1l', 'nombre' => 'Agua Mineral 1L', 'precio' => 2500, 'cat' => $gastronomiaCategory->id],
|
||||
['slug' => 'estacionamiento-auto', 'nombre' => 'Estacionamiento Auto', 'precio' => 5000, 'cat' => $category->id],
|
||||
['slug' => 'estacionamiento-moto', 'nombre' => 'Estacionamiento Moto', 'precio' => 2000, 'cat' => $category->id],
|
||||
];
|
||||
|
||||
foreach ($simpleProducts as $p) {
|
||||
$prod = $this->productService->create($tenant, [
|
||||
'categoria_id' => $p['cat'],
|
||||
'slug' => $p['slug'],
|
||||
'nombre' => $p['nombre'],
|
||||
'descripcion' => $p['nombre'],
|
||||
'precio' => $p['precio'],
|
||||
'stock' => null,
|
||||
]);
|
||||
|
||||
// To ensure the variant gets stock null and has_tickets if needed.
|
||||
// The default placeholder variant is created by ProductService::create with the given stock.
|
||||
// But if we want stock=null, we should update the variant.
|
||||
$variant = $prod->variants()->first();
|
||||
if ($variant) {
|
||||
$variant->stock = null;
|
||||
$variant->save();
|
||||
}
|
||||
}
|
||||
|
||||
// Also update the stock to null for the placeholder variant of Entrada General (or delete it, since we created specific variants)
|
||||
// Actually ProductService deletes placeholder variants if we add a variant with definitions!
|
||||
}
|
||||
}
|
||||
Loading…
Reference in New Issue