示例#1
0
 /**
  * Edit and Saves product
  *
  * @param FormInterface    $form    Form
  * @param ProductInterface $product Product
  * @param boolean          $isValid Is valid
  *
  * @return RedirectResponse Redirect response
  *
  * @Route(
  *      path = "/{id}",
  *      name = "admin_product_view",
  *      requirements = {
  *          "id" = "\d+",
  *      },
  *      methods = {"GET"}
  * )
  * @Route(
  *      path = "/{id}/edit",
  *      name = "admin_product_edit",
  *      requirements = {
  *          "id" = "\d+",
  *      },
  *      methods = {"GET"}
  * )
  * @Route(
  *      path = "/{id}/update",
  *      name = "admin_product_update",
  *      requirements = {
  *          "id" = "\d+",
  *      },
  *      methods = {"POST"}
  * )
  *
  * @Route(
  *      path = "/new",
  *      name = "admin_product_new",
  *      methods = {"GET"}
  * )
  * @Route(
  *      path = "/new/update",
  *      name = "admin_product_save",
  *      methods = {"POST"}
  * )
  *
  * @EntityAnnotation(
  *      class = {
  *          "factory" = "elcodi.factory.product",
  *          "method" = "create",
  *          "static" = false
  *      },
  *      mapping = {
  *          "id" = "~id~"
  *      },
  *      mappingFallback = true,
  *      name = "product",
  *      persist = true
  * )
  * @FormAnnotation(
  *      class = "elcodi_admin_product_form_type_product",
  *      name  = "form",
  *      entity = "product",
  *      handleRequest = true,
  *      validate = "isValid"
  * )
  *
  * @Template
  */
 public function editAction(FormInterface $form, ProductInterface $product, $isValid)
 {
     if ($isValid) {
         $firstImage = $product->getSortedImages()->first();
         if ($firstImage instanceof ImageInterface) {
             $product->setPrincipalImage($firstImage);
         }
         $this->flush($product);
         $this->addFlash('success', $this->get('translator')->trans('admin.product.saved'));
         return $this->redirectToRoute('admin_product_list');
     }
     return ['product' => $product, 'form' => $form->createView()];
 }
示例#2
0
 /**
  * Steps necessary to store an image
  *
  * @param ObjectManager             $imageObjectManager        Image ObjectManager
  * @param ImageManager              $imageManager              ImageManager
  * @param Filesystem                $filesystem                Filesystem
  * @param fileIdentifierTransformer $fileIdentifierTransformer fileIdentifierTransformer
  * @param ProductInterface          $product                   Product
  * @param string                    $imageName                 Image name
  *
  * @return $this Self object
  */
 protected function storeImage(ObjectManager $imageObjectManager, ImageManager $imageManager, Filesystem $filesystem, FileIdentifierTransformerInterface $fileIdentifierTransformer, ProductInterface $product, $imageName)
 {
     $imagePath = realpath(dirname(__FILE__) . '/images/' . $imageName);
     $image = $imageManager->createImage(new File($imagePath));
     $image->setPath('products');
     $imageObjectManager->persist($image);
     $imageObjectManager->flush($image);
     $filesystem->write($fileIdentifierTransformer->transform($image), file_get_contents($imagePath), true);
     $product->addImage($image);
     $product->setPrincipalImage($image);
     return $this;
 }
示例#3
0
 /**
  * Steps necessary to store an image
  *
  * @param ProductInterface $product   Product
  * @param string           $imageName Image name
  *
  * @return $this Self object
  */
 protected function storeProductImage(ProductInterface $product, $imageName)
 {
     $imagePath = realpath(dirname(__FILE__) . '/images/' . $imageName);
     $image = $this->storeImage($imagePath);
     $product->addImage($image);
     $product->setPrincipalImage($image);
     return $this;
 }