/** * @param ProductInterface $product * * @return array */ protected function getLabels(ProductInterface $product) { $labels = []; foreach ($this->localeRepository->getActivatedLocaleCodes() as $localeCode) { $labels[$localeCode] = $product->getLabel($localeCode); } return ['label' => $labels]; }
/** * {@inheritdoc} */ public function getDefaultValues() { $parameters = $this->simpleProvider->getDefaultValues(); $parameters['decimalSeparator'] = LocalizerInterface::DEFAULT_DECIMAL_SEPARATOR; $parameters['dateFormat'] = LocalizerInterface::DEFAULT_DATE_FORMAT; $parameters['with_media'] = true; $parameters['filePath'] = sys_get_temp_dir() . 'csv_products_export.csv'; $defaultChannel = $this->channelRepository->getFullChannels()[0]; $defaultLocaleCode = $this->localeRepository->getActivatedLocaleCodes()[0]; $parameters['filters'] = ['data' => [['field' => 'enabled', 'operator' => OPERATORS::EQUALS, 'value' => true], ['field' => 'completeness', 'operator' => OPERATORS::GREATER_OR_EQUAL_THAN, 'value' => 100], ['field' => 'categories.code', 'operator' => OPERATORS::IN_CHILDREN_LIST, 'value' => []]], 'structure' => ['scope' => $defaultChannel->getCode(), 'locales' => [$defaultLocaleCode]]]; return $parameters; }
/** * Create locales field * * @param FormBuilderInterface $builder * * @return ChannelType */ protected function addLocalesField(FormBuilderInterface $builder) { $builder->add('locales', 'entity', ['required' => true, 'multiple' => true, 'select2' => true, 'by_reference' => false, 'class' => 'Pim\\Bundle\\CatalogBundle\\Entity\\Locale', 'query_builder' => function (LocaleRepositoryInterface $repository) { return $repository->getLocalesQB(); }, 'preferred_choices' => $this->localeRepository->getActivatedLocaleCodes()]); return $this; }
/** * Prepare attributes list for CSV headers * * @param array $attributesList * * @return array */ protected function prepareAttributesList(array $attributesList) { $scopeCode = $this->catalogContext->getScopeCode(); $localeCodes = $this->localeRepository->getActivatedLocaleCodes(); $fieldsList = []; foreach ($attributesList as $attribute) { $attCode = $attribute->getCode(); if ($attribute->isLocalizable() && $attribute->isScopable()) { foreach ($localeCodes as $localeCode) { $fieldsList[] = sprintf('%s-%s-%s', $attCode, $localeCode, $scopeCode); } } elseif ($attribute->isLocalizable()) { foreach ($localeCodes as $localeCode) { $fieldsList[] = sprintf('%s-%s', $attCode, $localeCode); } } elseif ($attribute->isScopable()) { $fieldsList[] = sprintf('%s-%s', $attCode, $scopeCode); } elseif (AttributeTypes::IDENTIFIER === $attribute->getAttributeType()) { array_unshift($fieldsList, $attCode); } elseif (AttributeTypes::PRICE_COLLECTION === $attribute->getAttributeType()) { foreach ($this->currencyManager->getActiveCodes() as $currencyCode) { $fieldsList[] = sprintf('%s-%s', $attCode, $currencyCode); } } else { $fieldsList[] = $attCode; } } return $fieldsList; }
/** * Edit attribute form * * @param int $id * * @Template("PimEnrichBundle:Attribute:form.html.twig") * @AclAncestor("pim_enrich_attribute_edit") * * @return array */ public function editAction(Request $request, $id) { $attribute = $this->findAttributeOr404($id); if ($this->attributeHandler->process($attribute)) { $request->getSession()->getFlashBag()->add('success', new Message('flash.attribute.updated')); } return ['form' => $this->attributeForm->createView(), 'locales' => $this->localeRepository->getActivatedLocaleCodes(), 'disabledLocales' => $this->localeRepository->findBy(['activated' => false]), 'measures' => $this->measuresConfig, 'created' => $this->versionManager->getOldestLogEntry($attribute), 'updated' => $this->versionManager->getNewestLogEntry($attribute)]; }
/** * Edit attribute form * * @param Request $request * @param int $id * * @Template("PimEnrichBundle:Attribute:form.html.twig") * @AclAncestor("pim_enrich_attribute_edit") * * @return array */ public function editAction(Request $request, $id) { $attribute = $this->findAttributeOr404($id); if ($this->attributeHandler->process($attribute)) { $this->addFlash('success', 'flash.attribute.updated'); return $this->redirectToRoute('pim_enrich_attribute_edit', ['id' => $attribute->getId()]); } return ['form' => $this->attributeForm->createView(), 'locales' => $this->localeRepository->getActivatedLocaleCodes(), 'disabledLocales' => $this->localeRepository->findBy(['activated' => false]), 'measures' => $this->measuresConfig, 'created' => $this->versionManager->getOldestLogEntry($attribute), 'updated' => $this->versionManager->getNewestLogEntry($attribute)]; }
function it_provides_default_values($decoratedProvider, ChannelRepositoryInterface $channelRepository, LocaleRepositoryInterface $localeRepository, LocaleInterface $locale, ChannelInterface $channel) { $channel->getCode()->willReturn('channel_code'); $channelRepository->getFullChannels()->willReturn([$channel]); $locale->getCode()->willReturn('locale_code'); $localeRepository->getActivatedLocaleCodes()->willReturn([$locale]); $decoratedProvider->getDefaultValues()->willReturn(['decoratedParam' => true]); $this->getDefaultValues()->shouldReturnWellFormedDefaultValues(); }
/** * Get activated locales as choices * * @return string[] */ public function getActivatedLocaleChoices() { $translateIn = $this->getCurrentLocaleCode(); $activeCodes = $this->localeRepository->getActivatedLocaleCodes(); $results = []; foreach ($activeCodes as $activeCode) { $results[$activeCode] = $this->getLocaleLabel($activeCode, $translateIn); } return $results; }
/** * @param array $item * @param array $authorizedFields * * @throws ArrayConversionException */ protected function validateAuthorizedFields(array $item, array $authorizedFields) { $localeCodes = $this->localeRepository->getActivatedLocaleCodes(); foreach ($localeCodes as $code) { $authorizedFields[] = 'label-' . $code; } foreach ($item as $field => $data) { if (!in_array($field, $authorizedFields) && !$this->isAttribute($field)) { throw new ArrayConversionException(sprintf('Field "%s" is provided, authorized fields are: "%s"', $field, implode(', ', $authorizedFields))); } } }
/** * @param array $item * * @throws ArrayConversionException */ protected function validate(array $item) { $requiredFields = ['attribute', 'code']; $this->validator->validateFields($item, $requiredFields, false); $authorizedFields = array_merge($requiredFields, ['sort_order']); $localeCodes = $this->localeRepository->getActivatedLocaleCodes(); foreach ($localeCodes as $code) { $authorizedFields[] = 'label-' . $code; } foreach ($item as $field => $data) { if (!in_array($field, $authorizedFields)) { throw new ArrayConversionException(sprintf('Field "%s" is provided, authorized fields are: "%s"', $field, implode(', ', $authorizedFields))); } } }
/** * 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 getActivatedLocaleCodes() { return $this->localeRepository->getActivatedLocaleCodes(); }
/** * {@inheritdoc} */ public function configureOptions(OptionsResolver $resolver) { $locales = $this->localeRepository->getActivatedLocaleCodes(); $resolver->setDefaults(['choices' => array_combine($locales, $locales), 'required' => true, 'select2' => true, 'multiple' => true, 'label' => 'pim_connector.export.locales.label', 'help' => 'pim_connector.export.locales.help', 'attr' => ['data-tab' => 'content']]); }