/**
  * {@inheritdoc}
  */
 public function process($family)
 {
     $actions = $this->getConfiguredActions();
     foreach ($actions as $action) {
         $attribute = $this->attributeRepository->findOneByIdentifier($action['attribute_code']);
         $channel = $this->channelRepository->findOneByIdentifier($action['channel_code']);
         $isRequired = $action['is_required'];
         $family->addAttribute($attribute);
         $family->addAttributeRequirement($this->factory->createAttributeRequirement($attribute, $channel, $isRequired));
     }
     return $family;
 }
 /**
  * {@inheritdoc}
  */
 public function process($family)
 {
     $configuration = $this->getJobConfiguration();
     if (!array_key_exists('actions', $configuration)) {
         throw new InvalidArgumentException('Missing configuration for \'actions\'.');
     }
     $actions = $configuration['actions'];
     foreach ($actions as $action) {
         $attribute = $this->attributeRepository->findOneByIdentifier($action['attribute_code']);
         $channel = $this->channelRepository->findOneByIdentifier($action['channel_code']);
         $isRequired = $action['is_required'];
         $family->addAttribute($attribute);
         $family->addAttributeRequirement($this->factory->createAttributeRequirement($attribute, $channel, $isRequired));
     }
     return $family;
 }
 /**
  * @param string $code
  *
  * @return ChannelInterface
  */
 protected function getChannel($code)
 {
     if (!array_key_exists($code, $this->channels)) {
         $this->channels[$code] = $this->channelRepository->findOneByIdentifier($code);
     }
     return $this->channels[$code];
 }
 /**
  * @param string $code
  *
  * @throws ObjectNotFoundException
  *
  * @return ChannelInterface
  */
 protected function getChannelByCode($code)
 {
     $channel = $this->channelRepository->findOneByIdentifier($code);
     if (null === $channel) {
         throw new ObjectNotFoundException(sprintf('Channel with "%s" code does not exist', $code));
     }
     return $channel;
 }
 /**
  * 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']));
         }
     }
 }
 /**
  * {@inheritdoc}
  */
 public function validate($value, Constraint $constraint)
 {
     if (null === $value['scope'] || null === $value['locales']) {
         return;
     }
     $filterStructureScope = $value['scope'];
     $filterStructureLocales = $value['locales'];
     $scope = $this->channelRepository->findOneByIdentifier($filterStructureScope);
     $localesCodes = [];
     if (null !== $scope) {
         $localesCodes = $scope->getLocaleCodes();
     }
     $errorCount = 0;
     foreach ($filterStructureLocales as $localeCode) {
         if (!in_array($localeCode, $localesCodes)) {
             $this->context->buildViolation($constraint->message)->setParameter('%localeCode%', $localeCode)->atPath(sprintf('[locales][%d]', $errorCount))->addViolation();
             $errorCount++;
         }
     }
 }
Ejemplo n.º 7
0
 /**
  * @param FamilyInterface    $family
  * @param AttributeInterface $attribute
  * @param string             $channelCode
  *
  * @return AttributeRequirementInterface
  */
 protected function createAttributeRequirement(FamilyInterface $family, AttributeInterface $attribute, $channelCode)
 {
     $channel = $this->channelRepository->findOneByIdentifier($channelCode);
     if (null === $channel) {
         throw new \InvalidArgumentException(sprintf('Channel with "%s" code does not exist', $channelCode));
     }
     $requirement = $this->requirementRepo->findOneBy(['attribute' => $attribute->getId(), 'channel' => $channel->getId(), 'family' => $family->getId()]);
     if (null === $requirement) {
         $requirement = $this->attrRequiFactory->createAttributeRequirement($attribute, $channel, true);
     }
     return $requirement;
 }
Ejemplo n.º 8
0
 /**
  * Returns the configured channel from the parameters.
  * If no channel is specified, returns null.
  *
  * @throws ObjectNotFoundException
  *
  * @return ChannelInterface|null
  */
 protected function getConfiguredChannel()
 {
     $parameters = $this->stepExecution->getJobParameters();
     if (!isset($parameters->get('filters')['structure']['scope'])) {
         return null;
     }
     $channelCode = $parameters->get('filters')['structure']['scope'];
     $channel = $this->channelRepository->findOneByIdentifier($channelCode);
     if (null === $channel) {
         throw new ObjectNotFoundException(sprintf('Channel with "%s" code does not exist', $channelCode));
     }
     return $channel;
 }
Ejemplo n.º 9
0
 /**
  * {@inheritdoc}
  */
 public function process($product)
 {
     $parameters = $this->stepExecution->getJobParameters();
     $structure = $parameters->get('filters')['structure'];
     $channel = $this->channelRepository->findOneByIdentifier($structure['scope']);
     $this->productBuilder->addMissingProductValues($product, [$channel], $channel->getLocales()->toArray());
     $productStandard = $this->normalizer->normalize($product, 'json', ['channels' => [$channel->getCode()], 'locales' => array_intersect($channel->getLocaleCodes(), $parameters->get('filters')['structure']['locales'])]);
     if ($this->areAttributesToFilter($parameters)) {
         $attributesToFilter = $this->getAttributesToFilter($parameters);
         $productStandard['values'] = $this->filterValues($productStandard['values'], $attributesToFilter);
     }
     if ($parameters->has('with_media') && $parameters->get('with_media')) {
         $directory = $this->stepExecution->getJobExecution()->getExecutionContext()->get(JobInterface::WORKING_DIRECTORY_PARAMETER);
         $this->fetchMedia($product, $directory);
     } else {
         $mediaAttributes = $this->attributeRepository->findMediaAttributeCodes();
         $productStandard['values'] = array_filter($productStandard['values'], function ($attributeCode) use($mediaAttributes) {
             return !in_array($attributeCode, $mediaAttributes);
         }, ARRAY_FILTER_USE_KEY);
     }
     $this->detacher->detach($product);
     return $productStandard;
 }
Ejemplo n.º 10
0
 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->findOneByIdentifier([])->willReturn($mobile);
     $productCategoryRepo->getTrees()->willReturn([$firstTree, $secondTree]);
     $this->beConstructedWith($tokenStorage, $localeRepository, $channelRepository, $productCategoryRepo, $requestStack, $choicesBuilder, 'en_US');
 }
 /**
  * @param AttributeInterface $attribute
  * @param array              $values
  *
  * @throws ObjectNotFoundException
  *
  * @return array
  */
 protected function getNewValuesData(AttributeInterface $attribute, array $values)
 {
     $newValues = [];
     foreach ($values as $value) {
         $acceptValue = true;
         if (null !== $value['locale']) {
             $isAuthorizedOnLocale = !$this->objectFilter->filterObject($this->getLocale($value['locale']), 'pim.internal_api.locale.edit');
             $isEditableOnLocale = $attribute->isLocaleSpecific() ? in_array($value['locale'], $attribute->getLocaleSpecificCodes()) : true;
             $acceptValue = $isAuthorizedOnLocale && $isEditableOnLocale;
         }
         if ($attribute->isScopable() && $acceptValue) {
             $channel = $this->channelRepository->findOneByIdentifier($value['scope']);
             if (null === $channel) {
                 $acceptValue = false;
             }
         }
         if ($acceptValue) {
             $newValues[] = $value;
         }
     }
     return $newValues;
 }
Ejemplo n.º 12
0
 /**
  * Get locale codes for a channel
  *
  * @param string $channelCode
  *
  * @return array
  */
 protected function getLocaleCodes($channelCode)
 {
     $channel = $this->channelRepository->findOneByIdentifier($channelCode);
     return $channel->getLocaleCodes();
 }