/** * Update product * * @param Request $request * @param integer $id * * @Template("PimEnrichBundle:Product:edit.html.twig") * @AclAncestor("pim_enrich_product_index") * @return RedirectResponse */ public function updateAction(Request $request, $id) { $product = $this->findProductOr404($id); $this->productManager->ensureAllAssociationTypes($product); $form = $this->createForm('pim_product_edit', $product, $this->getEditFormOptions($product)); $form->submit($request, false); if ($form->isValid()) { try { $this->productManager->handleMedia($product); $this->productManager->save($product); $this->addFlash('success', 'flash.product.updated'); } catch (MediaManagementException $e) { $this->addFlash('error', $e->getMessage()); } $params = ['id' => $product->getId(), 'dataLocale' => $this->getDataLocaleCode()]; if ($comparisonLocale = $this->getComparisonLocale()) { $params['compareWith'] = $comparisonLocale; } return $this->redirectAfterEdit($params); } else { $this->addFlash('error', 'flash.product.invalid'); } $channels = $this->getRepository('PimCatalogBundle:Channel')->findAll(); $trees = $this->productCatManager->getProductCountByTree($product); return $this->getProductEditTemplateParams($form, $product, $channels, $trees); }
/** * Persists an object * * @param object $object */ protected function persistObject($object) { if ($object instanceof \Pim\Bundle\CatalogBundle\Model\ProductInterface) { $this->productManager->handleMedia($object); } $this->objectManager->persist($object); $this->doctrineCache->setReference($object); }