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