/** * List categories and trees for a product * * @param string $id * * @AclAncestor("pim_enrich_product_categories_view") * * @return JsonResponse */ public function listAction($id) { $product = $this->findProductOr404($id); $trees = $this->productCategoryRepository->getProductCountByTree($product); $result['trees'] = $this->buildTrees($trees); $result['categories'] = $this->buildCategories($product); return new JsonResponse($result); }
/** * List categories and trees for a product * * @param string $id * * @AclAncestor("pim_enrich_product_categories_view") * * @return JsonResponse */ public function listAction($id) { $product = $this->findProductOr404($id); $trees = $this->productCategoryRepository->getProductCountByTree($product); $result = ['trees' => [], 'categories' => []]; foreach ($trees as $tree) { $result['trees'][] = ['id' => $tree['tree']->getId(), 'code' => $tree['tree']->getCode(), 'label' => $tree['tree']->getLabel(), 'associated' => $tree['itemCount'] > 0]; } foreach ($product->getCategories() as $category) { $result['categories'][] = ['id' => $category->getId(), 'code' => $category->getCode(), 'rootId' => $category->getRoot()]; } return new JsonResponse($result); }
/** * Return the number of times the product is present in each tree * * @param ProductInterface $product The product to look for in the trees * * @return array Each row of the array has the format:'tree'=>treeObject, 'productCount'=>integer * * @deprecated Will be remove in 1.5, please use ProductCategoryRepositoryInterface::getProductCountByTree() * instead. */ public function getProductCountByTree(ProductInterface $product) { return $this->productRepository->getProductCountByTree($product); }