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

@@ -99,10 +99,18 @@ class PurchaseItemResource extends JsonResource
}
$attributes = $variant->definitions
->map(fn ($definition): array => [
'name' => (string) ($definition->itemAttribute?->attribute?->nombre ?? ''),
'value' => $definition->value,
])
->groupBy('item_attribute_id')
->map(function ($definitions): array {
$itemAttribute = $definitions->first()?->itemAttribute;
$values = $definitions->pluck('value')->values();
return [
'name' => (string) ($itemAttribute?->attribute?->nombre ?? ''),
'value' => $itemAttribute?->allow_multi_select
? $values->all()
: $values->first(),
];
})
->filter(fn (array $attribute): bool => $attribute['name'] !== '' || $attribute['value'] !== null)
->values();