src/PN/Bundle/ProductBundle/Controller/Administration/ProductController.php
/**
     * Creates a new product entity.
     *
     * @Route("/new/{category}", requirements={"category" = "\d+"}, name="product_new", methods={"GET", "POST"})
     */
Creates a new product entity.
Creates a new product entity .
public function newAction(Request $request, Category $category = null)
    {
        $this->denyAccessUnlessGranted('ROLE_ADMIN');
        $em = $this->getDoctrine()->getManager();
        $product = new Product();
        $details = new ProductDetails();
        $currency = $em->getRepository(Currency::class)->find(Currency::EGP);
        $details->setCurrency($currency);
        $product->setDetails($details);
        $product->setCategory($category);
        $form = $this->createForm(ProductType::class, $product);
        $form->handleRequest($request);
        if ($form->isSubmitted() && $form->isValid()) {
            $em->persist($product);
            $em->flush();
            $tearSheet = $this->uploadDocument($request, $form, $details);
            if ($request->request->get("action") == "saveAndNext") {
                return $this->redirectToRoute('post_set_images', ['id' => $product->getPost()->getId()]);
            }
            if ($tearSheet) {
                $this->addFlash('success', 'Successfully saved');
                return $this->redirectToRoute('product_index');
            }
            return $this->redirectToRoute('product_edit', ['id' => $product->getId()]);
        }
        return $this->render('product/admin/product/new.html.twig', array(
            'product' => $product,
            'currentCategory' => $product->getCategory(),
            'form' => $form->createView(),
        ));
    }
public function newAction ( Request $ request , Category $ category = null ) { $ this -> denyAccessUnlessGranted ( 'ROLE_ADMIN' ) ; $ em = $ this -> getDoctrine ( ) -> getManager ( ) ; $ product = new Product ( ) ; $ details = new ProductDetails ( ) ; $ currency = $ em -> getRepository ( Currency :: class ) -> find ( Currency :: EGP ) ; $ details -> setCurrency ( $ currency ) ; $ product -> setDetails ( $ details ) ; $ product -> setCategory ( $ category ) ; $ form = $ this -> createForm ( ProductType :: class , $ product ) ; $ form -> handleRequest ( $ request ) ; if ( $ form -> isSubmitted ( ) && $ form -> isValid ( ) ) { $ em -> persist ( $ product ) ; $ em -> flush ( ) ; $ tearSheet = $ this -> uploadDocument ( $ request , $ form , $ details ) ; if ( $ request -> request -> get ( " action " ) == " saveAndNext " ) { return $ this -> redirectToRoute ( 'post_set_images' , [ 'id' => $ product -> getPost ( ) -> getId ( ) ] ) ; } if ( $ tearSheet ) { $ this -> addFlash ( 'success' , 'Successfully saved' ) ; return $ this -> redirectToRoute ( 'product_index' ) ; } return $ this -> redirectToRoute ( 'product_edit' , [ 'id' => $ product -> getId ( ) ] ) ; } return $ this -> render ( 'product/admin/product/new.html.twig' , array ( 'product' => $ product , 'currentCategory' => $ product -> getCategory ( ) , 'form' => $ form -> createView ( ) , ) ) ; }
Creates a new product entity.
Creates a new product entity .