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']); }
/** * Pre remove * * @param GenericEvent $event */ public function checkChannelLink(GenericEvent $event) { $object = $event->getSubject(); if (!$object instanceof CurrencyInterface) { return; } if (!$object->isActivated() && 0 < $this->channelRepository->getChannelCountUsingCurrency($object)) { throw new LinkedChannelException('You cannot disable a currency linked to a channel.'); } }
/** * {@inheritdoc} */ public function initialize() { $this->channels = $this->channelRepository->findAll(); foreach ($this->attributeRepository->getNonIdentifierAttributes() as $attribute) { $this->attributes[(string) $attribute->getGroup()][] = $attribute; foreach ($this->channels as $channel) { $this->addAttributeRequirement($this->factory->createAttributeRequirement($attribute, $channel, false)); } } }
/** * Get completeness for a product * * @param int $id * * @return JSONResponse */ public function getAction($id) { $product = $this->productRepository->getFullProduct($id); $this->completenessManager->generateMissingForProduct($product); $channels = $this->channelRepository->getFullChannels(); $locales = $this->userContext->getUserLocales(); $filteredLocales = $this->collectionFilter->filterCollection($locales, 'pim.internal_api.locale.view'); $completenesses = $this->completenessManager->getProductCompleteness($product, $channels, $filteredLocales, $this->userContext->getCurrentLocale()->getCode()); return new JsonResponse($this->completenessNormalizer->normalize($completenesses, 'internal_api')); }
/** * @param FamilyInterface $family * * @return string[] */ protected function getMissingChannelCodes(FamilyInterface $family) { $requirements = $family->getAttributeRequirements(); $identifierCode = $this->attributeRepository->getIdentifierCode(); $currentChannelCodes = []; foreach ($requirements as $requirement) { if ($requirement->getAttributeCode() === $identifierCode) { $currentChannelCodes[] = $requirement->getChannelCode(); } } $expectedChannelCodes = $this->channelRepository->getChannelCodes(); $missingChannelCodes = array_diff($expectedChannelCodes, $currentChannelCodes); return $missingChannelCodes; }
/** * @return ChannelInterface[] */ protected function getChannels() { if (null === $this->channels) { $this->channels = $this->channelRepository->findAll(); } return $this->channels; }
/** * {@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 AttributeInterface $attribute * @param string $channelCode * * @throws \InvalidArgumentException * * @return AttributeRequirementInterface */ protected function createAttributeRequirement(AttributeInterface $attribute, $channelCode) { $channel = $this->channelRepository->findOneByIdentifier($channelCode); if (null === $channel) { throw new \InvalidArgumentException(sprintf('Channel with "%s" code does not exist', $channelCode)); } return $this->attrRequiFactory->createAttributeRequirement($attribute, $channel, true); }
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_initializes_attribute_requirements_with_all_channels_and_attributes_in_the_PIM(ChannelRepositoryInterface $channelRepository, ChannelInterface $ecommerceChannel, ChannelInterface $mobileChannel, AttributeRepositoryInterface $attributeRepository, AttributeInterface $nameAttribute, AttributeInterface $descriptionAttribute, AttributeRequirementFactory $factory, AttributeRequirementInterface $nameECommerceRequirement, AttributeRequirementInterface $nameMobileRequirement, AttributeRequirementInterface $descriptionECommerceRequirement, AttributeRequirementInterface $descriptionMobileRequirement) { $channelRepository->findAll()->willReturn([$ecommerceChannel, $mobileChannel]); $attributeRepository->getNonIdentifierAttributes()->willReturn([$nameAttribute, $descriptionAttribute]); $factory->createAttributeRequirement($nameAttribute, $ecommerceChannel, false)->willReturn($nameECommerceRequirement); $nameECommerceRequirement->getAttributeCode()->willReturn('name'); $nameECommerceRequirement->getChannelCode()->willReturn('ecommerce'); $factory->createAttributeRequirement($nameAttribute, $mobileChannel, false)->willReturn($nameMobileRequirement); $nameMobileRequirement->getAttributeCode()->willReturn('name'); $nameMobileRequirement->getChannelCode()->willReturn('mobile'); $factory->createAttributeRequirement($descriptionAttribute, $ecommerceChannel, false)->willReturn($descriptionECommerceRequirement); $descriptionECommerceRequirement->getAttributeCode()->willReturn('description'); $descriptionECommerceRequirement->getChannelCode()->willReturn('ecommerce'); $factory->createAttributeRequirement($descriptionAttribute, $mobileChannel, false)->willReturn($descriptionMobileRequirement); $descriptionMobileRequirement->getAttributeCode()->willReturn('description'); $descriptionMobileRequirement->getChannelCode()->willReturn('mobile'); $this->initialize(); $this->getAttributeRequirements()->toArray()->shouldReturn(['name_ecommerce' => $nameECommerceRequirement, 'name_mobile' => $nameMobileRequirement, 'description_ecommerce' => $descriptionECommerceRequirement, 'description_mobile' => $descriptionMobileRequirement]); }
/** * 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'])); } } }
/** * Get channel choices with user channel code first * * @return string[] */ public function getChannelChoicesWithUserChannel() { $channels = $this->channelRepository->findAll(); $channelChoices = $this->choicesBuilder->buildChoices($channels); $userChannelCode = $this->getUserChannelCode(); if (array_key_exists($userChannelCode, $channelChoices)) { return [$userChannelCode => $channelChoices[$userChannelCode]] + $channelChoices; } return $channelChoices; }
/** * Schedule recalculation of completenesses for all products * of a channel * * @param ChannelInterface $channel */ public function scheduleForChannel(ChannelInterface $channel) { if ($channel->getId()) { $deletedLocaleIds = $this->channelRepository->getDeletedLocaleIdsForChannel($channel); foreach ($deletedLocaleIds as $deletedLocaleId) { $deletedLocale = $this->localeRepository->find($deletedLocaleId); $this->generator->scheduleForChannelAndLocale($channel, $deletedLocale); } } }
function it_initializes_attribute_requirements_with_all_channels_and_attributes_in_the_PIM(ChannelRepositoryInterface $channelRepository, ChannelInterface $ecommerce, ChannelInterface $mobile, AttributeRepositoryInterface $attributeRepository, AttributeInterface $name, AttributeInterface $description, AttributeRequirementFactory $factory, AttributeRequirementInterface $r1, AttributeRequirementInterface $r2, AttributeRequirementInterface $r3, AttributeRequirementInterface $r4) { $channelRepository->findAll()->willReturn([$ecommerce, $mobile]); $attributeRepository->getNonIdentifierAttributes()->willReturn([$name, $description]); $factory->createAttributeRequirement($name, $ecommerce, false)->willReturn($r1); $r1->getAttributeCode()->willReturn('name'); $r1->getChannelCode()->willReturn('ecommerce'); $factory->createAttributeRequirement($name, $mobile, false)->willReturn($r2); $r2->getAttributeCode()->willReturn('name'); $r2->getChannelCode()->willReturn('mobile'); $factory->createAttributeRequirement($description, $ecommerce, false)->willReturn($r3); $r3->getAttributeCode()->willReturn('description'); $r3->getChannelCode()->willReturn('ecommerce'); $factory->createAttributeRequirement($description, $mobile, false)->willReturn($r4); $r4->getAttributeCode()->willReturn('description'); $r4->getChannelCode()->willReturn('mobile'); $this->initialize(); $this->getAttributeRequirements()->toArray()->shouldReturn(['name_ecommerce' => $r1, 'name_mobile' => $r2, 'description_ecommerce' => $r3, 'description_mobile' => $r4]); }
/** * Get all channels * * @return array */ protected function getChannels() { if (null === $this->channels) { $this->channels = []; $channels = $this->channelRepository->findAll(); foreach ($channels as $channel) { $this->channels[$channel->getCode()] = $channel; } } return $this->channels; }
/** * @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; }
/** * Generate a list of potential completeness value from existing channel * or from the provided channel * * @param ChannelInterface $channel * * @return array */ protected function getChannelLocaleCombinations(ChannelInterface $channel = null) { $channels = []; $combinations = []; if (null !== $channel) { $channels = [$channel]; } else { $channels = $this->channelRepository->getFullChannels(); } foreach ($channels as $channel) { $locales = $channel->getLocales(); foreach ($locales as $locale) { $combinations[] = $channel->getCode() . '-' . $locale->getCode(); } } return $combinations; }
/** * @param FamilyInterface $family * @param array $data */ protected function setAttributeRequirements(FamilyInterface $family, array $data) { $requirements = []; foreach ($data as $channelCode => $attributeCodes) { foreach ($attributeCodes as $attributeCode) { if (null !== ($attribute = $this->attributeRepository->findOneByIdentifier($attributeCode))) { if (null !== ($channel = $this->channelRepository->findOneByIdentifier($channelCode))) { $requirements[] = $this->attrRequiFactory->createAttributeRequirement($attribute, $channel, true); } else { throw new \InvalidArgumentException(sprintf('Channel with "%s" code does not exist', $channelCode)); } } else { throw new \InvalidArgumentException(sprintf('Attribute with "%s" code does not exist', $attributeCode)); } } } $family->setAttributeRequirements($requirements); }
/** * @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; }
/** * Checks that attributes in the header have existing locale, scope and currency. * * @throws \LogicException */ protected function checkAttributesInHeader() { $channels = $this->channelRepository->getChannelCodes(); $locales = $this->localeRepository->getActivatedLocaleCodes(); $currencies = $this->currencyRepository->getActivatedCurrencyCodes(); foreach ($this->fieldNames as $fieldName) { if (null !== ($info = $this->fieldExtractor->extractColumnInfo($fieldName))) { $locale = $info['locale_code']; $channel = $info['scope_code']; $currency = isset($info['price_currency']) ? $info['price_currency'] : null; if (null !== $locale && !in_array($locale, $locales)) { throw new \LogicException(sprintf('Locale %s does not exist.', $locale)); } if (null !== $channel && !in_array($channel, $channels)) { throw new \LogicException(sprintf('Channel %s does not exist.', $channel)); } if (null !== $currency && !in_array($currency, $currencies)) { throw new \LogicException(sprintf('Currency %s does not exist.', $currency)); } } } }
/** * @return array */ protected function getScopeCodes() { return $this->scopeRepository->getChannelCodes(); }
/** * {@inheritdoc} */ public function collect() { return ['nb_channels' => $this->channelRepository->countAll(), 'nb_products' => $this->productRepository->countAll(), 'nb_attributes' => $this->attributeRepository->countAll(), 'nb_locales' => $this->localeRepository->countAllActivated(), 'nb_families' => $this->familyRepository->countAll(), 'nb_users' => $this->userRepository->countAll()]; }
/** * Get channel by code * * @param string $code * * @return ChannelInterface */ public function getChannelByCode($code) { return $this->channelRepository->findOneBy(['code' => $code]); }
/** * @return JsonResponse */ public function indexAction() { $channels = $this->channelRepository->findAll(); $normalizedChannels = $this->normalizer->normalize($channels, 'json'); return new JsonResponse($normalizedChannels); }