Esempio n. 1
0
 /**
  * Render country grid column
  *
  * @param   \Magento\Framework\DataObject $row
  * @return  string
  */
 public function render(\Magento\Framework\DataObject $row)
 {
     if ($data = $row->getData($this->getColumn()->getIndex())) {
         $name = $this->localeLists->getCountryTranslation($data);
         if (empty($name)) {
             $name = $this->escapeHtml($data);
         }
         return $name;
     }
     return null;
 }
Esempio n. 2
0
 /**
  * Convert collection items to select options array
  *
  * @param string|boolean $emptyLabel
  * @return array
  */
 public function toOptionArray($emptyLabel = ' ')
 {
     $options = $this->_toOptionArray('country_id', 'name', ['title' => 'iso2_code']);
     $sort = [];
     foreach ($options as $data) {
         $name = (string) $this->_localeLists->getCountryTranslation($data['value']);
         if (!empty($name)) {
             $sort[$name] = $data['value'];
         }
     }
     $this->_arrayUtils->ksortMultibyte($sort, $this->_localeResolver->getLocale());
     foreach (array_reverse($this->_foregroundCountries) as $foregroundCountry) {
         $name = array_search($foregroundCountry, $sort);
         unset($sort[$name]);
         $sort = [$name => $foregroundCountry] + $sort;
     }
     $options = [];
     foreach ($sort as $label => $value) {
         $option = ['value' => $value, 'label' => $label];
         if ($this->helperData->isRegionRequired($value)) {
             $option['is_region_required'] = true;
         }
         $options[] = $option;
     }
     if (count($options) > 0 && $emptyLabel !== false) {
         array_unshift($options, ['value' => '', 'label' => $emptyLabel]);
     }
     return $options;
 }
Esempio n. 3
0
 /**
  * Convert collection items to select options array
  *
  * @param string|boolean $emptyLabel
  * @return array
  */
 public function toOptionArray($emptyLabel = ' ')
 {
     $options = $this->_toOptionArray('country_id', 'name', array('title' => 'iso2_code'));
     $sort = array();
     foreach ($options as $data) {
         $name = (string) $this->_localeLists->getCountryTranslation($data['value']);
         if (!empty($name)) {
             $sort[$name] = $data['value'];
         }
     }
     $this->_arrayUtils->ksortMultibyte($sort, $this->_localeResolver->getLocaleCode());
     foreach (array_reverse($this->_foregroundCountries) as $foregroundCountry) {
         $name = array_search($foregroundCountry, $sort);
         unset($sort[$name]);
         $sort = array($name => $foregroundCountry) + $sort;
     }
     $options = array();
     foreach ($sort as $label => $value) {
         $options[] = array('value' => $value, 'label' => $label);
     }
     if (count($options) > 0 && $emptyLabel !== false) {
         array_unshift($options, array('value' => '', 'label' => $emptyLabel));
     }
     return $options;
 }
Esempio n. 4
0
 /**
  * Get country name
  *
  * @return string
  */
 public function getName()
 {
     if (!$this->getData('name')) {
         $this->setData('name', $this->_localeLists->getCountryTranslation($this->getId()));
     }
     return $this->getData('name');
 }
Esempio n. 5
0
 /**
  * Get country name
  *
  * @return string
  */
 public function getName($locale = null)
 {
     if ($locale == null) {
         $cache_key = 'name_default';
     } else {
         $cache_key = 'name_' . $locale;
     }
     if (!$this->getData($cache_key)) {
         $this->setData($cache_key, $this->_localeLists->getCountryTranslation($this->getId(), $locale));
     }
     return $this->getData($cache_key);
 }