products->find($productId); if (!$product) { $this->mcpError('not_found', "Product not found: {$productId}"); } $constructeurs = []; foreach ($product->getConstructeurs() as $c) { $constructeurs[] = [ 'id' => $c->getId(), 'name' => $c->getName(), ]; } $typeProduct = null; if ($product->getTypeProduct()) { $typeProduct = [ 'id' => $product->getTypeProduct()->getId(), 'name' => $product->getTypeProduct()->getName(), ]; } return $this->jsonResponse([ 'id' => $product->getId(), 'name' => $product->getName(), 'reference' => $product->getReference(), 'supplierPrice' => $product->getSupplierPrice(), 'typeProduct' => $typeProduct, 'constructeurs' => $constructeurs, 'createdAt' => $product->getCreatedAt()->format('Y-m-d H:i:s'), 'updatedAt' => $product->getUpdatedAt()->format('Y-m-d H:i:s'), ]); } }