/**
  * {@inheritdoc}
  *
  * Expected data input format :
  * {
  *     "originalFilename": "original_filename.extension",
  *     "filePath": "/current/file/path/original_filename.extension"
  * }
  */
 public function setAttributeData(ProductInterface $product, AttributeInterface $attribute, $data, array $options = [])
 {
     $options = $this->resolver->resolve($options);
     $this->checkLocaleAndScope($attribute, $options['locale'], $options['scope'], 'media');
     $this->checkData($attribute, $data);
     $file = $this->getFileData($attribute, $data);
     $this->setMedia($product, $attribute, $file, $data['originalFilename'], $options['locale'], $options['scope']);
     $this->mediaManager->handleProductMedias($product);
 }
 /**
  * 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->mediaManager->handleProductMedias($product);
             $this->productSaver->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);
 }
Example #3
0
 /**
  * Persists an object
  *
  * @param object $object
  */
 protected function persistObject($object)
 {
     if ($object instanceof \Pim\Bundle\CatalogBundle\Model\ProductInterface) {
         $this->mediaManager->handleProductMedias($object);
     }
     $this->objectManager->persist($object);
     $this->doctrineCache->setReference($object);
 }
 /**
  * @param ProductInterface $product
  *
  * @return null
  *
  * @deprecated will be removed in 1.4, replaced by MediaManager::handleProductMedias
  */
 public function handleMedia(ProductInterface $product)
 {
     return $this->mediaManager->handleProductMedias($product);
 }