Esempio n. 1
0
 /**
  * Return option array
  *
  * @return array
  */
 public function toOptionArray()
 {
     $languages = array();
     foreach ($this->_helper->getLanguageCodes() as $languageCode) {
         $localeCode = $this->_helper->convertLanguageCodeToLocaleCode($languageCode);
         $translationForSpecifiedLanguage = $this->_locale->getTranslation($localeCode, 'language', $languageCode);
         $translationForDefaultLanguage = $this->_locale->getTranslation($localeCode, 'language');
         $label = sprintf('%s / %s (%s)', $this->_uppercaseFilter->filter($translationForSpecifiedLanguage), $translationForDefaultLanguage, $languageCode);
         $languages[] = array('value' => $languageCode, 'label' => $label);
     }
     return $languages;
 }
Esempio n. 2
0
 /**
  * Retrieve currencies array
  * Return array: code => currency name
  * Return empty array if only one currency
  *
  * @return array
  */
 public function getCurrencies()
 {
     $currencies = $this->getData('currencies');
     if (is_null($currencies)) {
         $currencies = [];
         $codes = $this->_storeManager->getStore()->getAvailableCurrencyCodes(true);
         if (is_array($codes) && count($codes) > 1) {
             $rates = $this->_currencyFactory->create()->getCurrencyRates($this->_storeManager->getStore()->getBaseCurrency(), $codes);
             foreach ($codes as $code) {
                 if (isset($rates[$code])) {
                     $currencies[$code] = $this->_locale->getTranslation($code, 'nametocurrency');
                 }
             }
         }
         $this->setData('currencies', $currencies);
     }
     return $currencies;
 }
Esempio n. 3
0
 /**
  * Returns currency symbol properties array based on config values
  *
  * @return array
  */
 public function getCurrencySymbolsData()
 {
     if ($this->_symbolsData) {
         return $this->_symbolsData;
     }
     $this->_symbolsData = array();
     $allowedCurrencies = explode(self::ALLOWED_CURRENCIES_CONFIG_SEPARATOR, $this->_scopeConfig->getValue(self::XML_PATH_ALLOWED_CURRENCIES, \Magento\Store\Model\ScopeInterface::SCOPE_STORE, null));
     /* @var $storeModel \Magento\Store\Model\System\Store */
     $storeModel = $this->_systemStore;
     foreach ($storeModel->getWebsiteCollection() as $website) {
         $websiteShow = false;
         foreach ($storeModel->getGroupCollection() as $group) {
             if ($group->getWebsiteId() != $website->getId()) {
                 continue;
             }
             foreach ($storeModel->getStoreCollection() as $store) {
                 if ($store->getGroupId() != $group->getId()) {
                     continue;
                 }
                 if (!$websiteShow) {
                     $websiteShow = true;
                     $websiteSymbols = $website->getConfig(self::XML_PATH_ALLOWED_CURRENCIES);
                     $allowedCurrencies = array_merge($allowedCurrencies, explode(self::ALLOWED_CURRENCIES_CONFIG_SEPARATOR, $websiteSymbols));
                 }
                 $storeSymbols = $this->_scopeConfig->getValue(self::XML_PATH_ALLOWED_CURRENCIES, \Magento\Store\Model\ScopeInterface::SCOPE_STORE, $store);
                 $allowedCurrencies = array_merge($allowedCurrencies, explode(self::ALLOWED_CURRENCIES_CONFIG_SEPARATOR, $storeSymbols));
             }
         }
     }
     ksort($allowedCurrencies);
     $currentSymbols = $this->_unserializeStoreConfig(self::XML_PATH_CUSTOM_CURRENCY_SYMBOL);
     foreach ($allowedCurrencies as $code) {
         if (!($symbol = $this->_locale->getTranslation($code, 'currencysymbol'))) {
             $symbol = $code;
         }
         $name = $this->_locale->getTranslation($code, 'nametocurrency');
         if (!$name) {
             $name = $code;
         }
         $this->_symbolsData[$code] = array('parentSymbol' => $symbol, 'displayName' => $name);
         if (isset($currentSymbols[$code]) && !empty($currentSymbols[$code])) {
             $this->_symbolsData[$code]['displaySymbol'] = $currentSymbols[$code];
         } else {
             $this->_symbolsData[$code]['displaySymbol'] = $this->_symbolsData[$code]['parentSymbol'];
         }
         if ($this->_symbolsData[$code]['parentSymbol'] == $this->_symbolsData[$code]['displaySymbol']) {
             $this->_symbolsData[$code]['inherited'] = true;
         } else {
             $this->_symbolsData[$code]['inherited'] = false;
         }
     }
     return $this->_symbolsData;
 }