function let(DocumentManager $manager, Channel $ecommerce, Channel $mobile, Locale $enUs, Locale $frFr, CategoryInterface $category, ChannelManager $channelManager, CategoryRepository $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_all_locales_from_database_as_sources(Locale $locale, $localeManager, $hasValidCredentialsValidator, $clientParameters) { $hasValidCredentialsValidator->areValidSoapCredentials($clientParameters)->willReturn(true); $localeManager->getActiveCodes()->willReturn(['foo']); $locale->getCode()->willReturn('foo'); $this->getAllSources()->shouldReturn([['id' => 'foo', 'text' => 'foo']]); }
function it_provides_active_locales_codes($repository, Locale $fr, Locale $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(ChannelManager $channelManager, MediaManager $mediaManager, ProductValueNormalizer $productValueNormalizer, CategoryMappingManager $categoryMappingManager, AssociationTypeManager $associationTypeManager, MappingCollection $storeViewMapping, MappingCollection $categoryMapping, MappingCollection $attributeMapping, Product $product, ProductValue $productValue, ProductValue $imageValue, Channel $channel, Locale $localeFR, Locale $localeEN, Category $category) { $this->beConstructedWith($channelManager, $mediaManager, $productValueNormalizer, $categoryMappingManager, $associationTypeManager, 1, 4, 'currency', 'magento_url'); $this->globalContext = ['attributeSetId' => 0, 'magentoAttributes' => [], 'magentoAttributesOptions' => [], 'storeViewMapping' => $storeViewMapping, 'magentoStoreViews' => [['code' => 'fr_fr']], 'defaultLocale' => 'default_locale', 'website' => 'website', 'channel' => 'channel', 'categoryMapping' => $categoryMapping, 'attributeCodeMapping' => $attributeMapping, 'create' => true, 'pimGrouped' => 'pim_grouped', 'created_date' => new \DateTime(), 'updated_date' => new \DateTime(), 'defaultStoreView' => 'default', 'smallImageAttribute' => 'small_image_attribute', 'baseImageAttribute' => 'image_attribute', 'thumbnailAttribute' => 'image_attribute']; $attributeMapping->getTarget('visibility')->willReturn('visibility'); $attributeMapping->getTarget('created_at')->willReturn('created_at'); $attributeMapping->getTarget('updated_at')->willReturn('updated_at'); $attributeMapping->getTarget('status')->willReturn('status'); $attributeMapping->getTarget('categories')->willReturn('categories'); $channelManager->getChannelByCode('channel')->willReturn($channel); $channel->getLocales()->willReturn([$localeEN, $localeFR]); $localeEN->getCode()->willReturn('default_locale'); $localeFR->getCode()->willReturn('fr_FR'); $channel->getCode()->willReturn('channel_code'); $channel->getCategory()->willReturn($category); $product->getCategories()->willReturn([$category]); $product->getIdentifier()->willReturn('sku-000'); $product->getCreated()->willReturn($this->globalContext['created_date']); $product->getUpdated()->willReturn($this->globalContext['updated_date']); $product->getValues()->willReturn(new ArrayCollection([$productValue, $imageValue])); $storeViewMapping->getTarget('default_locale')->willReturn('default_locale'); $storeViewMapping->getTarget('fr_FR')->willReturn('fr_fr'); $categoryMappingManager->getIdFromCategory($category, 'magento_url', $categoryMapping)->willReturn(2); $productValueNormalizer->normalize($productValue, Argument::cetera())->willReturn(['value' => 'productValueNormalized']); $productValueNormalizer->normalize($imageValue, Argument::cetera())->willReturn(null); }
function it_normalizes_completeness(Completeness $completeness, Channel $channel, Locale $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]); }
/** * @param AttributeInterface $attribute * @param array $data */ protected function addAvailableLocales(AttributeInterface $attribute, $data) { if (strtolower($data['available_locales']) !== 'all') { $locales = explode(',', $data['available_locales']); foreach ($locales as $localeCode) { $locale = new Locale(); $locale->setCode($localeCode); $attribute->addAvailableLocale($locale); } } }
function it_fails_if_the_locale_is_not_valid($context, $channelManager, AbstractProductProcessor $value, HasValidDefaultLocale $constraint, Channel $channel, Locale $locale) { $value->getChannel()->willReturn('channel'); $channelManager->getChannelByCode(Argument::any())->willReturn($channel); $channel->getLocales()->willReturn([$locale]); $locale->getCode()->willReturn('fr_FR'); $value->getDefaultLocale()->willReturn('us_US'); $constraint->message = 'The given default locale is not valid (check that the selected locale is in channel\'s locales)'; $context->addViolationAt('defaultLocale', 'The given default locale is not valid (check that the selected locale is in channel\'s locales)', ['defaultLocale'])->shouldBeCalled(); $this->validate($value, $constraint); }
/** * {@inheritdoc} */ public function load(ObjectManager $manager) { $bundle = new \ReflectionClass('Pim\\Bundle\\InstallerBundle\\PimInstallerBundle'); $locales = array_map('trim', file(sprintf('%s/Resources/config/locales', dirname($bundle->getFileName())))); foreach ($locales as $localeCode) { $locale = new Locale(); $locale->setCode($localeCode); $this->setReference(get_class($locale) . '.' . $localeCode, $locale); $this->validate($locale, $localeCode); $manager->persist($locale); } $manager->flush(); }
function it_doesnt_remove_value_when_the_attribute_is_locale_specific_and_current_locale_is_in_available_list(FormEvent $event, FormInterface $form, FormInterface $field, FormInterface $rootForm, ProductValueInterface $taxValue, AttributeInterface $taxAttribute) { $event->getForm()->willReturn($form); $event->getData()->willReturn(['tax' => $taxValue]); $taxValue->getAttribute()->willReturn($taxAttribute); $fr = new Locale(); $fr->setCode('fr_FR'); $en = new Locale(); $en->setCode('en_US'); $taxAttribute->isLocaleSpecific()->willReturn(true); $taxAttribute->getLocaleSpecificCodes()->willReturn(['fr_FR', 'en_US']); $form->remove('tax')->shouldNotBeCalled(); $this->preSetData($event); }
function let(ProductManager $productManager, UserContext $userContext, CurrencyManager $currencyManager, Locale $en, Locale $de, AttributeRepository $attributeRepository, AbstractProductValue $productValue, CatalogContext $catalogContext, ProductBuilder $productBuilder, ProductMassActionManager $massActionManager, MetricFactory $metricFactory) { $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); $productManager->createProductValue()->willReturn($productValue); $productValue->setAttribute(Argument::any())->willReturn($productValue); $productValue->setLocale(Argument::any())->willReturn($productValue); $productValue->setScope(Argument::any())->willReturn($productValue); $productValue->addPrice(Argument::any())->willReturn($productValue); $productManager->getAttributeRepository()->willReturn($attributeRepository); $this->beConstructedWith($productManager, $userContext, $currencyManager, $catalogContext, $productBuilder, $massActionManager, $metricFactory, ['product_price' => 'Pim\\Bundle\\CatalogBundle\\Model\\ProductPrice', 'product_media' => 'Pim\\Bundle\\CatalogBundle\\Model\\ProductMedia']); }
function let(ChannelManager $channelManager, ProductNormalizer $productNormalizer, PriceMappingManager $priceMappingManager, MappingCollection $categoryMapping, MappingCollection $attributeMapping, MappingCollection $storeViewMapping, ProductInterface $product, Channel $channel, Locale $localeFR, Locale $localeEN, Group $group) { $this->beConstructedWith($channelManager, $productNormalizer, $priceMappingManager, $attributeMapping); $this->globalContext = ['attributeSetId' => 0, 'magentoAttributes' => [], 'magentoAttributesOptions' => [], 'storeViewMapping' => $storeViewMapping, 'magentoStoreViews' => [['code' => 'fr_fr']], 'defaultLocale' => 'default_locale', 'website' => 'website', 'channel' => 'channel', 'categoryMapping' => $categoryMapping, 'attributeCodeMapping' => $attributeMapping, 'create' => true, 'defaultStoreView' => 'default']; $productNormalizer->getNormalizedImages($product, 'conf-group_code')->willReturn([]); $productNormalizer->getValues(Argument::cetera())->willReturn([]); $channelManager->getChannelByCode('channel')->willReturn($channel); $channel->getLocales()->willReturn([$localeEN, $localeFR]); $localeEN->getCode()->willReturn('default_locale'); $localeFR->getCode()->willReturn('fr_FR'); $channel->getCode()->willReturn('channel_code'); $storeViewMapping->getTarget('default_locale')->willReturn('default_locale'); $storeViewMapping->getTarget('fr_FR')->willReturn('fr_fr'); $group->getCode()->willReturn('group_code'); $product->getIdentifier()->willReturn('sku-000'); }
function let(SecurityContextInterface $securityContext, LocaleManager $localeManager, ChannelManager $channelManager, CategoryManager $categoryManager, TokenInterface $token, User $user, Locale $en, Locale $fr, Locale $de, Channel $ecommerce, Channel $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(ChannelManager $channelManager, ProductNormalizer $productNormalizer, PriceMappingManager $priceMappingManager, MappingCollection $categoryMapping, MappingCollection $attributeMapping, MappingCollection $storeViewMapping, ProductInterface $product, Channel $channel, Locale $localeFR, Locale $localeEN, Group $group, Attribute $attribute) { $this->beConstructedWith($channelManager, $productNormalizer, $priceMappingManager, 4); $this->globalContext = ['attributeSetId' => 0, 'magentoAttributes' => ['attribute_code' => ['attribute_id' => 42]], 'magentoAttributesOptions' => [], 'storeViewMapping' => $storeViewMapping, 'magentoStoreViews' => [['code' => 'fr_fr']], 'defaultLocale' => 'default_locale', 'website' => 'website', 'channel' => 'channel', 'categoryMapping' => $categoryMapping, 'attributeCodeMapping' => $attributeMapping, 'create' => true, 'defaultStoreView' => 'default', 'smallImageAttribute' => 'smallImageAttr', 'baseImageAttribute' => 'baseImageAttr', 'thumbnailAttribute' => 'thumbnailAttr', 'pimGrouped' => 'grouped_product_code', 'urlKey' => false, 'skuFirst' => false]; $productNormalizer->getNormalizedImages($product, 'conf-group_code', 'smallImageAttr', 'baseImageAttr', 'thumbnailAttr')->willReturn([]); $productNormalizer->getValues(Argument::cetera())->willReturn([ProductNormalizer::URL_KEY => 'my-url-key']); $channelManager->getChannelByCode('channel')->willReturn($channel); $channel->getLocales()->willReturn([$localeEN, $localeFR]); $localeEN->getCode()->willReturn('default_locale'); $localeFR->getCode()->willReturn('fr_FR'); $channel->getCode()->willReturn('channel_code'); $storeViewMapping->getTarget('default_locale')->willReturn('default_locale'); $storeViewMapping->getTarget('fr_FR')->willReturn('fr_fr'); $group->getId()->willReturn(44); $group->getCode()->willReturn('group_code'); $product->getIdentifier()->willReturn('sku-000'); $attribute->setCode('attribute_code'); $group->getAttributes()->willReturn([$attribute]); $attribute->getCode()->willReturn('attribute_code'); $attributeMapping->getTarget('attribute_code')->willReturn('attribute_code'); }
/** * Test activate/deactivate locale and chech isActivated method */ public function testActivateDeactivate() { $this->assertFalse($this->locale->isActivated()); $channel = new Channel(); $this->assertEntity($this->locale->addChannel($channel)); $this->assertTrue($this->locale->isActivated()); $this->assertEntity($this->locale->removeChannel($channel)); $this->assertFalse($this->locale->isActivated()); }
function it_generates_localizable_indexes_when_saving_enabled_locale($collection, $namingUtility, AbstractAttribute $description, Locale $en_US, Locale $de_DE, Channel $ecommerce) { $description->getCode()->willReturn('description'); $description->getBackendType()->willReturn('varchar'); $description->isLocalizable()->willReturn(true); $description->isScopable()->willReturn(false); $description->isUseableAsGridFilter()->willReturn(true); $description->getAttributeType()->willReturn('pim_catalog_text'); $en_US->getCode()->willReturn('en_US'); $en_US->isActivated()->willReturn(true); $de_DE->getCode()->willReturn('de_DE'); $de_DE->isActivated()->willReturn(true); $ecommerce->getCode()->willReturn('ecommerce'); $ecommerce->getLocales()->willReturn([$en_US, $de_DE]); $namingUtility->getChannels()->willReturn([$ecommerce]); $namingUtility->getLocalizableAttributes()->willReturn([$description]); $namingUtility->getAttributeNormFields($description)->willReturn(['normalizedData.description-en_US', 'normalizedData.description-de_DE']); $options = ['background' => true, 'w' => 0]; $collection->ensureIndex(['normalizedData.completenesses.ecommerce-en_US' => 1], $options)->shouldBeCalled(); $collection->ensureIndex(['normalizedData.completenesses.ecommerce-de_DE' => 1], $options)->shouldBeCalled(); $collection->ensureIndex(['normalizedData.description-en_US' => 1], $options)->shouldBeCalled(); $collection->ensureIndex(['normalizedData.description-de_DE' => 1], $options)->shouldBeCalled(); $this->ensureIndexesFromLocale($en_US); }
function it_removes_obsolete_localizable_indexes_when_locale_is_disabled($collection, Locale $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 getReference() { $this->__initializer__ && $this->__initializer__->__invoke($this, 'getReference', array()); return parent::getReference(); }
/** * Create a locale for testing * * @param string $code * * @return \Pim\Bundle\CatalogBundle\Tests\Unit\Entity\Locale */ protected function createLocale($code) { $locale = new Locale(); $locale->setCode($code); return $locale; }
function it_removes_indexes_for_locale_when_disabling_it($indexPurger, Locale $en_US, LifecycleEventArgs $args) { $en_US->isActivated()->willReturn(false); $args->getEntity()->willReturn($en_US); $indexPurger->purgeIndexesFromLocale($en_US)->shouldBeCalled(); $this->postUpdate($args); }
/** * Manage not found locales. * * @param Locale $locale * * @throws LocaleNotMatchedException */ protected function localeNotFound(Locale $locale) { throw new LocaleNotMatchedException(sprintf('No storeview found for the locale "%s". Please map the locale "%s" to a Prestashop storeview', $locale->getCode(), $locale->getCode())); }
/** * Remove indexes associated with the provided locale * * @param Locale $locale */ public function purgeIndexesFromLocale(Locale $locale) { $localePattern = sprintf('/^%s\\..+-%s/', ProductQueryUtility::NORMALIZED_FIELD, $locale->getCode()); $indexesToRemove = $this->getIndexesMatching($localePattern); $this->removeIndexes($indexesToRemove); }
/** * @return array */ protected function getLocales() { $localeEn = new Locale(); $localeEn->setCode('en_US'); $localeFr = new Locale(); $localeFr->setCode('fr_FR'); return array($localeEn, $localeFr); }
/** * @param AttributeInterface $attribute * @param array $data */ protected function addAvailableLocales(AttributeInterface $attribute, $data) { foreach ($data['available_locales'] as $code) { $locale = new Locale(); $locale->setCode($code); $attribute->addAvailableLocale($locale); } }
/** * {@inheritdoc} */ public function scheduleForChannelAndLocale(Channel $channel, Locale $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(); }
/** * Checks if a locale is activated * * @param Locale $locale * * @return boolean */ protected function isLocaleAvailable(Locale $locale) { return $locale->isActivated(); }
/** * Manage not found locales. * * @param Locale $locale * * @throws LocaleNotMatchedException */ protected function localeNotFound(Locale $locale) { throw new LocaleNotMatchedException(sprintf('No storeview found for "%s" locale. Please create a storeview named "%s" on your Magento or map ' . 'this locale to a storeview code. You can also disable this locale in your channel\'s settings if you ' . 'don\'t want to export it.', $locale->getCode(), $locale->getCode())); }
function let(UserContext $userContext, LocaleManager $localeManager, Locale $en) { $en->getCode()->willReturn('en_US'); $userContext->getCurrentLocale()->willReturn($en); $this->beConstructedWith($userContext, $localeManager); }
/** * {@inheritdoc} */ public function scheduleForChannelAndLocale(Channel $channel, Locale $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(); }