Ejemplo n.º 1
0
 /**
  * Creates a new Category entity.
  *
  * @Route("/", name="category_create")
  * @Method("POST")
  * @Template("ShopBundle:Category:new.html.twig")
  */
 public function createAction(Request $request)
 {
     $name = $request->request->get('name');
     $code = $request->request->get('code');
     $description = $request->request->get('description');
     $em = $this->getDoctrine()->getManager();
     //Создаем новую категорию
     $entity = new Category();
     $entity->setName($name);
     $entity->setCode($code);
     $entity->setDescription($description);
     $em->persist($entity);
     $em->flush();
     return $this->redirect($this->generateUrl('category'));
 }
Ejemplo n.º 2
0
 private function createOrUpdateCategory(Category &$category, Request &$request)
 {
     $em = $this->getDoctrine()->getManager();
     $category->setName($request->get('name'));
     $category->setUrl($request->get('url'));
     $category->setEnabled((bool) $request->get('enabled'));
     $menu = (int) $request->get('shop_part');
     $category->setShopPart($menu);
     foreach ($category->getChildren() as $child) {
         $child->setShopPart($menu);
     }
     $category->setTitle($request->get('title') ?: null);
     $category->setDescription($request->get('description') ?: null);
     $category->setKeywords($request->get('keywords') ?: null);
     $category->setSeoText($request->get('seo_text') ?: null);
     $parent = (int) $request->get('parent');
     if ($parent) {
         $parentCategory = $em->getRepository('ShopBundle:Category')->find($parent);
         if ($parentCategory) {
             $category->setParent($parentCategory);
         }
     } else {
         $category->setParent(null);
     }
     $em->persist($category);
     $em->flush();
 }