diff --git a/app/Domains/Catalog/Models/ProductAttributeOption.php b/app/Domains/Catalog/Models/ProductAttributeOption.php index 9dd1f18..f1e75a9 100644 --- a/app/Domains/Catalog/Models/ProductAttributeOption.php +++ b/app/Domains/Catalog/Models/ProductAttributeOption.php @@ -9,6 +9,7 @@ use Illuminate\Database\Eloquent\Relations\BelongsTo; #[Fillable([ 'attribute_id', + 'value', 'label', 'sort_order', 'metadata', diff --git a/app/Domains/Catalog/Requests/StoreProductAttributeRequest.php b/app/Domains/Catalog/Requests/StoreProductAttributeRequest.php index 2f7ebf4..5e8cc65 100644 --- a/app/Domains/Catalog/Requests/StoreProductAttributeRequest.php +++ b/app/Domains/Catalog/Requests/StoreProductAttributeRequest.php @@ -43,6 +43,7 @@ class StoreProductAttributeRequest extends FormRequest ], true)), 'array', ], + 'options.*.value' => ['required', 'string', 'max:255'], 'options.*.label' => ['required', 'string', 'max:255'], 'options.*.sort_order' => ['sometimes', 'integer'], 'options.*.metadata' => ['nullable', 'array'], diff --git a/app/Domains/Catalog/Requests/UpdateProductAttributeRequest.php b/app/Domains/Catalog/Requests/UpdateProductAttributeRequest.php index aa3ff7c..46f9921 100644 --- a/app/Domains/Catalog/Requests/UpdateProductAttributeRequest.php +++ b/app/Domains/Catalog/Requests/UpdateProductAttributeRequest.php @@ -37,6 +37,7 @@ class UpdateProductAttributeRequest extends FormRequest 'metadata_schema' => ['nullable', 'array'], 'type' => ['required', Rule::enum(FieldType::class)], 'options' => ['sometimes', 'array'], + 'options.*.value' => ['required', 'string', 'max:255'], 'options.*.label' => ['required', 'string', 'max:255'], 'options.*.sort_order' => ['sometimes', 'integer'], 'options.*.metadata' => ['nullable', 'array'], diff --git a/app/Domains/Catalog/Resources/ProductAttributeOptionResource.php b/app/Domains/Catalog/Resources/ProductAttributeOptionResource.php index 60b5aed..78ad00c 100644 --- a/app/Domains/Catalog/Resources/ProductAttributeOptionResource.php +++ b/app/Domains/Catalog/Resources/ProductAttributeOptionResource.php @@ -17,6 +17,7 @@ class ProductAttributeOptionResource extends JsonResource { return [ 'id' => $this->id, + 'value' => $this->value, 'label' => $this->label, 'sort_order' => $this->sort_order, 'metadata' => $this->metadata, diff --git a/database/migrations/2026_06_24_000310_create_attribute_options_table.php b/database/migrations/2026_06_24_000310_create_attribute_options_table.php index 0d79eb3..32044bf 100644 --- a/database/migrations/2026_06_24_000310_create_attribute_options_table.php +++ b/database/migrations/2026_06_24_000310_create_attribute_options_table.php @@ -14,6 +14,7 @@ return new class extends Migration Schema::create('attribute_options', function (Blueprint $table) { $table->id(); $table->foreignId('attribute_id')->constrained('productos_attributes')->cascadeOnUpdate()->cascadeOnDelete(); + $table->string('value'); $table->string('label'); $table->unsignedInteger('sort_order')->default(0); $table->json('metadata')->nullable(); diff --git a/tests/Feature/Cart/CartControllerTest.php b/tests/Feature/Cart/CartControllerTest.php index 445e6fd..ef12c19 100644 --- a/tests/Feature/Cart/CartControllerTest.php +++ b/tests/Feature/Cart/CartControllerTest.php @@ -37,7 +37,7 @@ class CartControllerTest extends TestCase 'tenant_codigo' => 'acme', 'codigo' => 'color', 'nombre' => 'Color', - 'type' => 'text', + 'type' => 'string', ]); ProductVariantDefinition::query()->create([ diff --git a/tests/Feature/Catalog/ProductAttributeControllerTest.php b/tests/Feature/Catalog/ProductAttributeControllerTest.php index cd1668d..9e36add 100644 --- a/tests/Feature/Catalog/ProductAttributeControllerTest.php +++ b/tests/Feature/Catalog/ProductAttributeControllerTest.php @@ -24,11 +24,13 @@ class ProductAttributeControllerTest extends TestCase ], 'options' => [ [ + 'value' => 'red', 'label' => 'Red', 'sort_order' => 1, 'metadata' => ['hex' => '#ff0000'], ], [ + 'value' => 'blue', 'label' => 'Blue', 'sort_order' => 2, 'metadata' => ['hex' => '#0000ff'], @@ -41,6 +43,7 @@ class ProductAttributeControllerTest extends TestCase ->assertJsonPath('data.tenant_codigo', 'acme') ->assertJsonPath('data.codigo', 'color') ->assertJsonPath('data.type', 'select') + ->assertJsonPath('data.options.0.value', 'red') ->assertJsonPath('data.options.0.label', 'Red') ->assertJsonPath('data.options.1.metadata.hex', '#0000ff'); @@ -51,6 +54,7 @@ class ProductAttributeControllerTest extends TestCase ]); $this->assertDatabaseHas('attribute_options', [ + 'value' => 'red', 'label' => 'Red', 'sort_order' => 1, ]);