src/Flowcode/ShopBundle/Controller/AdminProductController.php
/**
     * Creates a new Product entity.
     *
     * @Route("/", name="admin_product_create")
     * @Method("POST")
     * @Template("FlowcodeShopBundle:AdminProduct:new.html.twig")
     */
Creates a new Product entity.
Creates a new Product entity .
public function createAction(Request $request)
    {
        $entity = new Product();
        $entity = $this->addProductItemFieldData($entity);
        $form = $this->createCreateForm($entity);
        $form->handleRequest($request);
        if ($form->isValid()) {
            $em = $this->getDoctrine()->getManager();
            $em->persist($entity);
            if (is_null($entity->getMediaGallery())) {
                $mediaGallery = new Gallery();
                $mediaGallery->setName($entity->getName());
                $mediaGallery->setEnabled(true);
                $em->persist($mediaGallery);
                $entity->setMediaGallery($mediaGallery);
            }
            $em->flush();
            $this->get('session')->getFlashBag()->add(
                'success', $this->get('translator')->trans('save_success')
            );
            return $this->redirect($this->generateUrl('admin_product_show', array('id' => $entity->getId())));
        } else {
            $this->get('session')->getFlashBag()->add(
                'warning', $this->get('translator')->trans('save_fail')
            );
        }
        return array(
            'entity' => $entity,
            'form' => $form->createView(),
        );
    }
public function createAction ( Request $ request ) { $ entity = new Product ( ) ; $ entity = $ this -> addProductItemFieldData ( $ entity ) ; $ form = $ this -> createCreateForm ( $ entity ) ; $ form -> handleRequest ( $ request ) ; if ( $ form -> isValid ( ) ) { $ em = $ this -> getDoctrine ( ) -> getManager ( ) ; $ em -> persist ( $ entity ) ; if ( is_null ( $ entity -> getMediaGallery ( ) ) ) { $ mediaGallery = new Gallery ( ) ; $ mediaGallery -> setName ( $ entity -> getName ( ) ) ; $ mediaGallery -> setEnabled ( true ) ; $ em -> persist ( $ mediaGallery ) ; $ entity -> setMediaGallery ( $ mediaGallery ) ; } $ em -> flush ( ) ; $ this -> get ( 'session' ) -> getFlashBag ( ) -> add ( 'success' , $ this -> get ( 'translator' ) -> trans ( 'save_success' ) ) ; return $ this -> redirect ( $ this -> generateUrl ( 'admin_product_show' , array ( 'id' => $ entity -> getId ( ) ) ) ) ; } else { $ this -> get ( 'session' ) -> getFlashBag ( ) -> add ( 'warning' , $ this -> get ( 'translator' ) -> trans ( 'save_fail' ) ) ; } return array ( 'entity' => $ entity , 'form' => $ form -> createView ( ) , ) ; }
Creates a new Product entity.
Creates a new Product entity .
/* persist product */ /* create media gallery */ /* set media gallery */