feat: enhance product detail retrieval to support variant selection and update resource fields

This commit is contained in:
2026-06-30 16:21:15 -03:00
parent 1d0f9e323d
commit 191a40fcb9
4 changed files with 36 additions and 20 deletions

View File

@@ -10,6 +10,7 @@ use App\Domains\Catalog\Services\ProductService;
use App\Domains\Tenant\Models\Tenant;
use App\Http\Controllers\Controller;
use Illuminate\Http\JsonResponse;
use Illuminate\Http\Request;
use Illuminate\Http\Response;
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
@@ -29,10 +30,12 @@ class ProductController extends Controller
return ProductResource::make($product)->response()->setStatusCode(201);
}
public function show(Tenant $tenant, Product $producto, ProductService $productService): ProductResource
public function show(Request $request, Tenant $tenant, Product $producto, ProductService $productService): ProductResource
{
$producto = $this->resolveScopedProduct($tenant, $producto);
$producto = $productService->getProductDetail($tenant, $producto);
$variantId = $request->query('variant_id');
$variantId = is_numeric($variantId) ? (int) $variantId : null;
$producto = $productService->getProductDetail($tenant, $producto, $variantId);
return ProductResource::make($producto);
}