public function index(Application $app, Request $request, $parent_id = null, $id = null) { if ($parent_id) { $Parent = $app['eccube.repository.category']->find($parent_id); if (!$Parent) { throw new NotFoundHttpException('親カテゴリが存在しません'); } } else { $Parent = null; } if ($id) { $TargetCategory = $app['eccube.repository.category']->find($id); if (!$TargetCategory) { throw new NotFoundHttpException('カテゴリが存在しません'); } $Parent = $TargetCategory->getParent(); } else { $TargetCategory = new \Eccube\Entity\Category(); $TargetCategory->setParent($Parent); if ($Parent) { $TargetCategory->setLevel($Parent->getLevel() + 1); } else { $TargetCategory->setLevel(1); } } // $builder = $app['form.factory']->createBuilder('admin_category', $TargetCategory); $event = new EventArgs(array('builder' => $builder, 'Parent' => $Parent, 'TargetCategory' => $TargetCategory), $request); $app['eccube.event.dispatcher']->dispatch(EccubeEvents::ADMIN_PRODUCT_CATEGORY_INDEX_INITIALIZE, $event); $form = $builder->getForm(); // if ($request->getMethod() === 'POST') { $form->handleRequest($request); if ($form->isValid()) { if ($app['config']['category_nest_level'] < $TargetCategory->getLevel()) { throw new BadRequestHttpException('リクエストが不正です'); } log_info('カテゴリ登録開始', array($id)); $status = $app['eccube.repository.category']->save($TargetCategory); if ($status) { log_info('カテゴリ登録完了', array($id)); $event = new EventArgs(array('form' => $form, 'Parent' => $Parent, 'TargetCategory' => $TargetCategory), $request); $app['eccube.event.dispatcher']->dispatch(EccubeEvents::ADMIN_PRODUCT_CATEGORY_INDEX_COMPLETE, $event); $app->addSuccess('admin.category.save.complete', 'admin'); if ($Parent) { return $app->redirect($app->url('admin_product_category_show', array('parent_id' => $Parent->getId()))); } else { return $app->redirect($app->url('admin_product_category')); } } else { log_info('カテゴリ登録エラー', array($id)); $app->addError('admin.category.save.error', 'admin'); } } } $Categories = $app['eccube.repository.category']->getList($Parent); // ツリー表示のため、ルートからのカテゴリを取得 $TopCategories = $app['eccube.repository.category']->getList(null); return $app->render('Product/category.twig', array('form' => $form->createView(), 'Parent' => $Parent, 'Categories' => $Categories, 'TopCategories' => $TopCategories, 'TargetCategory' => $TargetCategory)); }
public function index(Application $app, Request $request, $parent_id = null, $id = null) { if ($parent_id) { $Parent = $app['eccube.repository.category']->find($parent_id); if (!$Parent) { throw new NotFoundHttpException(); } } else { $Parent = null; } if ($id) { $TargetCategory = $app['eccube.repository.category']->find($id); if (!$TargetCategory) { throw new NotFoundHttpException(); } $Parent = $TargetCategory->getParent(); } else { $TargetCategory = new \Eccube\Entity\Category(); $TargetCategory->setParent($Parent); if ($Parent) { $TargetCategory->setLevel($Parent->getLevel() + 1); } else { $TargetCategory->setLevel(1); } } // $form = $app['form.factory']->createBuilder('admin_category', $TargetCategory)->getForm(); // if ($request->getMethod() === 'POST') { $form->handleRequest($request); if ($form->isValid()) { if ($app['config']['category_nest_level'] < $TargetCategory->getLevel()) { throw new BadRequestHttpException(); } $status = $app['eccube.repository.category']->save($TargetCategory); if ($status) { $app->addSuccess('admin.category.save.complete', 'admin'); if ($Parent) { return $app->redirect($app->url('admin_product_category_show', array('parent_id' => $Parent->getId()))); } else { return $app->redirect($app->url('admin_product_category')); } } else { $app->addError('admin.category.save.error', 'admin'); } } } $Children = $app['eccube.repository.category']->getList(null); $Categories = $app['eccube.repository.category']->getList($Parent); $TopCategories = $app['eccube.repository.category']->findBy(array('Parent' => null), array('rank' => 'DESC')); $category_count = $app['eccube.repository.category']->getTotalCount(); return $app->render('Product/category.twig', array('form' => $form->createView(), 'Children' => $Children, 'Parent' => $Parent, 'Categories' => $Categories, 'TopCategories' => $TopCategories, 'TargetCategory' => $TargetCategory, 'category_count' => $category_count)); }
public function index(Application $app, Request $request, $category_id = null) { if ($category_id) { // カテゴリが選択されている場合は親になるカテゴリを取得しておく $Parent = $app['eccube.repository.category']->find($category_id); if (!$Parent) { throw new EntityNotFoundException(); } } else { $Parent = null; } $TargetCategory = new \Eccube\Entity\Category(); $TargetCategory->setParent($Parent); if ($Parent) { $TargetCategory->setLevel($Parent->getLevel() + 1); } else { $TargetCategory->setLevel(1); } $Children = $app['eccube.repository.category']->getList(null); $ProductCategorys = $app['eccube.plugin.product_rank.repository.product_rank']->findBySearchData($Parent); $TopCategories = $app['eccube.repository.category']->findBy(array('Parent' => null), array('rank' => 'DESC')); $category_count = $app['eccube.repository.category']->getTotalCount(); return $app->render('ProductRank/Resource/template/admin//product_rank.twig', array('Children' => $Children, 'Parent' => $Parent, 'ProductCategorys' => $ProductCategorys, 'TopCategories' => $TopCategories, 'TargetCategory' => $TargetCategory, 'category_count' => $category_count, 'category_id' => $category_id)); }