/**
  * @return array
  */
 public function resolveAttributeColumns()
 {
     if (empty($this->attributesFields)) {
         $attributes = $this->attributeRepository->findAll();
         $currencyCodes = $this->currencyRepository->getActivatedCurrencyCodes();
         $values = $this->valuesResolver->resolveEligibleValues($attributes);
         foreach ($values as $value) {
             if (null !== $value['locale'] && null !== $value['scope']) {
                 $field = sprintf('%s-%s-%s', $value['attribute'], $value['locale'], $value['scope']);
             } elseif (null !== $value['locale']) {
                 $field = sprintf('%s-%s', $value['attribute'], $value['locale']);
             } elseif (null !== $value['scope']) {
                 $field = sprintf('%s-%s', $value['attribute'], $value['scope']);
             } else {
                 $field = $value['attribute'];
             }
             if (AttributeTypes::PRICE_COLLECTION === $value['type']) {
                 $this->attributesFields[] = $field;
                 foreach ($currencyCodes as $currencyCode) {
                     $currencyField = sprintf('%s-%s', $field, $currencyCode);
                     $this->attributesFields[] = $currencyField;
                 }
             } elseif (AttributeTypes::METRIC === $value['type']) {
                 $this->attributesFields[] = $field;
                 $metricField = sprintf('%s-%s', $field, 'unit');
                 $this->attributesFields[] = $metricField;
             } else {
                 $this->attributesFields[] = $field;
             }
         }
     }
     return $this->attributesFields;
 }
 /**
  * @return JsonResponse
  */
 public function indexAction()
 {
     $currencies = $this->currencyRepository->getActivatedCurrencies();
     $normalizedCurrencies = [];
     foreach ($currencies as $currency) {
         $normalizedCurrencies[$currency->getCode()] = ['code' => $currency->getCode()];
     }
     return new JsonResponse($normalizedCurrencies);
 }
 /**
  * Get active currencies
  *
  * @return array
  */
 protected function getCurrencies()
 {
     if (null === $this->currencies) {
         $this->currencies = [];
         $currencies = $this->currencyRepository->findBy(['activated' => 1]);
         foreach ($currencies as $currency) {
             $this->currencies[$currency->getCode()] = $currency;
         }
     }
     return $this->currencies;
 }
 /**
  * {@inheritdoc}
  */
 public function addMissingPrices(ProductValueInterface $value)
 {
     $activeCurrencyCodes = $this->currencyRepository->getActivatedCurrencyCodes();
     if (AttributeTypes::PRICE_COLLECTION === $value->getAttribute()->getAttributeType()) {
         $prices = $value->getPrices();
         foreach ($activeCurrencyCodes as $currencyCode) {
             if (null === $value->getPrice($currencyCode)) {
                 $this->addPriceForCurrency($value, $currencyCode);
             }
         }
         foreach ($prices as $price) {
             if (!in_array($price->getCurrency(), $activeCurrencyCodes)) {
                 $value->removePrice($price);
             }
         }
     }
     return $value;
 }
 /**
  * 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));
             }
         }
     }
 }
 /**
  * Get active codes
  *
  * @deprecated CurrencyRepositoryInterface::getActivatedCurrencyCodes must be used
  *
  * @return string[]
  */
 public function getActiveCodes()
 {
     return $this->repository->getActivatedCurrencyCodes();
 }