refactor(variant): enhance selection values handling for multi-select attributes
This commit is contained in:
@@ -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();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user