feat: implement product attribute options with database migration, resource, and validation requests
This commit is contained in:
parent
b0508d79b3
commit
6efda4727f
|
|
@ -9,6 +9,7 @@ use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
|||
|
||||
#[Fillable([
|
||||
'attribute_id',
|
||||
'value',
|
||||
'label',
|
||||
'sort_order',
|
||||
'metadata',
|
||||
|
|
|
|||
|
|
@ -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'],
|
||||
|
|
|
|||
|
|
@ -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'],
|
||||
|
|
|
|||
|
|
@ -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,
|
||||
|
|
|
|||
|
|
@ -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();
|
||||
|
|
|
|||
|
|
@ -37,7 +37,7 @@ class CartControllerTest extends TestCase
|
|||
'tenant_codigo' => 'acme',
|
||||
'codigo' => 'color',
|
||||
'nombre' => 'Color',
|
||||
'type' => 'text',
|
||||
'type' => 'string',
|
||||
]);
|
||||
|
||||
ProductVariantDefinition::query()->create([
|
||||
|
|
|
|||
|
|
@ -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,
|
||||
]);
|
||||
|
|
|
|||
Loading…
Reference in New Issue