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');
 }
 /**
  * Returns normalized category
  *
  * @param ChannelInterface $channel
  *
  * @return string
  */
 protected function normalizeCategoryTree(ChannelInterface $channel)
 {
     $translations = $channel->getCategory()->getTranslations();
     $labels = [];
     foreach ($translations as $translation) {
         $labels[$translation->getLocale()] = $translation->getLabel();
     }
     return ['id' => $channel->getCategory()->getId(), 'code' => $channel->getCategory()->getCode(), 'labels' => $labels];
 }
 function it_normalizes_channel(ChannelInterface $channel, CategoryInterface $category, CurrencyInterface $currencyUSD, CurrencyInterface $currencyEUR)
 {
     $units = ['weight_attribute' => WeightFamilyInterface::GRAM, 'length_attribute' => LengthFamilyInterface::CENTIMETER];
     $channel->getCode()->willReturn('my_code');
     $channel->getLabel()->willReturn('my_label');
     $channel->getCurrencies()->willReturn([$currencyEUR, $currencyUSD]);
     $channel->getLocaleCodes()->willReturn(['fr_FR', 'en_US', 'de_DE', 'es_ES']);
     $channel->getCategory()->willReturn($category);
     $channel->getConversionUnits()->willReturn($units);
     $category->getCode()->willReturn('winter');
     $currencyEUR->getCode()->willReturn('EUR');
     $currencyUSD->getCode()->willReturn('USD');
     $this->normalize($channel, 'standard', [])->shouldReturn(['code' => 'my_code', 'label' => 'my_label', 'currencies' => ['EUR', 'USD'], 'locales' => ['fr_FR', 'en_US', 'de_DE', 'es_ES'], 'category_tree' => 'winter', 'conversion_units' => $units]);
 }
 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']);
 }
 function it_normalizes_channel(ChannelInterface $channel, CurrencyInterface $eur, CurrencyInterface $usd, LocaleInterface $en, LocaleInterface $fr, CategoryInterface $category, CategoryTranslationInterface $translation)
 {
     $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');
     $category->getId()->willReturn(42);
     $translation->getLabel()->willReturn('label');
     $translation->getLocale()->willReturn('en_US');
     $category->getTranslations()->willReturn([$translation]);
     $channel->getConversionUnits()->willReturn(['Weight' => 'Kilogram', 'Size' => 'Centimeter']);
     $this->normalize($channel)->shouldReturn(['code' => 'ecommerce', 'label' => 'Ecommerce', 'currencies' => ['EUR', 'USD'], 'locales' => ['en_US', 'fr_FR'], 'category' => ['id' => 42, 'code' => 'master', 'labels' => ['en_US' => 'label']], 'conversion_units' => 'Weight: Kilogram, Size: Centimeter']);
 }
 /**
  * Returns category tree code
  *
  * @param ChannelInterface $channel
  *
  * @return string
  */
 protected function normalizeCategoryTree(ChannelInterface $channel)
 {
     return $channel->getCategory()->getCode();
 }
 /**
  * {@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 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;
 }