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_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 it_provides_active_locales_codes($repository, LocaleInterface $fr, LocaleInterface $be)
 {
     $fr->getCode()->willReturn('fr_FR');
     $be->getCode()->willReturn('fr_BE');
     $repository->getActivatedLocales()->willReturn([$fr, $be]);
     $this->getActiveCodes()->shouldReturn(['fr_FR', 'fr_BE']);
 }
 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_locales($localeHelper, LocaleInterface $en)
 {
     $en->getCode()->willReturn('en_US');
     $localeHelper->getLocaleLabel('en_US')->willReturn('English (America)');
     $localeHelper->getDisplayRegion('en_US')->willReturn('America');
     $localeHelper->getDisplayLanguage('en_US')->willReturn('English');
     $this->normalize($en, 'internal_api')->shouldReturn(['code' => 'en_US', 'label' => 'English (America)', 'region' => 'America', 'language' => 'English']);
 }
 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 let(ProductBuilder $productBuilder, ProductUpdaterInterface $productUpdater, UserContext $userContext, LocaleInterface $en, LocaleInterface $de, ProductValueInterface $productValue, CatalogContext $catalogContext, ProductMassActionManager $massActionManager, NormalizerInterface $normalizer, BulkSaverInterface $productSaver)
 {
     $en->getCode()->willReturn('en_US');
     $de->getCode()->willReturn('de_DE');
     $userContext->getCurrentLocale()->willReturn($en);
     $userContext->getUserLocales()->willReturn([$en, $de]);
     $catalogContext->setLocaleCode(Argument::any())->willReturn($catalogContext);
     $productValue->setAttribute(Argument::any())->willReturn($productValue);
     $productValue->setLocale(Argument::any())->willReturn($productValue);
     $productValue->setScope(Argument::any())->willReturn($productValue);
     $productValue->addPrice(Argument::any())->willReturn($productValue);
     $this->beConstructedWith($productBuilder, $productUpdater, $userContext, $catalogContext, $massActionManager, $normalizer, $productSaver, ['product_price' => 'Pim\\Bundle\\CatalogBundle\\Model\\ProductPrice', 'product_media' => 'Pim\\Bundle\\CatalogBundle\\Model\\ProductMedia']);
 }
 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 let(SecurityContextInterface $securityContext, LocaleManager $localeManager, ChannelManager $channelManager, CategoryManager $categoryManager, TokenInterface $token, User $user, LocaleInterface $en, LocaleInterface $fr, LocaleInterface $de, ChannelInterface $ecommerce, ChannelInterface $mobile, CategoryInterface $firstTree, CategoryInterface $secondTree)
 {
     $securityContext->getToken()->willReturn($token);
     $token->getUser()->willReturn($user);
     $en->getCode()->willReturn('en_US');
     $fr->getCode()->willReturn('fr_FR');
     $de->getCode()->willReturn('de_DE');
     $en->isActivated()->willReturn(true);
     $fr->isActivated()->willReturn(true);
     $de->isActivated()->willReturn(true);
     $localeManager->getLocaleByCode('en_US')->willReturn($en);
     $localeManager->getLocaleByCode('fr_FR')->willReturn($fr);
     $localeManager->getLocaleByCode('de_DE')->willReturn($de);
     $localeManager->getActiveLocales()->willReturn([$en, $fr, $de]);
     $channelManager->getChannels()->willReturn([$mobile, $ecommerce]);
     $categoryManager->getTrees()->willReturn([$firstTree, $secondTree]);
     $this->beConstructedWith($securityContext, $localeManager, $channelManager, $categoryManager, 'en_US');
 }
 function let(TokenStorageInterface $tokenStorage, LocaleRepositoryInterface $localeRepository, ChannelRepositoryInterface $channelRepository, TokenInterface $token, User $user, LocaleInterface $en, LocaleInterface $fr, LocaleInterface $de, ChannelInterface $ecommerce, ChannelInterface $mobile, CategoryInterface $firstTree, CategoryInterface $secondTree, CategoryRepositoryInterface $productCategoryRepo, RequestStack $requestStack, ChoicesBuilderInterface $choicesBuilder)
 {
     $tokenStorage->getToken()->willReturn($token);
     $token->getUser()->willReturn($user);
     $en->getCode()->willReturn('en_US');
     $fr->getCode()->willReturn('fr_FR');
     $de->getCode()->willReturn('de_DE');
     $en->isActivated()->willReturn(true);
     $fr->isActivated()->willReturn(true);
     $de->isActivated()->willReturn(true);
     $localeRepository->findOneByIdentifier('en_US')->willReturn($en);
     $localeRepository->findOneByIdentifier('fr_FR')->willReturn($fr);
     $localeRepository->findOneByIdentifier('de_DE')->willReturn($de);
     $localeRepository->getActivatedLocales()->willReturn([$en, $fr, $de]);
     $channelRepository->findOneBy([])->willReturn($mobile);
     $productCategoryRepo->getTrees()->willReturn([$firstTree, $secondTree]);
     $this->beConstructedWith($tokenStorage, $localeRepository, $channelRepository, $productCategoryRepo, $requestStack, $choicesBuilder, 'en_US');
 }
 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);
 }
 /**
  * {@inheritdoc}
  */
 public function hasLocaleSpecific(LocaleInterface $locale)
 {
     return in_array($locale->getCode(), $this->getLocaleSpecificCodes());
 }
 function it_gets_all_product_attributes_and_sets_correct_locale($attributeRepository, $massActionManager, AttributeInterface $attr1, AttributeInterface $attr2, AttributeGroupInterface $attrGroup, LocaleInterface $enLocale)
 {
     $enLocale->getCode()->willReturn('en_US');
     $this->setLocale($enLocale);
     $attributeRepository->findWithGroups([], ['conditions' => ['unique' => 0]])->shouldBeCalled()->willReturn([$attr1, $attr2]);
     $attr1->setLocale('en_US')->shouldBeCalled();
     $attr2->setLocale('en_US')->shouldBeCalled();
     $attr1->getGroup()->willReturn($attrGroup);
     $attr2->getGroup()->willReturn($attrGroup);
     $massActionManager->filterLocaleSpecificAttributes([$attr1, $attr2], 'en_US')->willReturn([$attr1, $attr2]);
     $attrGroup->setLocale('en_US')->shouldBeCalledTimes(2);
     $this->getAllAttributes()->shouldReturn([$attr1, $attr2]);
 }
 function it_removes_obsolete_localizable_indexes_when_locale_is_disabled($collection, LocaleInterface $en_US)
 {
     $en_US->getCode()->willReturn('en_US');
     $en_US->isActivated()->willReturn(false);
     $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.cost-en_US.USD.data" => 1]], ["key" => ["normalizedData.color-ecommerce-en_US.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_left-en_US')->shouldBeCalled();
     $collection->deleteIndex('normalizedData.cost-en_US.USD.data')->shouldBeCalled();
     $collection->deleteIndex('normalizedData.color-ecommerce-en_US.id')->shouldBeCalled();
     $collection->deleteIndex('normalizedData.completenesses-ecommerce-en_US')->shouldBeCalled();
     $this->purgeIndexesFromLocale($en_US);
 }
 /**
  * {@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();
 }
 /**
  * Add all the values required by the given attribute
  *
  * @param AttributeInterface $attribute
  * @param LocaleInterface    $locale
  */
 protected function addValues(AttributeInterface $attribute, $locale)
 {
     if ($attribute->isScopable()) {
         foreach ($locale->getChannels() as $channel) {
             $key = $attribute->getCode() . '_' . $channel->getCode();
             $value = $this->productBuilder->createProductValue($attribute, $locale->getCode(), $channel->getCode());
             $this->productBuilder->addMissingPrices($value);
             $this->values[$key] = $value;
         }
     } else {
         $value = $this->productBuilder->createProductValue($attribute, $locale->getCode());
         $this->productBuilder->addMissingPrices($value);
         $this->values[$attribute->getCode()] = $value;
     }
 }
 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();
 }
 function let(UserContext $userContext, LocaleRepositoryInterface $localeRepository, LocaleInterface $en)
 {
     $en->getCode()->willReturn('en_US');
     $userContext->getCurrentLocale()->willReturn($en);
     $this->beConstructedWith($userContext, $localeRepository);
 }
Пример #19
0
 /**
  * Remove indexes associated with the provided locale
  *
  * @param LocaleInterface $locale
  */
 public function purgeIndexesFromLocale(LocaleInterface $locale)
 {
     $localePattern = sprintf('/^%s\\..+-%s/', ProductQueryUtility::NORMALIZED_FIELD, $locale->getCode());
     $indexesToRemove = $this->getIndexesMatching($localePattern);
     $this->removeIndexes($indexesToRemove);
 }