/** * 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; }
/** * {@inheritdoc} */ public function getQuery() { if (!$this->query) { $channel = $this->channelManager->getChannelByCode($this->channel); $this->query = $this->repository->findOrderedCategories($channel->getCategory())->getQuery(); } return $this->query; }
/** * {@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; }
/** * 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']); }
/** * {@inheritdoc} */ public function read() { $this->documentManager->clear(); if (!$this->executed) { $this->executed = true; 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)->getQuery(); $this->products = $this->getQuery()->execute(); // MongoDB Cursor are not positioned on first element (whereas ArrayIterator is) // as long as getNext() hasn't be called $this->products->getNext(); } $result = $this->products->current(); if ($result) { $this->metricConverter->convert($result, $this->channel); $this->stepExecution->incrementSummaryInfo('read'); $this->products->next(); } return $result; }
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']]); }
/** * {@inheritdoc} */ public function read() { if (!$this->query) { $code = $this->channel; if (!is_object($this->channel)) { $this->channel = $this->channelManager->getChannelByCode($this->channel); } if (!$this->channel) { throw new \InvalidArgumentException(sprintf('Could not find the channel "%s"', $code)); } $this->completenessManager->generateMissingForChannel($this->channel); $this->query = $this->repository->buildByChannelAndCompleteness($this->channel)->getQuery(); } $product = parent::read(); if ($product) { $this->metricConverter->convert($product, $this->channel); } return $product; }
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']]); }
/** * @{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->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); }
/** * 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); }
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']]); }
/** * Get locale codes for a channel * * @param string $channelCode * * @return array */ protected function getLocaleCodes($channelCode) { $channel = $this->channelManager->getChannelByCode($channelCode); return $channel->getLocaleCodes(); }
/** * @param mixed $product * @return array|mixed * @throws InvalidItemException */ public function process($product) { /** @var Channel $channel */ $channel = $this->channelManager->getChannelByCode($this->channel); return $this->normalizeProduct($product, $channel); }
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']]); }
/** * Get channel font color * * @param string $code * * @return string */ public function channelFontColor($code) { $channel = $this->channelManager->getChannelByCode($code); return $channel ? $this->colorsProvider->getFontColor($channel->getColor()) : ''; }