$this->id, 'title' => $this->group_name, 'layout' => $this->product_layout, 'group_order' => $this->group_order, 'items' => $this->whenLoaded('groupItems', function () use ($request) { return $this->groupItems->map(function (GroupItem $groupItem) use ($request) { $groupable = $groupItem->groupable; if ($groupable instanceof Bundle) { return [ 'id' => $groupable->id, 'groupable_type' => 'bundle', 'groupable_id' => $groupable->id, 'nombre' => $groupable->nombre, 'descripcion' => $groupable->descripcion, 'precio' => $groupable->precio, 'cantidad_maxima' => $groupable->stock_tecnico, 'items' => $groupable->items->map(fn ($item) => [ 'cantidad' => $item->cantidad, 'variant' => (new ProductVariantResource($item->variant))->toArray($request), ])->values(), ]; } if (! $groupable instanceof ProductVariant) { return null; } $variantResource = (new ProductVariantResource($groupable))->toArray($request); $variantResource['groupable_type'] = 'variant'; $variantResource['groupable_id'] = $groupable->id; if ($this->product_layout === 'row' || $this->product_layout === 'column_with_cart' || $this->product_layout === 'vertical_with_cart') { // Devuelve el Product Variant Resource completo como pidio el usuario // "Que todo devuelva el product variant resource" return $variantResource; } // Para column_with_image o vertical_with_image if ($this->product_layout === 'column_with_image' || $this->product_layout === 'vertical_with_image') { if (isset($variantResource['images']) && count($variantResource['images']) > 0) { $variantResource['images'] = [$variantResource['images'][0]]; } return $variantResource; } return $variantResource; })->filter()->values(); }), ]; } }