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');
 }
 /**
  * @param AttributeInterface $attribute
  * @param array              $data
  */
 protected function setAvailableLocales(AttributeInterface $attribute, array $data)
 {
     $localeSpecificCodes = $attribute->getLocaleSpecificCodes();
     foreach ($data as $localeCode) {
         if (!in_array($localeCode, $localeSpecificCodes)) {
             $locale = $this->localeRepository->findOneByIdentifier($localeCode);
             $attribute->addAvailableLocale($locale);
         }
     }
 }
 /**
  * Check the consistency of the field with channel associated
  *
  * @param AttributeInterface $attribute
  * @param string             $fieldName
  * @param array              $attributeInfo
  *
  * @throws \InvalidArgumentException
  */
 protected function checkFieldNameLocaleByChannel(AttributeInterface $attribute, $fieldName, array $attributeInfo)
 {
     if ($attribute->isScopable() && $attribute->isLocalizable() && isset($attributeInfo['scope_code']) && isset($attributeInfo['locale_code'])) {
         $channel = $this->channelRepository->findOneByIdentifier($attributeInfo['scope_code']);
         $locale = $this->localeRepository->findOneByIdentifier($attributeInfo['locale_code']);
         if ($channel !== null && $locale !== null && !$channel->hasLocale($locale)) {
             throw new \InvalidArgumentException(sprintf('The locale "%s" of the field "%s" is not available in scope "%s"', $attributeInfo['locale_code'], $fieldName, $attributeInfo['scope_code']));
         }
     }
 }
 /**
  * @param string $code
  * @param bool   $activeOnly
  *
  * @throws ObjectNotFoundException
  *
  * @return LocaleInterface
  */
 protected function getLocale($code, $activeOnly = true)
 {
     if (!array_key_exists($code, $this->locales)) {
         $locale = $this->localeRepository->findOneByIdentifier($code);
         if (!$locale) {
             throw new ObjectNotFoundException(sprintf('Locale with code "%s" was not found.', $code));
         }
         if ($activeOnly && !$locale->isActivated()) {
             throw new ObjectNotFoundException(sprintf('Active locale with code "%s" was not found.', $code));
         }
         $this->locales[$code] = $locale;
     }
     return $this->locales[$code];
 }
Exemplo n.º 5
0
 /**
  * Get locale by code
  *
  * @param string $code
  *
  * @return LocaleInterface
  */
 public function getLocaleByCode($code)
 {
     return $this->repository->findOneByIdentifier($code);
 }
Exemplo n.º 6
0
 /**
  * Returns the default application locale
  *
  * @return LocaleInterface|null
  */
 protected function getDefaultLocale()
 {
     return $this->localeRepository->findOneByIdentifier($this->defaultLocale);
 }