function let(DocumentManager $manager, Channel $ecommerce, Channel $mobile, Locale $enUs, Locale $frFr, CategoryInterface $category, ChannelManager $channelManager, CategoryRepository $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 boolean $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); }
/** * Returns formatted root categories * * * @return array */ protected function getFormattedRootCategory($code) { if (empty($this->formattedRootCategories)) { $this->rootCategories = $this->categoryRepository->getRootNodes(); foreach ($this->rootCategories as $rootCategory) { $this->formattedRootCategories[$rootCategory->getId()] = $rootCategory->getCode(); } } return $this->formattedRootCategories[$code]; }
/** * @param ChannelManager $channelManager * @param NormalizerGuesser $normalizerGuesser */ public function __construct(ChannelManager $channelManager, NormalizerGuesser $normalizerGuesser, CategoryRepository $categoryRepository, ProductManager $productManager) { $this->channelManager = $channelManager; $this->productManager = $channelManager; $this->normalizerGuesser = $normalizerGuesser; $this->categoryRepository = $categoryRepository; $this->productManager = $productManager; if (empty($this->formatedRootCategories)) { $this->rootCategories = $this->categoryRepository->getRootNodes(); foreach ($this->rootCategories as $rootCategory) { $this->formatedRootCategories[$rootCategory->getId()] = $rootCategory->getCode(); } } }
/** * {@inheritdoc} */ public function buildByChannelAndCompleteness(Channel $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; }
/** * Get move normalized categories. * * @param CategoryInterface $category * @param array $context * * @return array */ protected function getNormalizedMoveCategory(CategoryInterface $category, array $context) { $prestashopCategoryId = $this->getPrestashopCategoryId($category, $context['prestashopUrl']); $prestashopCategoryNewParentId = $this->categoryMappingManager->getIdFromCategory($category->getParent(), $context['prestashopUrl'], $context['categoryMapping']); $previousCategories = $this->categoryRepository->getPrevSiblings($category); $previousCategory = end($previousCategories); $previousPrestashopCategoryId = null; if ($previousCategory && null !== $previousCategory) { $previousPrestashopCategoryId = $this->categoryMappingManager->getIdFromCategory($previousCategory, $context['prestashopUrl'], $context['categoryMapping']); } return [$prestashopCategoryId, $prestashopCategoryNewParentId, $previousPrestashopCategoryId]; }
/** * {@inheritdoc} */ public function getCompleteProductsCountPerChannels() { $channels = $this->channelManager->getFullChannels(); $productRepo = $this->documentManager->getRepository($this->productClass); $productsCount = array(); foreach ($channels as $channel) { $category = $channel->getCategory(); $categoryQb = $this->categoryRepository->getAllChildrenQueryBuilder($category, true); $categoryIds = $this->categoryRepository->getCategoryIds($category, $categoryQb); foreach ($channel->getLocales() as $locale) { $data = array(); $compSuffix = $channel->getCode() . '-' . $locale->getCode(); $qb = $productRepo->createQueryBuilder()->hydrate(false)->field('categoryIds')->in($categoryIds)->field('enabled')->equals(true)->field('normalizedData.completenesses.' . $compSuffix)->equals(100)->select('_id'); $localeCount = $qb->getQuery()->execute()->count(); $data['locale'] = $locale->getCode(); $data['label'] = $channel->getLabel(); $data['total'] = $localeCount; $productsCount[] = $data; } } return $productsCount; }