/** * @param ChannelInterface $channel * @param string $field * @param mixed $data * * @throws \InvalidArgumentException */ protected function setData(ChannelInterface $channel, $field, $data) { if ('code' === $field) { $channel->setCode($data); } elseif ('tree' === $field) { $category = $this->findCategory($data); if (null !== $category) { $channel->setCategory($category); } else { throw new \InvalidArgumentException(sprintf('Category with "%s" code does not exist', $data)); } } elseif ('locales' === $field) { foreach ($data as $localeCode) { $locale = $this->findLocale($localeCode); if (null !== $locale) { $channel->addLocale($locale); } else { throw new \InvalidArgumentException(sprintf('Locale with "%s" code does not exist', $localeCode)); } } } elseif ('currencies' === $field) { foreach ($data as $currencyCode) { $currency = $this->findCurrency($currencyCode); if (null !== $currency) { $channel->addCurrency($currency); } else { throw new \InvalidArgumentException(sprintf('Currency with "%s" code does not exist', $currencyCode)); } } } elseif ('label' === $field) { $channel->setLabel($data); } elseif ('color' === $field) { $channel->setColor($data); } }
function it_provide_product_completeness_if_family_is_not_defined(ProductInterface $product, ChannelInterface $mobile, LocaleInterface $en) { $product->getFamily()->willReturn(null); $en->getCode()->willReturn('en_US'); $mobile->getCode()->willReturn('mobile'); $this->getProductCompleteness($product, [$mobile], [$en], 'en_US')->shouldReturn([['channels' => [['completeness' => null, 'missing' => []]], 'stats' => ['total' => 0, 'complete' => 0], 'locale' => '']]); }
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_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_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_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']]]); }
/** * Returns an array containing the currency values * * @param ChannelInterface $channel * * @return array */ protected function normalizeCurrencies(ChannelInterface $channel) { $currencies = []; foreach ($channel->getCurrencies() as $currency) { $currencies[] = $currency->getCode(); } return $currencies; }
function it_provides_default_values($decoratedProvider, ChannelRepositoryInterface $channelRepository, LocaleRepositoryInterface $localeRepository, LocaleInterface $locale, ChannelInterface $channel) { $channel->getCode()->willReturn('channel_code'); $channelRepository->getFullChannels()->willReturn([$channel]); $locale->getCode()->willReturn('locale_code'); $localeRepository->getActivatedLocaleCodes()->willReturn([$locale]); $decoratedProvider->getDefaultValues()->willReturn(['decoratedParam' => true]); $this->getDefaultValues()->shouldReturnWellFormedDefaultValues(); }
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_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]]]); }
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_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']]); }
/** * {@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; }
function it_builds_user_product_context_for_normalization($tokenStorage, $localeRepository, $channelRepository, $choicesBuilder, ChannelInterface $userChannel, ChannelInterface $ecommerce, LocaleInterface $fr, LocaleInterface $en, TokenInterface $token, UserInterface $user) { $userChannel->getCode()->willReturn('mobile'); $channelRepository->findOneByIdentifier([])->willReturn($userChannel); $tokenStorage->getToken()->willReturn($token); $token->getUser()->willReturn($user); $channelRepository->findAll()->willReturn([$ecommerce]); $choicesBuilder->buildChoices([$ecommerce])->willReturn(['mobile' => $userChannel, 'ecommerce' => $ecommerce]); $fr->getCode()->willReturn('fr_FR'); $en->getCode()->willReturn('en_US'); $localeRepository->getActivatedLocales()->willReturn([$en, $fr]); $user->getUiLocale()->willReturn($fr); $user->getCatalogScope()->willReturn($userChannel); $this->toArray()->shouldReturn(['locales' => ['en_US', 'fr_FR'], 'channels' => ['mobile', 'ecommerce'], 'locale' => 'fr_FR']); }
/** * {@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(); }
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); }
/** * 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()])) { if (null === $data->getData()) { return; } $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 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, 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_updates_a_channel($categoryRepository, $localeRepository, $currencyRepository, ChannelInterface $channel, CategoryInterface $tree, LocaleInterface $enUS, LocaleInterface $frFR, CurrencyInterface $usd, CurrencyInterface $eur) { $values = ['code' => 'ecommerce', 'label' => 'Ecommerce', 'locales' => ['en_US', 'fr_FR'], 'currencies' => ['EUR', 'USD'], 'tree' => 'master_catalog', 'conversion_units' => ['weight' => 'GRAM']]; $channel->setCode('ecommerce')->shouldBeCalled(); $channel->setLabel('Ecommerce')->shouldBeCalled(); $categoryRepository->findOneByIdentifier('master_catalog')->willReturn($tree); $channel->setCategory($tree)->shouldBeCalled(); $localeRepository->findOneByIdentifier('en_US')->willReturn($enUS); $localeRepository->findOneByIdentifier('fr_FR')->willReturn($frFR); $channel->setLocales([$enUS, $frFR])->shouldBeCalled(); $currencyRepository->findOneByIdentifier('EUR')->willReturn($eur); $currencyRepository->findOneByIdentifier('USD')->willReturn($usd); $channel->setCurrencies([$eur, $usd])->shouldBeCalled(); $channel->setConversionUnits(['weight' => 'GRAM'])->shouldBeCalled(); $this->update($channel, $values, []); }
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']); }
function it_removes_obsolete_scopable_indexes_when_channel_removed($collection, ChannelInterface $ecommerce) { $ecommerce->getCode()->willReturn('ecommerce'); $collection->getIndexInfo()->willReturn([["key" => ["_id" => 1]], ["key" => ["normalizedData.title-ecommerce-en_US" => 1]], ["key" => ["normalizedData.title-ecommerce-de_DE" => 1]], ["key" => ["normalizedData.title-mobile-de_DE" => 1]], ["key" => ["normalizedData.manufacturer_title" => 1]], ["key" => ["normalizedData.title_left-en_US" => 1]], ["key" => ["normalizedData.title_left-de_DE" => 1]], ["key" => ["normalizedData.price-ecommerce.EUR.data" => 1]], ["key" => ["normalizedData.price-mobile.USD.data" => 1]], ["key" => ["normalizedData.name-mobile" => 1]], ["key" => ["normalizedData.name-ecommerce" => 1]], ["key" => ["normalizedData.mobile_support.id" => 1]], ["key" => ["normalizedData.color-ecommerce.id" => 1]], ["key" => ["normalizedData.completenesses-ecommerce-en_US" => 1]], ["key" => ["normalizedData.completenesses-ecommerce-de_DE" => 1]]]); $collection->deleteIndex('normalizedData.title-ecommerce-en_US')->shouldBeCalled(); $collection->deleteIndex('normalizedData.title-ecommerce-de_DE')->shouldBeCalled(); $collection->deleteIndex('normalizedData.price-ecommerce.EUR.data')->shouldBeCalled(); $collection->deleteIndex('normalizedData.name-ecommerce')->shouldBeCalled(); $collection->deleteIndex('normalizedData.color-ecommerce.id')->shouldBeCalled(); $collection->deleteIndex('normalizedData.completenesses-ecommerce-en_US')->shouldBeCalled(); $collection->deleteIndex('normalizedData.completenesses-ecommerce-de_DE')->shouldBeCalled(); $this->purgeIndexesFromChannel($ecommerce); }
/** * {@inheritdoc} */ public function getChannelCode() { return $this->channel->getCode(); }
/** * Returns conversion units * * @param ChannelInterface $channel * * @return string */ protected function normalizeConversionUnits(ChannelInterface $channel) { $result = []; foreach ($channel->getConversionUnits() as $family => $unit) { $result[] = sprintf('%s: %s', $family, $unit); } return implode(', ', $result); }
/** * {@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; }
/** * Remove indexes associated with the provided channel * * @param ChannelInterface $channel */ public function purgeIndexesFromChannel(ChannelInterface $channel) { $channelPattern = sprintf('/^%s\\..+-%s/', ProductQueryUtility::NORMALIZED_FIELD, $channel->getCode()); $indexesToRemove = $this->getIndexesMatching($channelPattern); $this->removeIndexes($indexesToRemove); }
/** * {@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; }