shopit-back/database/seeders/AttributeSeeder.php

139 lines
4.8 KiB
PHP

<?php
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;
class AttributeSeeder extends Seeder
{
/**
* Run the database seeds.
*/
public function run(): void
{
$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)
->where('codigo', 'talle')
->first();
if ($existingTalle) {
Product::deleteAttribute($existingTalle);
}
Product::createAttribute($tenant, [
'codigo' => 'talle',
'nombre' => 'Talle',
'type' => FieldType::Select->value,
'is_required' => true,
'options' => [
['value' => 'S', 'label' => 'S', 'sort_order' => 1],
['value' => 'M', 'label' => 'M', 'sort_order' => 2],
['value' => 'L', 'label' => 'L', 'sort_order' => 3],
['value' => 'XL', 'label' => 'XL', 'sort_order' => 4],
],
]);
// 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);
}
Product::createAttribute($tenant, [
'codigo' => 'talle_numerico',
'nombre' => 'Talle Numérico',
'type' => FieldType::Select->value,
'is_required' => true,
'options' => [
['value' => '38', 'label' => '38', 'sort_order' => 1],
['value' => '40', 'label' => '40', 'sort_order' => 2],
['value' => '42', 'label' => '42', 'sort_order' => 3],
['value' => '44', 'label' => '44', 'sort_order' => 4],
],
]);
// 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],
],
]);
}
}
}