/** * List categories associated with the provided product and descending from the category * defined by the parent parameter. * * @param Request $request The request object * @param int|string $id Product id * @param int $categoryId The parent category id * * httpparam include_category if true, will include the parentCategory in the response * * @Template * @AclAncestor("pim_enrich_product_categories_view") * * @return array */ public function listCategoriesAction(Request $request, $id, $categoryId) { $product = $this->findProductOr404($id); $parent = $this->findOr404($this->categoryFactory->getCategoryClass(), $categoryId); $categories = null; $includeParent = $request->get('include_parent', false); $includeParent = $includeParent === 'true'; $selectedCategoryIds = $request->get('selected', null); if (null !== $selectedCategoryIds) { $categories = $this->categoryManager->getCategoriesByIds($selectedCategoryIds); } elseif (null !== $product) { $categories = $product->getCategories(); } $trees = $this->getFilledTree($parent, $categories); return ['trees' => $trees, 'categories' => $categories]; }
/** * List categories associated with the provided product and descending from the category * defined by the parent parameter. * * @param Request $request The request object * @param int|string $id Product id * @param int $categoryId The parent category id * * httpparam include_category if true, will include the parentCategory in the response * * @Template * @AclAncestor("pim_enrich_product_categories_view") * * @return array */ public function listCategoriesAction(Request $request, $id, $categoryId) { $product = $this->findProductOr404($id); $parent = $this->categoryRepository->find($categoryId); if (null === $parent) { throw new NotFoundHttpException(sprintf('%s entity not found', $this->categoryFactory->getCategoryClass())); } $categories = null; $includeParent = $request->get('include_parent', false); $includeParent = $includeParent === 'true'; $selectedCategoryIds = $request->get('selected', null); if (null !== $selectedCategoryIds) { $categories = $this->categoryManager->getCategoriesByIds($selectedCategoryIds); } elseif (null !== $product) { $categories = $product->getCategories(); } $trees = $this->getFilledTree($parent, $categories); return ['trees' => $trees, 'categories' => $categories]; }