refactor(catalog): Complete catalog refactor to simplify its data model and its querying.

source commits: refactor/catalog
This commit is contained in:
2026-07-21 09:23:19 -03:00
parent d3182fbd13
commit 29a2ca19a3
116 changed files with 5141 additions and 5217 deletions

View File

@@ -3,7 +3,6 @@
namespace Database\Seeders;
use App\Domains\Catalog\Models\Attribute;
use App\Domains\Catalog\Models\Product;
use App\Domains\Shared\Enums\FieldType;
use App\Domains\Tenant\Models\Tenant;
use Illuminate\Database\Seeder;
@@ -19,17 +18,15 @@ class AttributeSeeder extends Seeder
foreach ($tenants as $tenant) {
// Fiesta Futbol Infantil only uses the Fecha attribute.
$existingColor = Attribute::query()
->where('tenant_codigo', $tenant->codigo)
->where('codigo', 'color')
->first();
if ($existingColor) {
Product::deleteAttribute($existingColor);
if ($tenant->codigo === 'fiesta_futbol_infantil') {
Attribute::query()
->where('tenant_codigo', $tenant->codigo)
->whereIn('codigo', ['color', 'talle', 'talle_numerico'])
->delete();
}
if ($tenant->codigo !== 'fiesta_futbol_infantil') {
Product::createAttribute($tenant, [
$this->seedAttribute($tenant, [
'codigo' => 'color',
'nombre' => 'Color',
'type' => FieldType::Select->value,
@@ -67,17 +64,8 @@ class AttributeSeeder extends Seeder
}
// Seed Talle (Size - Text options) attribute
$existingTalle = Attribute::query()
->where('tenant_codigo', $tenant->codigo)
->where('codigo', 'talle')
->first();
if ($existingTalle) {
Product::deleteAttribute($existingTalle);
}
if ($tenant->codigo !== 'fiesta_futbol_infantil') {
Product::createAttribute($tenant, [
$this->seedAttribute($tenant, [
'codigo' => 'talle',
'nombre' => 'Talle',
'type' => FieldType::Select->value,
@@ -92,17 +80,8 @@ class AttributeSeeder extends Seeder
}
// Seed Talle Numérico (Numeric Size options) attribute
$existingTalleNumerico = Attribute::query()
->where('tenant_codigo', $tenant->codigo)
->where('codigo', 'talle_numerico')
->first();
if ($existingTalleNumerico) {
Product::deleteAttribute($existingTalleNumerico);
}
if ($tenant->codigo !== 'fiesta_futbol_infantil') {
Product::createAttribute($tenant, [
$this->seedAttribute($tenant, [
'codigo' => 'talle_numerico',
'nombre' => 'Talle Numérico',
'type' => FieldType::Select->value,
@@ -117,16 +96,7 @@ 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, [
$this->seedAttribute($tenant, [
'codigo' => 'fecha',
'nombre' => 'Fecha',
'type' => FieldType::Select->value,
@@ -141,4 +111,24 @@ class AttributeSeeder extends Seeder
}
}
/**
* @param array<string, mixed> $data
*/
private function seedAttribute(Tenant $tenant, array $data): void
{
$options = $data['options'] ?? [];
unset($data['options']);
$attribute = Attribute::query()->updateOrCreate(
[
'tenant_codigo' => $tenant->codigo,
'codigo' => $data['codigo'],
],
$data,
);
$attribute->options()->delete();
$attribute->options()->createMany($options);
}
}