Example #1
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();
 }