function let(DocumentManager $manager, ChannelInterface $ecommerce, ChannelInterface $mobile, LocaleInterface $enUs, LocaleInterface $frFr, CategoryInterface $category, ChannelManager $channelManager, CategoryRepositoryInterface $categoryRepository, ProductRepository $productRepository, QueryBuilder $ormQb, Builder $odmQb, Query $odmQuery, Cursor $cursor) { $enUs->getCode()->willReturn('en_US'); $frFr->getCode()->willReturn('fr_FR'); $ecommerce->getCode()->willReturn('ecommerce'); $ecommerce->getLabel()->willReturn('ECommerce'); $ecommerce->getLocales()->willReturn(array($enUs, $frFr)); $ecommerce->getCategory()->willReturn($category); $mobile->getCode()->willReturn('mobile'); $mobile->getLabel()->willReturn('Mobile'); $mobile->getLocales()->willReturn(array($enUs)); $mobile->getCategory()->willReturn($category); $odmQuery->execute()->willReturn($cursor); $productRepository->createQueryBuilder()->willReturn($odmQb); $odmQb->hydrate(Argument::any())->willReturn($odmQb); $odmQb->field(Argument::any())->willReturn($odmQb); $odmQb->in(Argument::any())->willReturn($odmQb); $odmQb->equals(Argument::any())->willReturn($odmQb); $odmQb->select('_id')->willReturn($odmQb); $odmQb->getQuery()->willReturn($odmQuery); $categoryRepository->getAllChildrenQueryBuilder($category, true)->willReturn($ormQb); $categoryRepository->getCategoryIds($category, $ormQb)->willReturn(array(1, 2, 3)); $channelManager->getFullChannels()->willReturn(array($ecommerce, $mobile)); $manager->getRepository('pim_product_class')->willReturn($productRepository); $this->beConstructedWith($manager, $channelManager, $categoryRepository, 'pim_product_class'); }
/** * Get product ids linked to a category or its children. * You can define if you just want to get the property of the actual node or with its children with the direct * parameter * * @param CategoryInterface $category the requested node * @param bool $inChildren true to take children not into account * * @return array */ public function getProductIdsInCategory(CategoryInterface $category, $inChildren = false) { $categoryQb = null; if ($inChildren) { $categoryQb = $this->categoryRepository->getAllChildrenQueryBuilder($category, true); } return $this->productRepository->getProductIdsInCategory($category, $categoryQb); }
/** * {@inheritdoc} */ public function getItemsCountInCategory(CategoryInterface $category, $inChildren = false, $inProvided = true) { $categoryQb = null; if ($inChildren) { $categoryQb = $this->categoryRepository->getAllChildrenQueryBuilder($category, $inProvided); } return $this->itemRepository->getItemsCountInCategory($category, $categoryQb); }
function let(TokenStorageInterface $tokenStorage, LocaleRepositoryInterface $localeRepository, ChannelRepositoryInterface $channelRepository, TokenInterface $token, User $user, LocaleInterface $en, LocaleInterface $fr, LocaleInterface $de, ChannelInterface $ecommerce, ChannelInterface $mobile, CategoryInterface $firstTree, CategoryInterface $secondTree, CategoryRepositoryInterface $productCategoryRepo, RequestStack $requestStack, ChoicesBuilderInterface $choicesBuilder) { $tokenStorage->getToken()->willReturn($token); $token->getUser()->willReturn($user); $en->getCode()->willReturn('en_US'); $fr->getCode()->willReturn('fr_FR'); $de->getCode()->willReturn('de_DE'); $en->isActivated()->willReturn(true); $fr->isActivated()->willReturn(true); $de->isActivated()->willReturn(true); $localeRepository->findOneByIdentifier('en_US')->willReturn($en); $localeRepository->findOneByIdentifier('fr_FR')->willReturn($fr); $localeRepository->findOneByIdentifier('de_DE')->willReturn($de); $localeRepository->getActivatedLocales()->willReturn([$en, $fr, $de]); $channelRepository->findOneBy([])->willReturn($mobile); $productCategoryRepo->getTrees()->willReturn([$firstTree, $secondTree]); $this->beConstructedWith($tokenStorage, $localeRepository, $channelRepository, $productCategoryRepo, $requestStack, $choicesBuilder, 'en_US'); }
/** * List children categories * * @param Request $request The request object * @param int $identifier The parent category identifier * * @return array */ public function listSelectedChildrenAction(Request $request, $identifier) { $parent = $this->repository->findOneByIdentifier($identifier); if (null === $parent) { return new JsonResponse(null, 404); } $selectedCategories = $this->repository->getCategoriesByCodes($request->get('selected', [])); if (0 !== $selectedCategories->count()) { $tree = $this->twigExtension->listCategoriesResponse($this->repository->getFilledTree($parent, $selectedCategories), $selectedCategories); } else { $tree = $this->twigExtension->listCategoriesResponse($this->repository->getFilledTree($parent, new ArrayCollection([$parent])), new ArrayCollection()); } // Returns only children of the given category without the node itself if (!empty($tree)) { $tree = $tree[0]['children']; } return new JsonResponse($tree); }
/** * @param Request $request * @param CategoryInterface|null $selectNode * * @return array|ArrayCollection */ protected function getChildrenCategories(Request $request, $selectNode) { $parent = $this->findCategory($request->get('id')); if (null !== $selectNode) { $categories = $this->categoryRepository->getChildrenTreeByParentId($parent->getId(), $selectNode->getId()); } else { $categories = $this->categoryRepository->getChildrenByParentId($parent->getId()); } return $categories; }
/** * {@inheritdoc} */ public function buildByChannelAndCompleteness(ChannelInterface $channel) { $qb = $this->createQueryBuilder('p'); foreach ($channel->getLocales() as $locale) { $qb->addOr($qb->expr()->field(sprintf('normalizedData.completenesses.%s-%s', $channel->getCode(), $locale->getCode()))->equals(100)); } $categoryIds = $this->categoryRepository->getAllChildrenIds($channel->getCategory()); $qb->addAnd($qb->expr()->field('categoryIds')->in($categoryIds)); return $qb; }
/** * {@inheritdoc} */ public function getCompleteProductsCountPerChannels() { $channels = $this->channelRepository->findAll(); $productRepo = $this->documentManager->getRepository($this->productClass); $productsCount = []; foreach ($channels as $channel) { $category = $channel->getCategory(); $categoryIds = $this->categoryRepository->getAllChildrenIds($category, true); foreach ($channel->getLocales() as $locale) { $data = []; $compSuffix = $channel->getCode() . '-' . $locale->getCode(); $localeCount = $productRepo->createQueryBuilder()->hydrate(false)->field('categoryIds')->in($categoryIds)->field('enabled')->equals(true)->field('normalizedData.completenesses.' . $compSuffix)->equals(100)->select('_id')->getQuery()->execute()->count(); $data['locale'] = $locale->getCode(); $data['label'] = $channel->getLabel(); $data['total'] = $localeCount; $productsCount[] = $data; } } return $productsCount; }
/** * Get children category ids * * @param integer[] $categoryIds * * @return integer[] */ protected function getAllChildrenIds(array $categoryIds) { $allChildrenIds = []; foreach ($categoryIds as $categoryId) { $category = $this->categoryRepository->find($categoryId); $childrenIds = $this->categoryRepository->getAllChildrenIds($category); $childrenIds[] = $category->getId(); $allChildrenIds = array_merge($allChildrenIds, $childrenIds); } return $allChildrenIds; }
/** * Get all categories that are not root * * @return string[] */ protected function getCategoryCodes() { if (null === $this->categoryCodes) { $this->categoryCodes = []; $categories = $this->categoryRepository->findAll(); foreach ($categories as $category) { if (null !== $category->getParent()) { $this->categoryCodes[] = $category->getCode(); } } } return $this->categoryCodes; }
/** * {@inheritdoc} */ public function getItemsCountInCategory(CategoryInterface $category, $inChildren = false, $inProvided = true) { $categoryIds = $inChildren ? $this->categoryRepository->getAllChildrenIds($category, $inProvided) : [$category->getId()]; return $this->itemRepository->getItemsCountInCategory($categoryIds); }
/** * {@inheritDoc} */ public function buildView(FormView $view, FormInterface $form, array $options) { $view->vars['trees'] = $this->categoryRepository->findBy(['parent' => null]); }
/** * 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]; }
/** * @return array * * @deprecated Please use CategoryRepositoryInterface::getTrees() instead */ public function getTrees() { return $this->categoryRepository->getTrees(); }
function let(CategoryManager $categoryManager, CategoryRepositoryInterface $categoryRepository) { $categoryRepository->findBy(['parent' => null])->willReturn(['this', 'is', 'a', 'category', 'tree']); $categoryManager->getEntityRepository()->willReturn($categoryRepository); $this->beConstructedWith($categoryManager, 'Pim\\Bundle\\CatalogBundle\\Entity\\Category', 'Pim\\Bundle\\EnrichBundle\\MassEditAction\\Operation\\Classify'); }
/** * {@inheritdoc} */ protected function getResults() { return new \ArrayIterator($this->repository->getOrderedAndSortedByTreeCategories()); }
/** * Get children category ids * * @param CategoryInterface $category * * @return integer[] */ protected function getAllChildrenIds(CategoryInterface $category) { $categoryIds = $this->categoryRepo->getAllChildrenIds($category); return $categoryIds; }
/** * Get user product category tree * * @return CategoryInterface */ public function getUserProductCategoryTree() { $defaultTree = $this->getUserOption('defaultTree'); return $defaultTree ?: current($this->categoryRepository->getTrees()); }
/** * Fetch the filled tree * * @param CategoryInterface $parent * @param Collection $categories * * @return CategoryInterface[] */ protected function getFilledTree(CategoryInterface $parent, Collection $categories) { return $this->categoryRepository->getFilledTree($parent, $categories); }