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_resolves_eligible_values_for_a_set_of_attributes($localeRepository, $channelRepository, AttributeInterface $sku, AttributeInterface $name, AttributeInterface $desc, AttributeInterface $tax, LocaleInterface $fr, LocaleInterface $en, ChannelInterface $ecom, ChannelInterface $print)
 {
     $sku->getCode()->willReturn('sku');
     $sku->getAttributeType()->willReturn('pim_catalog_identifier');
     $sku->isLocalizable()->willReturn(false);
     $sku->isScopable()->willReturn(false);
     $sku->isLocaleSpecific()->willReturn(false);
     $name->getCode()->willReturn('name');
     $name->getAttributeType()->willReturn('pim_catalog_text');
     $name->isLocalizable()->willReturn(true);
     $name->isScopable()->willReturn(false);
     $name->isLocaleSpecific()->willReturn(false);
     $desc->getCode()->willReturn('description');
     $desc->getAttributeType()->willReturn('pim_catalog_text');
     $desc->isLocalizable()->willReturn(true);
     $desc->isScopable()->willReturn(true);
     $desc->isLocaleSpecific()->willReturn(false);
     $tax->getCode()->willReturn('tax');
     $tax->getAttributeType()->willReturn('pim_catalog_text');
     $tax->isLocalizable()->willReturn(true);
     $tax->isScopable()->willReturn(false);
     $tax->isLocaleSpecific()->willReturn(true);
     $tax->getLocaleSpecificCodes()->willReturn(['fr_FR']);
     $fr->getCode()->willReturn('fr_FR');
     $en->getCode()->willReturn('en_US');
     $localeRepository->getActivatedLocales()->willReturn([$fr, $en]);
     $ecom->getCode()->willReturn('ecommerce');
     $ecom->getLocales()->willReturn([$en, $fr]);
     $print->getCode()->willReturn('print');
     $print->getLocales()->willReturn([$en, $fr]);
     $channelRepository->findAll()->willReturn([$ecom, $print]);
     $this->resolveEligibleValues([$sku, $name, $desc, $tax])->shouldReturn([['attribute' => 'sku', 'type' => 'pim_catalog_identifier', 'locale' => null, 'scope' => null], ['attribute' => 'name', 'type' => 'pim_catalog_text', 'locale' => 'fr_FR', 'scope' => null], ['attribute' => 'name', 'type' => 'pim_catalog_text', 'locale' => 'en_US', 'scope' => null], ['attribute' => 'description', 'type' => 'pim_catalog_text', 'locale' => 'en_US', 'scope' => 'ecommerce'], ['attribute' => 'description', 'type' => 'pim_catalog_text', 'locale' => 'fr_FR', 'scope' => 'ecommerce'], ['attribute' => 'description', 'type' => 'pim_catalog_text', 'locale' => 'en_US', 'scope' => 'print'], ['attribute' => 'description', 'type' => 'pim_catalog_text', 'locale' => 'fr_FR', 'scope' => 'print'], ['attribute' => 'tax', 'type' => 'pim_catalog_text', 'locale' => 'fr_FR', 'scope' => null]]);
 }
 /**
  * Returns an array containing the locale values
  *
  * @param ChannelInterface $channel
  *
  * @return array
  */
 protected function normalizeLocales(ChannelInterface $channel)
 {
     $locales = [];
     foreach ($channel->getLocales() as $locale) {
         $locales[] = $locale->getCode();
     }
     return $locales;
 }
 function it_normalizes_a_channel($collectionFilter, $localeNormalizer, $channelNormalizer, ChannelInterface $channel, LocaleInterface $locale1, LocaleInterface $locale2)
 {
     $channel->getLocales()->willReturn([$locale1, $locale2]);
     $collectionFilter->filterCollection([$locale1, $locale2], 'pim.internal_api.locale.view')->willReturn([$locale1]);
     $localeNormalizer->normalize($locale1, 'json')->willReturn(['code' => 'fr_FR', 'label' => 'French']);
     $channelNormalizer->normalize($channel, 'json', [])->willReturn(['keyFromNormalizer' => 'dataFromNormalizer']);
     $this->normalize($channel, Argument::cetera())->shouldReturn(['keyFromNormalizer' => 'dataFromNormalizer', 'locales' => [['code' => 'fr_FR', 'label' => 'French']]]);
 }
 function it_returns_flat_data_without_media($productBuilder, ChannelInterface $channel, LocaleInterface $locale, ChannelManager $channelManager, ProductInterface $product, Serializer $serializer)
 {
     $localeCodes = ['en_US'];
     $channel->getLocales()->willReturn(new ArrayCollection([$locale]));
     $channel->getLocaleCodes()->willReturn($localeCodes);
     $productBuilder->addMissingProductValues($product, [$channel], [$locale])->shouldBeCalled();
     $product->getValues()->willReturn([]);
     $this->setDecimalSeparator(',');
     $serializer->normalize($product, 'flat', ['scopeCode' => 'foobar', 'localeCodes' => $localeCodes, 'decimal_separator' => ',', 'date_format' => 'yyyy-MM-dd'])->willReturn(['normalized_product']);
     $channelManager->getChannelByCode('foobar')->willReturn($channel);
     $this->setChannel('foobar');
     $this->process($product)->shouldReturn(['media' => [], 'product' => ['normalized_product']]);
 }
 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 getDeletedLocaleIdsForChannel(ChannelInterface $channel)
    {
        $currentLocaleIds = array_map(function ($locale) {
            return $locale->getId();
        }, $channel->getLocales()->toArray());
        $sql = <<<SQL
    SELECT cl.locale_id
    FROM pim_catalog_channel_locale cl
    WHERE cl.channel_id = :channel_id
      AND cl.locale_id NOT IN (:current_locale_ids)
SQL;
        $stmt = $this->getEntityManager()->getConnection()->executeQuery($sql, [':channel_id' => $channel->getId(), ':current_locale_ids' => $currentLocaleIds], [':current_locale_ids' => Connection::PARAM_INT_ARRAY]);
        $rows = $stmt->fetchAll();
        $locales = array_map(function ($row) {
            return (int) $row['locale_id'];
        }, $rows);
        return $locales;
    }
 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']);
 }
 /**
  * {@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;
 }
 /**
  * Get the completeness fields for the channel
  *
  * @param ChannelInterface $channel
  *
  * @return array
  */
 protected function getCompletenessNormFields(ChannelInterface $channel = null)
 {
     $normFields = [];
     $channels = [];
     if (null === $channel) {
         $channels = $this->namingUtility->getChannels();
     } else {
         $channels[] = $channel;
     }
     foreach ($channels as $channel) {
         foreach ($channel->getLocales() as $locale) {
             $normFields[] = sprintf('%s.completenesses.%s-%s', ProductQueryUtility::NORMALIZED_FIELD, $channel->getCode(), $locale->getCode());
         }
     }
     return $normFields;
 }
 function it_generates_completeness_indexes($namingUtility, $collection, ChannelInterface $channelWeb, ChannelInterface $channelPrint, LocaleInterface $localeFr, LocaleInterface $localeEn)
 {
     $indexes = array_fill(0, 10, 'fake_index');
     $collection->getIndexInfo()->willReturn($indexes);
     $namingUtility->getChannels()->willReturn([$channelWeb, $channelPrint]);
     $channelWeb->getLocales()->willReturn([$localeEn]);
     $channelPrint->getLocales()->willReturn([$localeFr, $localeEn]);
     $channelPrint->getCode()->willReturn('PRINT');
     $channelWeb->getCode()->willReturn('WEB');
     $localeEn->getCode()->willReturn('en_US');
     $localeFr->getCode()->willReturn('fr_FR');
     $indexOptions = ['background' => true, 'w' => 0];
     $collection->ensureIndex(['normalizedData.completenesses.PRINT-en_US' => 1], $indexOptions)->shouldBeCalled();
     $collection->ensureIndex(['normalizedData.completenesses.PRINT-fr_FR' => 1], $indexOptions)->shouldBeCalled();
     $collection->ensureIndex(['normalizedData.completenesses.WEB-en_US' => 1], $indexOptions)->shouldBeCalled();
     $this->ensureCompletenessesIndexes();
 }
 /**
  * Generate a list of potential completeness value from existing channel
  * or from the provided channel
  *
  * @param ChannelInterface $channel
  *
  * @return array
  */
 protected function getChannelLocaleCombinations(ChannelInterface $channel = null)
 {
     $channels = [];
     $combinations = [];
     if (null !== $channel) {
         $channels = [$channel];
     } else {
         $channels = $this->channelRepository->getFullChannels();
     }
     foreach ($channels as $channel) {
         $locales = $channel->getLocales();
         foreach ($locales as $locale) {
             $combinations[] = $channel->getCode() . '-' . $locale->getCode();
         }
     }
     return $combinations;
 }
 /**
  * {@inheritdoc}
  */
 public function getDeletedLocalesForChannel(ChannelInterface $channel)
 {
     $currentLocaleIds = array_map(function (LocaleInterface $locale) {
         return $locale->getId();
     }, $channel->getLocales()->toArray());
     return $this->createQueryBuilder('l')->innerJoin('l.channels', 'lc')->andWhere('lc.id = :channel_id')->andWhere('l.id NOT IN (:current_locale_ids)')->setParameter(':channel_id', $channel->getId())->setParameter(':current_locale_ids', implode(',', $currentLocaleIds))->getQuery()->getResult();
 }