feat: implement product seeding logic from image catalog and add supporting service methods and requests

This commit is contained in:
2026-07-01 09:48:43 -03:00
parent 35384b48ab
commit e78e64ed2e
7 changed files with 99 additions and 47 deletions

View File

@@ -18,6 +18,52 @@ class AttributeSeeder extends Seeder
$tenants = Tenant::all();
foreach ($tenants as $tenant) {
// Seed Color attribute
$existingColor = Attribute::query()
->where('tenant_codigo', $tenant->codigo)
->where('codigo', 'color')
->first();
if ($existingColor) {
Product::deleteAttribute($existingColor);
}
Product::createAttribute($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
$existingTalle = Attribute::query()
->where('tenant_codigo', $tenant->codigo)
@@ -64,51 +110,6 @@ class AttributeSeeder extends Seeder
],
]);
// Seed Color attribute
$existingColor = Attribute::query()
->where('tenant_codigo', $tenant->codigo)
->where('codigo', 'color')
->first();
if ($existingColor) {
Product::deleteAttribute($existingColor);
}
Product::createAttribute($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'],
],
],
]);
}
}
}

View File

@@ -16,7 +16,8 @@ class CategorySeeder extends Seeder
'Remeras',
'Pantalones',
'Zapatillas',
'Buzos'
'Buzos',
'Accesorios'
];
foreach ($categories as $nombre) {

View File

@@ -42,6 +42,7 @@ class ProductCatalogFromImagesSeeder extends Seeder
],
'zapatillas_lecoq' => ['price' => 109999, 'stock' => 6],
'zapatillas_topper' => ['price' => 104999, 'stock' => 7],
'pelota_mundial' => ['price' => 45000, 'stock' => 15],
];
/**
@@ -220,6 +221,15 @@ class ProductCatalogFromImagesSeeder extends Seeder
$variantGroup['files']
);
if ($attributeIds->isEmpty()) {
$this->productService->createVariant($product, [
'stock' => $variantGroup['stock'],
'definitions' => [],
'images' => $images,
]);
continue;
}
foreach ($sizes as $size) {
$definitions = [];
@@ -301,6 +311,19 @@ class ProductCatalogFromImagesSeeder extends Seeder
];
}
if ($groupKey === 'pelota_mundial') {
return [
'type' => 'pelota',
'category_name' => 'Accesorios',
'brand_name' => 'Adidas',
'color' => null,
'attribute_codes' => [],
'product_slug' => $groupKey,
'product_name' => 'Pelota Mundial 2026',
'description' => 'Pelota oficial del mundial 2026 sin variantes.',
];
}
$segments = explode('_', $groupKey);
$type = array_shift($segments);