feat: enhance item attributes management by adding sort order; update related models, resources, and tests for visibility and ordering of variants

This commit is contained in:
2026-08-10 13:58:35 -03:00
parent e7c8807a67
commit 8542c03466
18 changed files with 252 additions and 19 deletions

View File

@@ -21,6 +21,12 @@ class FoodService
{
private const ATTRIBUTE_CODES = ['event_date', 'horario', 'servicio'];
private const ATTRIBUTE_SORT_ORDERS = [
'event_date' => 1,
'horario' => 2,
'servicio' => 3,
];
public function __construct(private readonly CatalogService $catalogService) {}
public function current(Tenant $tenant): ?CatalogItem
@@ -169,9 +175,12 @@ class FoodService
private function itemAttributes(CatalogItem $food, Collection $attributes): Collection
{
return $attributes->mapWithKeys(function (Attribute $attribute, string $code) use ($food): array {
$itemAttribute = $food->itemAttributes()->firstOrCreate(
$itemAttribute = $food->itemAttributes()->updateOrCreate(
['attribute_id' => $attribute->id],
['allow_multi_select' => false],
[
'allow_multi_select' => false,
'sort_order' => self::ATTRIBUTE_SORT_ORDERS[$code],
],
);
return [$code => $itemAttribute];