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([
|
#[Fillable([
|
||||||
'attribute_id',
|
'attribute_id',
|
||||||
|
'value',
|
||||||
'label',
|
'label',
|
||||||
'sort_order',
|
'sort_order',
|
||||||
'metadata',
|
'metadata',
|
||||||
|
|
|
||||||
|
|
@ -43,6 +43,7 @@ class StoreProductAttributeRequest extends FormRequest
|
||||||
], true)),
|
], true)),
|
||||||
'array',
|
'array',
|
||||||
],
|
],
|
||||||
|
'options.*.value' => ['required', 'string', 'max:255'],
|
||||||
'options.*.label' => ['required', 'string', 'max:255'],
|
'options.*.label' => ['required', 'string', 'max:255'],
|
||||||
'options.*.sort_order' => ['sometimes', 'integer'],
|
'options.*.sort_order' => ['sometimes', 'integer'],
|
||||||
'options.*.metadata' => ['nullable', 'array'],
|
'options.*.metadata' => ['nullable', 'array'],
|
||||||
|
|
|
||||||
|
|
@ -37,6 +37,7 @@ class UpdateProductAttributeRequest extends FormRequest
|
||||||
'metadata_schema' => ['nullable', 'array'],
|
'metadata_schema' => ['nullable', 'array'],
|
||||||
'type' => ['required', Rule::enum(FieldType::class)],
|
'type' => ['required', Rule::enum(FieldType::class)],
|
||||||
'options' => ['sometimes', 'array'],
|
'options' => ['sometimes', 'array'],
|
||||||
|
'options.*.value' => ['required', 'string', 'max:255'],
|
||||||
'options.*.label' => ['required', 'string', 'max:255'],
|
'options.*.label' => ['required', 'string', 'max:255'],
|
||||||
'options.*.sort_order' => ['sometimes', 'integer'],
|
'options.*.sort_order' => ['sometimes', 'integer'],
|
||||||
'options.*.metadata' => ['nullable', 'array'],
|
'options.*.metadata' => ['nullable', 'array'],
|
||||||
|
|
|
||||||
|
|
@ -17,6 +17,7 @@ class ProductAttributeOptionResource extends JsonResource
|
||||||
{
|
{
|
||||||
return [
|
return [
|
||||||
'id' => $this->id,
|
'id' => $this->id,
|
||||||
|
'value' => $this->value,
|
||||||
'label' => $this->label,
|
'label' => $this->label,
|
||||||
'sort_order' => $this->sort_order,
|
'sort_order' => $this->sort_order,
|
||||||
'metadata' => $this->metadata,
|
'metadata' => $this->metadata,
|
||||||
|
|
|
||||||
|
|
@ -14,6 +14,7 @@ return new class extends Migration
|
||||||
Schema::create('attribute_options', function (Blueprint $table) {
|
Schema::create('attribute_options', function (Blueprint $table) {
|
||||||
$table->id();
|
$table->id();
|
||||||
$table->foreignId('attribute_id')->constrained('productos_attributes')->cascadeOnUpdate()->cascadeOnDelete();
|
$table->foreignId('attribute_id')->constrained('productos_attributes')->cascadeOnUpdate()->cascadeOnDelete();
|
||||||
|
$table->string('value');
|
||||||
$table->string('label');
|
$table->string('label');
|
||||||
$table->unsignedInteger('sort_order')->default(0);
|
$table->unsignedInteger('sort_order')->default(0);
|
||||||
$table->json('metadata')->nullable();
|
$table->json('metadata')->nullable();
|
||||||
|
|
|
||||||
|
|
@ -37,7 +37,7 @@ class CartControllerTest extends TestCase
|
||||||
'tenant_codigo' => 'acme',
|
'tenant_codigo' => 'acme',
|
||||||
'codigo' => 'color',
|
'codigo' => 'color',
|
||||||
'nombre' => 'Color',
|
'nombre' => 'Color',
|
||||||
'type' => 'text',
|
'type' => 'string',
|
||||||
]);
|
]);
|
||||||
|
|
||||||
ProductVariantDefinition::query()->create([
|
ProductVariantDefinition::query()->create([
|
||||||
|
|
|
||||||
|
|
@ -24,11 +24,13 @@ class ProductAttributeControllerTest extends TestCase
|
||||||
],
|
],
|
||||||
'options' => [
|
'options' => [
|
||||||
[
|
[
|
||||||
|
'value' => 'red',
|
||||||
'label' => 'Red',
|
'label' => 'Red',
|
||||||
'sort_order' => 1,
|
'sort_order' => 1,
|
||||||
'metadata' => ['hex' => '#ff0000'],
|
'metadata' => ['hex' => '#ff0000'],
|
||||||
],
|
],
|
||||||
[
|
[
|
||||||
|
'value' => 'blue',
|
||||||
'label' => 'Blue',
|
'label' => 'Blue',
|
||||||
'sort_order' => 2,
|
'sort_order' => 2,
|
||||||
'metadata' => ['hex' => '#0000ff'],
|
'metadata' => ['hex' => '#0000ff'],
|
||||||
|
|
@ -41,6 +43,7 @@ class ProductAttributeControllerTest extends TestCase
|
||||||
->assertJsonPath('data.tenant_codigo', 'acme')
|
->assertJsonPath('data.tenant_codigo', 'acme')
|
||||||
->assertJsonPath('data.codigo', 'color')
|
->assertJsonPath('data.codigo', 'color')
|
||||||
->assertJsonPath('data.type', 'select')
|
->assertJsonPath('data.type', 'select')
|
||||||
|
->assertJsonPath('data.options.0.value', 'red')
|
||||||
->assertJsonPath('data.options.0.label', 'Red')
|
->assertJsonPath('data.options.0.label', 'Red')
|
||||||
->assertJsonPath('data.options.1.metadata.hex', '#0000ff');
|
->assertJsonPath('data.options.1.metadata.hex', '#0000ff');
|
||||||
|
|
||||||
|
|
@ -51,6 +54,7 @@ class ProductAttributeControllerTest extends TestCase
|
||||||
]);
|
]);
|
||||||
|
|
||||||
$this->assertDatabaseHas('attribute_options', [
|
$this->assertDatabaseHas('attribute_options', [
|
||||||
|
'value' => 'red',
|
||||||
'label' => 'Red',
|
'label' => 'Red',
|
||||||
'sort_order' => 1,
|
'sort_order' => 1,
|
||||||
]);
|
]);
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue