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]]); }
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_converts_metric_values_given_the_configured_base_unit_in_the_channel($converter, ProductValueInterface $weightValue, ProductValueInterface $surfaceValue, ProductValueInterface $nameValue, AttributeInterface $weight, AttributeInterface $surface, AttributeInterface $name, MetricInterface $weightMetric, MetricInterface $surfaceMetric, ProductInterface $product, ChannelInterface $channel) { $weightValue->getAttribute()->willReturn($weight); $weightValue->getData()->willReturn($weightMetric); $weight->getCode()->willReturn('weight'); $weightMetric->getFamily()->willReturn('Weight'); $weightMetric->getUnit()->willReturn('KILOGRAM'); $weightMetric->getData()->willReturn(1); $surfaceValue->getAttribute()->willReturn($surface); $surfaceValue->getData()->willReturn($surfaceMetric); $surface->getCode()->willReturn('surface'); $surfaceMetric->getFamily()->willReturn('Surface'); $surfaceMetric->getUnit()->willReturn('METER_SQUARE'); $surfaceMetric->getData()->willReturn(10); $nameValue->getAttribute()->willReturn($name); $nameValue->getData()->willReturn('foobar'); $product->getValues()->willReturn(array($weightValue, $surfaceValue, $nameValue)); $channel->getConversionUnits()->willReturn(array('weight' => 'GRAM')); $converter->setFamily('Weight')->shouldBeCalled(); $converter->convert('KILOGRAM', 'GRAM', 1)->willReturn(0.001); $converter->setFamily('Surface')->shouldNotBeCalled(); $weightMetric->setData(0.001)->shouldBeCalled(); $weightMetric->setUnit('GRAM')->shouldBeCalled(); $this->convert($product, $channel); }
function it_provide_product_completeness_if_family_is_not_defined(ProductInterface $product, ChannelInterface $mobile, LocaleInterface $en, FamilyInterface $shirt) { $product->getFamily()->willReturn(null); $en->getCode()->willReturn('en_US'); $mobile->getCode()->willReturn('mobile'); $this->getProductCompleteness($product, [$mobile], [$en], 'en_US')->shouldReturn(['en_US' => ['channels' => ['mobile' => ['completeness' => null, 'missing' => []]], 'stats' => ['total' => 0, 'complete' => 0]]]); }
function it_initializes_itself($productBuilder, $catalogContext, $attributeRepository, $massActionManager, LocaleInterface $deLocale, AttributeInterface $attr1, AttributeInterface $attr2, ProductValueInterface $prodVal1, ProductValueInterface $prodVal2, ChannelInterface $channel, AttributeGroupInterface $attrGroup) { $deLocale->getCode()->willReturn('de_DE'); $this->setLocale($deLocale); $catalogContext->setLocaleCode('de_DE')->shouldBeCalled(); $attributeRepository->findWithGroups([], ['conditions' => ['unique' => 0]])->shouldBeCalled()->willReturn([$attr1, $attr2]); $attr1->setLocale('de_DE')->shouldBeCalled(); $attr2->setLocale('de_DE')->shouldBeCalled(); $attr1->getGroup()->willReturn($attrGroup); $attr2->getGroup()->willReturn($attrGroup); $attrGroup->setLocale('de_DE')->shouldBeCalledTimes(2); $massActionManager->filterLocaleSpecificAttributes([$attr1, $attr2], 'de_DE')->willReturn([$attr1, $attr2]); // First attribute $deLocale->getChannels()->willReturn([$channel]); $attr1->isScopable()->willReturn(true); $attr1->getCode()->willReturn('color'); $channel->getCode()->willReturn('mobile'); $productBuilder->createProductValue($attr1, 'de_DE', 'mobile')->shouldBeCalled()->willReturn($prodVal1); $productBuilder->addMissingPrices($prodVal1)->shouldBeCalled(); // Second attribute $attr2->isScopable()->willReturn(false); $attr2->getCode()->willReturn('price'); $productBuilder->createProductValue($attr2, 'de_DE')->shouldBeCalled()->willReturn($prodVal2); $productBuilder->addMissingPrices($prodVal2)->shouldBeCalled(); $this->initialize(); $this->getValues()->shouldHaveCount(2); }
function it_returns_well_formatted_actions_for_batch_job(AttributeInterface $attrColor, AttributeInterface $attrSize, ChannelInterface $channelMobile, ChannelInterface $channelEcommerce, AttributeRequirementInterface $colorMobileRequirement, AttributeRequirementInterface $colorEcommerceRequirement, AttributeRequirementInterface $sizeEcommerceRequirement) { $attrColor->getCode()->willReturn('color'); $attrSize->getCode()->willReturn('size'); $channelMobile->getCode()->willReturn('mobile'); $channelEcommerce->getCode()->willReturn('ecommerce'); $colorMobileRequirement->getAttribute()->willReturn($attrColor); $colorEcommerceRequirement->getAttribute()->willReturn($attrColor); $sizeEcommerceRequirement->getAttribute()->willReturn($attrSize); $colorMobileRequirement->getChannel()->willReturn($channelMobile); $colorEcommerceRequirement->getChannel()->willReturn($channelEcommerce); $sizeEcommerceRequirement->getChannel()->willReturn($channelEcommerce); $colorMobileRequirement->isRequired()->willReturn(false); $colorEcommerceRequirement->isRequired()->willReturn(true); $sizeEcommerceRequirement->isRequired()->willReturn(true); $colorMobileRequirement->getAttributeCode()->willReturn('color'); $colorEcommerceRequirement->getAttributeCode()->willReturn('color'); $sizeEcommerceRequirement->getAttributeCode()->willReturn('size'); $colorMobileRequirement->getChannelCode()->willReturn('mobile'); $colorEcommerceRequirement->getChannelCode()->willReturn('ecommerce'); $sizeEcommerceRequirement->getChannelCode()->willReturn('ecommerce'); $this->addAttributeRequirement($colorMobileRequirement); $this->addAttributeRequirement($colorEcommerceRequirement); $this->addAttributeRequirement($sizeEcommerceRequirement); $this->getActions()->shouldReturn([['attribute_code' => 'color', 'channel_code' => 'mobile', 'is_required' => false], ['attribute_code' => 'color', 'channel_code' => 'ecommerce', 'is_required' => true], ['attribute_code' => 'size', 'channel_code' => 'ecommerce', 'is_required' => true]]); }
function it_normalizes_completeness(Completeness $completeness, ChannelInterface $channel, LocaleInterface $locale) { $channel->getCode()->willReturn('ecommerce'); $locale->getCode()->willReturn('en_US'); $completeness->getChannel()->willReturn($channel); $completeness->getLocale()->willReturn($locale); $completeness->getRatio()->willReturn(42); $this->normalize($completeness, 'mongodb_json', [])->shouldReturn(["ecommerce-en_US" => 42]); }
function it_provides_channel_choices(ObjectManager $objectManager, ChannelRepositoryInterface $repository, ChannelInterface $mobile, ChannelInterface $ecommerce) { $repository->findBy(array())->willReturn(array($mobile, $ecommerce)); $mobile->getCode()->willReturn('mobile'); $mobile->getLabel()->willReturn('Mobile'); $ecommerce->getCode()->willReturn('ecommerce'); $ecommerce->getLabel()->willReturn('Ecommerce'); $this->getChannelChoices()->shouldReturn(['mobile' => 'Mobile', 'ecommerce' => 'Ecommerce']); }
function it_saves_a_channel_and_does_not_schedule($completenessManager, $optionsResolver, $objectManager, ChannelInterface $channel) { $channel->getCode()->willReturn('my_code'); $optionsResolver->resolveSaveOptions(['schedule' => false])->shouldBeCalled()->willReturn(['recalculate' => true, 'flush' => true, 'schedule' => false]); $objectManager->persist($channel)->shouldBeCalled(); $objectManager->flush()->shouldBeCalled(); $completenessManager->scheduleForchannel($channel)->shouldNotBeCalled($channel); $this->save($channel, ['schedule' => false]); }
public function it_succesfully_checks_incomplete_price_collection(ProductValueInterface $value, ChannelInterface $channel, LocaleInterface $locale, ArrayCollection $arrayCollection, CurrencyInterface $currency1, CurrencyInterface $currency2, ProductPriceInterface $price1) { $channel->getCurrencies()->willReturn($arrayCollection); $arrayCollection->toArray()->willReturn([$currency1, $currency2]); $currency1->getCode()->willReturn('USD'); $price1->getCurrency()->willReturn('USD'); $price1->getData()->willReturn(null); $value->getData()->willReturn([$price1]); $this->isComplete($value, $channel, $locale)->shouldReturn(false); }
function it_saves_a_channel_and_does_not_flushe($objectManager, $optionsResolver, $eventDispatcher, ChannelInterface $channel) { $channel->getCode()->willReturn('my_code'); $optionsResolver->resolveSaveOptions(['flush' => false])->shouldBeCalled()->willReturn(['flush' => false, 'schedule' => true]); $objectManager->persist($channel)->shouldBeCalled(); $objectManager->flush()->shouldNotBeCalled(); $eventDispatcher->dispatch(StorageEvents::PRE_SAVE, Argument::cetera())->shouldBeCalled(); $eventDispatcher->dispatch(StorageEvents::POST_SAVE, Argument::cetera())->shouldBeCalled(); $this->save($channel, ['flush' => false]); }
function it_generates_a_query_to_update_product_scopable_attributes($namingUtility, AttributeInterface $label, ChannelInterface $mobile) { $namingUtility->getScopableAttributes(false)->willReturn([$label]); $label->getCode()->willReturn('label'); $namingUtility->getLocaleCodes()->willReturn(['fr_FR', 'en_US']); $namingUtility->appendSuffixes(['normalizedData.label'], ['fr_FR', 'en_US'])->willReturn(['normalizedData.label-fr_FR', 'normalizedData.label-en_US']); $namingUtility->appendSuffixes(['normalizedData.label-fr_FR', 'normalizedData.label-en_US'], ['mobile'])->willReturn(['normalizedData.label-fr_FR-mobile', 'normalizedData.label-en_US-mobile']); $mobile->getCode()->willReturn('mobile'); $this->generateQuery($mobile, '', '', '')->shouldReturn([[['normalizedData.label-fr_FR-mobile' => ['$exists' => true]], ['$unset' => ['normalizedData.label-fr_FR-mobile' => '']], ['multiple' => true]], [['normalizedData.label-en_US-mobile' => ['$exists' => true]], ['$unset' => ['normalizedData.label-en_US-mobile' => '']], ['multiple' => true]]]); }
/** * Convert all the products metric values into the channel configured conversion units * * @param ProductInterface $product * @param ChannelInterface $channel */ public function convert(ProductInterface $product, ChannelInterface $channel) { $channelUnits = $channel->getConversionUnits(); foreach ($product->getValues() as $value) { $data = $value->getData(); $attribute = $value->getAttribute(); if ($data instanceof MetricInterface && isset($channelUnits[$attribute->getCode()])) { $channelUnit = $channelUnits[$attribute->getCode()]; $this->converter->setFamily($data->getFamily()); $data->setData($this->converter->convert($data->getUnit(), $channelUnit, $data->getData())); $data->setUnit($channelUnit); } } }
/** * {@inheritdoc} */ public function isComplete(ProductValueInterface $productValue, ChannelInterface $channel = null, LocaleInterface $locale = null) { $expectedCurrencies = array_map(function ($currency) { return $currency->getCode(); }, $channel->getCurrencies()->toArray()); foreach ($expectedCurrencies as $currency) { foreach ($productValue->getData() as $price) { if ($price->getCurrency() === $currency && null === $price->getData()) { return false; } } } return true; }
/** * {@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; }
function it_does_not_convert_null_metric_values_in_the_channel($converter, ProductValueInterface $weightValue, AttributeInterface $weight, MetricInterface $weightMetric, ProductInterface $product, ChannelInterface $channel) { $weightValue->getAttribute()->willReturn($weight); $weightValue->getData()->willReturn($weightMetric); $weight->getCode()->willReturn('weight'); $weightMetric->getFamily()->willReturn('Weight'); $weightMetric->getUnit()->willReturn(null); $weightMetric->getData()->willReturn(null); $product->getValues()->willReturn(array($weightValue)); $channel->getConversionUnits()->willReturn(array('weight' => 'GRAM')); $converter->setFamily('Weight')->shouldNotBeCalled(); $converter->convert('KILOGRAM', 'GRAM', 1)->shouldNotBeCalled(); $weightMetric->setData(null)->shouldNotBeCalled(); $weightMetric->setUnit('GRAM')->shouldNotBeCalled(); $this->convert($product, $channel); }
/** * {@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(); }
/** * {@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, array(':channel_id' => $channel->getId(), ':current_locale_ids' => $currentLocaleIds), array(':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_adds_missing_product_values_from_family_on_new_product(FamilyInterface $family, ProductInterface $product, AttributeInterface $sku, AttributeInterface $name, AttributeInterface $desc, $localeRepository, LocaleInterface $fr, LocaleInterface $en, $channelRepository, ChannelInterface $ecom, ChannelInterface $print, ProductValueInterface $skuValue) { // get expected attributes $product->getAttributes()->willReturn([$sku]); $product->getFamily()->willReturn($family); $family->getAttributes()->willReturn([$sku, $name, $desc]); // get expected values $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('desc'); $desc->getAttributeType()->willReturn('pim_catalog_text'); $desc->isLocalizable()->willReturn(true); $desc->isScopable()->willReturn(true); $desc->isLocaleSpecific()->willReturn(false); $fr->getCode()->willReturn('fr_FR'); $en->getCode()->willReturn('fr_FR'); $localeRepository->getActivatedLocales()->willReturn([$fr, $en]); $ecom->getCode()->willReturn('ecom'); $ecom->getLocales()->willReturn([$en, $fr]); $print->getCode()->willReturn('print'); $print->getLocales()->willReturn([$en, $fr]); $channelRepository->findAll()->willReturn([$ecom, $print]); // get existing values $skuValue->getAttribute()->willReturn($sku); $skuValue->getLocale()->willReturn(null); $skuValue->getScope()->willReturn(null); $product->getValues()->willReturn([$skuValue]); // add 6 new values : 4 desc (locales x scopes) + 2 name (locales $product->addValue(Argument::any())->shouldBeCalledTimes(6); $this->addMissingProductValues($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 getDeletedLocalesForChannel(ChannelInterface $channel) { $currentLocaleIds = array_map(function ($locale) { return $locale->getId(); }, $channel->getLocales()->toArray()); $dql = <<<DQL SELECT l JOIN l.channels c WHERE c.id = :channel_id AND l.id NOT IN (:current_locale_ids) DQL; $query = $this->getEntityManager()->createQuery($dql)->setParameter(':channel_id', $channel->getId())->setParameter(':current_locale_ids', implode(',', $currentLocaleIds)); return $query->getResult(); }
/** * Schedule recalculation of completenesses for all products * of a channel * * @param ChannelInterface $channel */ public function scheduleForChannel(ChannelInterface $channel) { if ($channel->getId()) { $deletedLocaleIds = $this->channelRepository->getDeletedLocaleIdsForChannel($channel); foreach ($deletedLocaleIds as $deletedLocaleId) { $deletedLocale = $this->localeRepository->find($deletedLocaleId); $this->generator->scheduleForChannelAndLocale($channel, $deletedLocale); } } }
/** * {@inheritdoc} */ public function scheduleForChannelAndLocale(ChannelInterface $channel, LocaleInterface $locale) { $sql = <<<SQL DELETE c FROM pim_catalog_completeness c WHERE c.channel_id = :channel_id AND c.locale_id = :locale_id SQL; $sql = $this->applyTableNames($sql); $stmt = $this->connection->prepare($sql); $stmt->bindValue('channel_id', $channel->getId()); $stmt->bindValue('locale_id', $locale->getId()); $stmt->execute(); }
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(); }
/** * {@inheritdoc} */ public function getChannelCode() { return $this->channel->getCode(); }
/** * 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; }
/** * 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 scheduleForChannelAndLocale(ChannelInterface $channel, LocaleInterface $locale) { $productQb = $this->documentManager->createQueryBuilder($this->productClass); $pullExpr = $productQb->expr()->addAnd($productQb->expr()->field('channel')->equals($channel->getId()))->addAnd($productQb->expr()->field('locale')->equals($locale->getId())); $productQb->update()->multiple(true)->field(sprintf('normalizedData.completenesses.%s-%s', $channel->getCode(), $locale->getCode()))->unsetField()->field('completenesses')->pull($pullExpr)->getQuery()->execute(); }
/** * Update catalog scope of users using a channel that will be removed * * @param ChannelInterface $channel * * @return null */ protected function onChannelRemoved(ChannelInterface $channel) { $users = $this->findUsersBy(array('catalogScope' => $channel)); $scopes = $this->container->get('pim_catalog.manager.channel')->getChannels(); $defaultScope = current(array_filter($scopes, function ($scope) use($channel) { return $scope->getCode() !== $channel->getCode(); })); foreach ($users as $user) { $user->setCatalogScope($defaultScope); $this->computeChangeset($user); } }
/** * {@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; }