requireRole($this->security, 'ROLE_GESTIONNAIRE'); $product = $this->products->find($productId); if (!$product) { $this->mcpError('not_found', "Product not found: {$productId}"); } if (null !== $name) { $product->setName($name); } if (null !== $reference) { $product->setReference($reference); } if (null !== $supplierPrice) { $product->setSupplierPrice($supplierPrice); } if (null !== $modelTypeId) { if ('' === $modelTypeId) { $product->setTypeProduct(null); } else { $modelType = $this->modelTypes->find($modelTypeId); if (!$modelType) { $this->mcpError('not_found', "ModelType not found: {$modelTypeId}"); } $product->setTypeProduct($modelType); } } if (null !== $constructeurIds) { foreach ($product->getConstructeurLinks()->toArray() as $existing) { $this->em->remove($existing); } foreach ($constructeurIds as $cId) { $c = $this->constructeurs->find($cId); if (!$c) { $this->mcpError('not_found', "Constructeur not found: {$cId}"); } $link = new ProductConstructeurLink(); $link->setProduct($product); $link->setConstructeur($c); $this->em->persist($link); } } $this->em->flush(); return $this->jsonResponse(['id' => $product->getId(), 'name' => $product->getName()]); } }