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'); }
function it_normalizes_channel(ChannelInterface $channel, CurrencyInterface $eur, CurrencyInterface $usd, LocaleInterface $en, LocaleInterface $fr, CategoryInterface $category) { $channel->getCode()->willReturn('ecommerce'); $channel->getLabel()->willReturn('Ecommerce'); $channel->getCurrencies()->willReturn([$eur, $usd]); $eur->getCode()->willReturn('EUR'); $usd->getCode()->willReturn('USD'); $channel->getLocales()->willReturn([$en, $fr]); $en->getCode()->willReturn('en_US'); $fr->getCode()->willReturn('fr_FR'); $channel->getCategory()->willReturn($category); $category->getCode()->willReturn('Master catalog'); $channel->getConversionUnits()->willReturn(['Weight' => 'Kilogram', 'Size' => 'Centimeter']); $this->normalize($channel)->shouldReturn(['code' => 'ecommerce', 'label' => 'Ecommerce', 'currencies' => ['EUR', 'USD'], 'locales' => ['en_US', 'fr_FR'], 'category' => 'Master catalog', 'conversion_units' => 'Weight: Kilogram, Size: Centimeter']); }
/** * {@inheritdoc} */ public function buildByChannelAndCompleteness(ChannelInterface $channel) { $scope = $channel->getCode(); $qb = $this->buildByScope($scope); $rootAlias = current($qb->getRootAliases()); $expression = 'pCompleteness.product = ' . $rootAlias . ' AND ' . $qb->expr()->eq('pCompleteness.ratio', '100') . ' AND ' . $qb->expr()->eq('pCompleteness.channel', $channel->getId()); $rootEntity = current($qb->getRootEntities()); $completenessMapping = $this->_em->getClassMetadata($rootEntity)->getAssociationMapping('completenesses'); $completenessClass = $completenessMapping['targetEntity']; $qb->innerJoin($completenessClass, 'pCompleteness', 'WITH', $expression); $treeId = $channel->getCategory()->getId(); $expression = $qb->expr()->eq('pCategory.root', $treeId); $qb->innerJoin($rootAlias . '.categories', 'pCategory', 'WITH', $expression); return $qb; }
/** * Applies categorization filter * * @param ProductQueryBuilderInterface $pqb * @param ChannelInterface $channel */ protected function applyCategorizationFilter(ProductQueryBuilderInterface $pqb, ChannelInterface $channel) { switch ($this->categorizationCondition) { case "onlyCategorized": $pqb->addFilter('categories.id', 'IN CHILDREN', [$channel->getCategory()->getId()]); break; case "onlyNonCategorized": $pqb->addFilter('categories.id', 'UNCLASSIFIED', []); break; } }
/** * {@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; }
/** * Returns category tree code * * @param ChannelInterface $channel * * @return string */ protected function normalizeCategoryTree(ChannelInterface $channel) { return $channel->getCategory()->getCode(); }