refactor(variant): enhance selection values handling for multi-select attributes

This commit is contained in:
2026-08-07 12:07:07 -03:00
parent 21b70777f2
commit 6318a99328
6 changed files with 153 additions and 19 deletions

View File

@@ -172,6 +172,32 @@ class CatalogServiceTest extends TestCase
);
}
public function test_it_creates_multiple_values_for_any_multi_select_attribute(): void
{
$color = $this->createAttribute('color', FieldType::Select);
$color->options()->createMany([
['value' => 'Green', 'label' => 'Green', 'sort_order' => 1],
['value' => 'White', 'label' => 'White', 'sort_order' => 2],
]);
$item = $this->service->create([
'tenant_code' => $this->tenant->codigo,
'slug' => 'multi-color-shirt',
'nombre' => 'Multi-color shirt',
'precio' => 100,
'attribute_codes' => ['color'],
'multi_select_attribute_codes' => ['color'],
'variants' => [[
'real_stock' => 5,
'values' => ['color' => ['White', 'Green']],
]],
]);
$variant = $item->variants->sole();
$this->assertSame(['White', 'Green'], $variant->definitions->pluck('value')->all());
$this->assertSame(['White', 'Green'], $variant->selectionValues()->get('color'));
}
public function test_it_rejects_duplicate_variant_combinations(): void
{
$sector = $this->createAttribute('sector');