/** * Get all Pim locales for the given channel. * * @param string $channel * * @return array */ protected function getPimLocales($channel) { if (!$this->pimLocales) { $this->pimLocales = $this->channelManager->getChannelByCode($channel)->getLocales(); } return $this->pimLocales; }
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_returns_flat_data_without_media(ChannelInterface $channel, ChannelManager $channelManager, ProductInterface $product, Serializer $serializer) { $product->getValues()->willReturn([]); $serializer->normalize($product, 'flat', ['scopeCode' => 'foobar', 'localeCodes' => ''])->willReturn(['normalized_product']); $channelManager->getChannelByCode('foobar')->willReturn($channel); $this->setChannel('foobar'); $this->process($product)->shouldReturn(['media' => [], 'product' => ['normalized_product']]); }
/** * Displays completeness for a product * * @param int $id * * @return Response */ public function completenessAction($id) { $product = $this->productManager->getProductRepository()->getFullProduct($id); $channels = $this->channelManager->getFullChannels(); $locales = $this->userContext->getUserLocales(); $completenesses = $this->completenessManager->getProductCompleteness($product, $channels, $locales, $this->userContext->getCurrentLocale()->getCode()); return $this->templating->renderResponse('PimEnrichBundle:Completeness:_completeness.html.twig', array('product' => $product, 'channels' => $channels, 'locales' => $locales, 'completenesses' => $completenesses)); }
/** * {@inheritdoc} */ public function finishView(FormView $view, FormInterface $form, array $options) { $values = null !== $view->vars['value'] ? $view->vars['value']->getValues() : []; $view->vars['groups'] = $this->productFormView->getView(); $view->vars['orderedGroups'] = $this->getOrderedGroups($values); $view->vars['locales'] = $this->userContext->getUserLocales(); $view->vars['channels'] = $this->channelManager->getChannels(); $view->vars['currentLocale'] = $options['currentLocale']; }
/** * {@inheritdoc} */ public function validate($value, Constraint $constraint) { $channels = $this->manager->getChannelChoices(); if (0 === count($channels)) { throw new ConstraintDefinitionException('No channel is set in the application'); } $constraint->choices = array_keys($channels); parent::validate($value, $constraint); }
/** * {@inheritdoc} */ public function addFieldFilter($field, $operator, $value, $locale = null, $scope = null, $options = []) { $this->checkValue($field, $value, $locale, $scope); $channel = $this->channelManager->getChannelByCode($scope); foreach ($channel->getLocales() as $locale) { $field = sprintf("%s.%s.%s-%s", ProductQueryUtility::NORMALIZED_FIELD, 'completenesses', $scope, $locale); $value = intval($value); $this->qb->addOr($this->getExpr($value, $field, $operator)); } return $this; }
function it_throws_an_exception_if_no_file_is_found(ChannelInterface $channel, ProductInterface $product, ChannelManager $channelManager, Serializer $serializer, ProductValueInterface $productValue, AttributeInterface $attribute) { $product->getValues()->willReturn([$productValue]); $productValue->getAttribute()->willReturn($attribute); $attribute->getAttributeType()->willReturn('pim_catalog_image'); $product->getIdentifier()->willReturn($productValue); $productValue->getData()->willReturn('data'); $this->setChannel('foobar'); $channelManager->getChannelByCode('foobar')->willReturn($channel); $serializer->normalize(['data'], 'flat', ['field_name' => 'media', 'prepare_copy' => true])->willThrow('Symfony\\Component\\HttpFoundation\\File\\Exception\\FileNotFoundException'); $this->shouldThrow('Akeneo\\Bundle\\BatchBundle\\Item\\InvalidItemException')->during('process', [$product]); }
function it_returns_flat_data_without_media($productBuilder, ChannelInterface $channel, LocaleInterface $locale, ChannelManager $channelManager, ProductInterface $product, Serializer $serializer) { $localeCodes = ['en_US']; $channel->getLocales()->willReturn(new ArrayCollection([$locale])); $channel->getLocaleCodes()->willReturn($localeCodes); $productBuilder->addMissingProductValues($product, [$channel], [$locale])->shouldBeCalled(); $product->getValues()->willReturn([]); $this->setDecimalSeparator(','); $serializer->normalize($product, 'flat', ['scopeCode' => 'foobar', 'localeCodes' => $localeCodes, 'decimal_separator' => ',', 'date_format' => 'yyyy-MM-dd'])->willReturn(['normalized_product']); $channelManager->getChannelByCode('foobar')->willReturn($channel); $this->setChannel('foobar'); $this->process($product)->shouldReturn(['media' => [], 'product' => ['normalized_product']]); }
/** * Checks if the passed value is valid. * * @param AbstractProductProcessor $value The value that should be validated * @param Constraint $constraint The constraint for the validation * * @api */ public function validate($value, Constraint $constraint) { if (!$value instanceof AbstractProductProcessor) { return null; } if ($channel = $this->channelManager->getChannelByCode($value->getChannel())) { foreach ($channel->getLocales() as $locale) { if ($locale->getCode() === $value->getDefaultLocale()) { return null; } } } $this->context->addViolationAt('defaultLocale', $constraint->message, ['defaultLocale']); }
/** * Checks if the passed value is valid. * * @param mixed $value The value that should be validated * @param Constraint $constraint The constraint for the validation * * @api * @return null */ public function validate($value, Constraint $constraint) { if (!$value instanceof AbstractProductProcessor) { return null; } if ($channel = $this->channelManager->getChannelByCode($value->getChannel())) { foreach ($channel->getCurrencies() as $currency) { if ($currency->getCode() === $value->getCurrency()) { return null; } } } $this->context->addViolationAt('currency', $constraint->message, ['currency']); }
/** * Edit a family * * TODO : find a way to use param converter with interfaces * * @param Family $family * * @Template * @AclAncestor("pim_enrich_family_index") * * @return array */ public function editAction(Family $family) { if ($this->familyHandler->process($family)) { $this->addFlash('success', 'flash.family.updated'); } return ['form' => $this->familyForm->createView(), 'attributesForm' => $this->getAvailableAttributesForm($family->getAttributes()->toArray())->createView(), 'channels' => $this->channelManager->getChannels()]; }
/** * Get channel choices with user channel code first * * @return string[] */ public function getChannelChoicesWithUserChannel() { $channelChoices = $this->channelManager->getChannelChoices(); $userChannelCode = $this->getUserChannelCode(); if (array_key_exists($userChannelCode, $channelChoices)) { return [$userChannelCode => $channelChoices[$userChannelCode]] + $channelChoices; } return $channelChoices; }
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 it_returns_flat_data_without_media($productBuilder, ChannelInterface $channel, ChannelManager $channelManager, ProductInterface $product, Serializer $serializer) { $productBuilder->addMissingProductValues($product)->shouldBeCalled(); $this->setLocale('en_US'); $product->getValues()->willReturn([]); $serializer->normalize($product, 'flat', ['scopeCode' => 'mobile', 'localeCodes' => '', 'locale' => 'en_US'])->willReturn(['normalized_product']); $channelManager->getChannelByCode('mobile')->willReturn($channel); $this->setChannelCode('mobile'); $this->process($product)->shouldReturn(['media' => [], 'product' => ['normalized_product']]); }
/** * Return rows for available channels and theirs locales * * @param AbstractAttribute $attribute * * @return array */ protected function getScopeToLocaleRows(AbstractAttribute $attribute) { $channels = $this->channelManager->getChannels(); $scopeToLocaleRows = array(); foreach ($channels as $channel) { foreach ($channel->getLocales() as $locale) { $scopeToLocaleRows[] = array('attribute' => $attribute->getCode(), 'locale' => $locale->getCode(), 'scope' => $channel->getCode()); } } return $scopeToLocaleRows; }
/** * Edit a family * * @param int $id * * @Template * @AclAncestor("pim_enrich_family_index") * * @return array */ public function editAction($id) { $family = $this->familyRepository->find($id); if (null === $family) { throw new NotFoundHttpException(sprintf('%s entity not found', $this->familyClass)); } if ($this->familyHandler->process($family)) { $this->request->getSession()->getFlashBag()->add('success', new Message('flash.family.updated')); } return ['form' => $this->familyForm->createView(), 'attributesForm' => $this->getAvailableAttributesForm($family->getAttributes()->toArray())->createView(), 'channels' => $this->channelManager->getChannels()]; }
/** * {@inheritdoc} */ public function getCompleteProductsCountPerChannels() { $channels = $this->channelManager->getFullChannels(); $productRepo = $this->documentManager->getRepository($this->productClass); $productsCount = array(); foreach ($channels as $channel) { $category = $channel->getCategory(); $categoryQb = $this->categoryRepository->getAllChildrenQueryBuilder($category, true); $categoryIds = $this->categoryRepository->getCategoryIds($category, $categoryQb); foreach ($channel->getLocales() as $locale) { $data = array(); $compSuffix = $channel->getCode() . '-' . $locale->getCode(); $qb = $productRepo->createQueryBuilder()->hydrate(false)->field('categoryIds')->in($categoryIds)->field('enabled')->equals(true)->field('normalizedData.completenesses.' . $compSuffix)->equals(100)->select('_id'); $localeCount = $qb->getQuery()->execute()->count(); $data['locale'] = $locale->getCode(); $data['label'] = $channel->getLabel(); $data['total'] = $localeCount; $productsCount[] = $data; } } return $productsCount; }
/** * @{inheritdoc} */ public function read() { $product = null; if ($this->products->valid()) { $product = $this->products->current(); $this->stepExecution->incrementSummaryInfo('read'); $this->products->next(); } if (null !== $product) { $channel = $this->channelManager->getChannelByCode($this->channel); $this->metricConverter->convert($product, $channel); } return $product; }
/** * Get ids of products which are completes and in channel * * @return array */ protected function getIds() { if (!is_object($this->channel)) { $this->channel = $this->channelManager->getChannelByCode($this->channel); } if ($this->missingCompleteness) { $this->completenessManager->generateMissingForChannel($this->channel); } $this->query = $this->repository->buildByChannelAndCompleteness($this->channel); $rootAlias = current($this->query->getRootAliases()); $rootIdExpr = sprintf('%s.id', $rootAlias); $from = current($this->query->getDQLPart('from')); $this->query->select($rootIdExpr)->resetDQLPart('from')->from($from->getFrom(), $from->getAlias(), $rootIdExpr)->groupBy($rootIdExpr); $results = $this->query->getQuery()->getArrayResult(); return array_keys($results); }
/** * Get ids of products which are completes and in channel * * @return array */ protected function getIds() { if (!is_object($this->channel)) { $this->channel = $this->channelManager->getChannelByCode($this->channel); } if ($this->missingCompleteness) { $this->completenessManager->generateMissingForChannel($this->channel); } $this->query = $this->DnDBuildByChannelAndCompleteness($this->channel, $this->getIsComplete()); $rootAlias = current($this->query->getRootAliases()); $rootIdExpr = sprintf('%s.id', $rootAlias); $from = current($this->query->getDQLPart('from')); $this->query->select($rootIdExpr)->resetDQLPart('from')->from($from->getFrom(), $from->getAlias(), $rootIdExpr)->andWhere($this->query->expr()->orX($this->query->expr()->gte($from->getAlias() . '.updated', ':updated')))->setParameter('updated', $this->getDateFilter())->setParameter('enabled', $this->getIsEnabled())->groupBy($rootIdExpr); $results = $this->query->getQuery()->getArrayResult(); return array_keys($results); }
/** * Generate a list of potential completeness value from existing channel * or from the provided channel * * @param Channel $channel * * @return array */ protected function getChannelLocaleCombinations(Channel $channel = null) { $channels = array(); $combinations = array(); if (null !== $channel) { $channels = [$channel]; } else { $channels = $this->channelManager->getFullChannels(); } foreach ($channels as $channel) { $locales = $channel->getLocales(); foreach ($locales as $locale) { $combinations[] = $channel->getCode() . '-' . $locale->getCode(); } } return $combinations; }
/** * @param ChannelManager $channelManager */ public function __construct(ChannelManager $channelManager) { $this->channels = $channelManager->getChannels(); }
function it_returns_flat_data_without_media($dateformatProvider, $numberFormatProvider, ChannelInterface $channel, ChannelManager $channelManager, ProductInterface $product, Serializer $serializer) { $dateformatProvider->getFormat('en_US')->willReturn('n/j/y'); $numberFormatProvider->getFormat('en_US')->willReturn(['decimal_separator' => '.']); $this->configureOptions('en_US'); $product->getValues()->willReturn([]); $serializer->normalize($product, 'flat', ['scopeCode' => 'mobile', 'localeCodes' => '', 'decimal_separator' => '.', 'date_format' => 'n/j/y'])->willReturn(['normalized_product']); $channelManager->getChannelByCode('mobile')->willReturn($channel); $this->setChannelCode('mobile'); $this->process($product)->shouldReturn(['media' => [], 'product' => ['normalized_product']]); }
/** * {@inheritdoc} */ public function getConfigurationFields() { return array_merge(parent::getConfigurationFields(), ['channel' => ['type' => 'choice', 'options' => ['choices' => $this->channelManager->getChannelChoices(), 'required' => true, 'help' => 'pim_prestashop_connector.export.channel.help', 'label' => 'pim_prestashop_connector.export.channel.label']], 'enabled' => ['type' => 'switch', 'options' => ['required' => true, 'help' => 'pim_prestashop_connector.export.enabled.help', 'label' => 'pim_prestashop_connector.export.enabled.label']], 'visibility' => ['type' => 'text', 'options' => ['required' => true, 'help' => 'pim_prestashop_connector.export.visibility.help', 'label' => 'pim_prestashop_connector.export.visibility.label']], 'variantMemberVisibility' => ['type' => 'text', 'options' => ['required' => true, 'help' => 'pim_prestashop_connector.export.variant_member_visibility.help', 'label' => 'pim_prestashop_connector.export.variant_member_visibility.label']], 'currency' => ['type' => 'choice', 'options' => ['choices' => $this->currencyManager->getCurrencyChoices(), 'required' => true, 'help' => 'pim_prestashop_connector.export.currency.help', 'label' => 'pim_prestashop_connector.export.currency.label', 'attr' => ['class' => 'select2']]], 'smallImageAttribute' => ['type' => 'choice', 'options' => ['choices' => $this->attributeManager->getImageAttributeChoice(), 'help' => 'pim_prestashop_connector.export.smallImageAttribute.help', 'label' => 'pim_prestashop_connector.export.smallImageAttribute.label', 'attr' => ['class' => 'select2']]], 'baseImageAttribute' => ['type' => 'choice', 'options' => ['choices' => $this->attributeManager->getImageAttributeChoice(), 'help' => 'pim_prestashop_connector.export.baseImageAttribute.help', 'label' => 'pim_prestashop_connector.export.baseImageAttribute.label', 'attr' => ['class' => 'select2']]], 'thumbnailAttribute' => ['type' => 'choice', 'options' => ['choices' => $this->attributeManager->getImageAttributeChoice(), 'help' => 'pim_prestashop_connector.export.thumbnailAttribute.help', 'label' => 'pim_prestashop_connector.export.thumbnailAttribute.label', 'attr' => ['class' => 'select2']]], 'urlKey' => ['type' => 'checkbox', 'options' => ['help' => 'pim_prestashop_connector.export.urlKey.help', 'label' => 'pim_prestashop_connector.export.urlKey.label']], 'skuFirst' => ['type' => 'checkbox', 'options' => ['help' => 'pim_prestashop_connector.export.skuFirst.help', 'label' => 'pim_prestashop_connector.export.skuFirst.label']]], $this->categoryMappingMerger->getConfigurationField(), $this->attributeMappingMerger->getConfigurationField()); }
/** * {@inheritdoc} */ public function getConfigurationFields() { return array_merge(parent::getConfigurationFields(), ['channel' => ['type' => 'choice', 'options' => ['choices' => $this->channelManager->getChannelChoices(), 'required' => true, 'help' => 'pim_magento_connector.export.channel.help', 'label' => 'pim_magento_connector.export.channel.label']], 'enabled' => ['type' => 'switch', 'options' => ['required' => true, 'help' => 'pim_magento_connector.export.enabled.help', 'label' => 'pim_magento_connector.export.enabled.label']], 'visibility' => ['type' => 'text', 'options' => ['required' => true, 'help' => 'pim_magento_connector.export.visibility.help', 'label' => 'pim_magento_connector.export.visibility.label']], 'currency' => ['type' => 'choice', 'options' => ['choices' => $this->currencyManager->getCurrencyChoices(), 'required' => true, 'help' => 'pim_magento_connector.export.currency.help', 'label' => 'pim_magento_connector.export.currency.label', 'attr' => ['class' => 'select2']]]], $this->categoryMappingMerger->getConfigurationField(), $this->attributeMappingMerger->getConfigurationField()); }
/** * Get the PIM channels * * @return \Pim\Bundle\CatalogBundle\Entity\Channel[] */ protected function getChannels() { return $this->channelManager->getChannels(); }
/** * Get locale codes for a channel * * @param string $channelCode * * @return array */ protected function getLocaleCodes($channelCode) { $channel = $this->channelManager->getChannelByCode($channelCode); return $channel->getLocaleCodes(); }
/** * {@inheritdoc} */ public function getConfigurationFields() { return array_merge(parent::getConfigurationFields(), array('channel' => array('type' => 'choice', 'options' => array('choices' => $this->channelManager->getChannelChoices(), 'required' => true, 'select2' => true, 'label' => 'pim_base_connector.export.channel.label', 'help' => 'pim_base_connector.export.channel.help')))); }
/** * Get fields for the twig * * @return array */ public function getConfigurationFields() { return array_merge(parent::getConfigurationFields(), ['channel' => ['type' => 'choice', 'options' => ['choices' => $this->channelManager->getChannelChoices(), 'required' => true, 'help' => 'actualys_drupal_commerce_connector.export.channel.help', 'label' => 'actualys_drupal_commerce_connector.export.channel.label']]]); }