public function createcountriesAction()
 {
     $language = $this->_getParam("language");
     $locale = new Zend_Locale($language);
     $regions = Zend_Locale::getTranslationList('RegionToTerritory');
     $countryGroup = array();
     foreach ($regions as $region => $countriesString) {
         $countries = explode(' ', $countriesString);
         foreach ($countries as $country) {
             $countryGroup[$country] = $locale->getTranslation($region, 'territory', $locale);
         }
     }
     $countries = Country::getCountries();
     foreach ($countries as $iso => $name) {
         $currencyCode = Country::getCurrencyCodeForCountry($iso);
         $currencyDetail = Country::getCurrencyDetail($currencyCode);
         if (!$currencyCode || !$currencyDetail) {
             continue;
         }
         $currencyName = $currencyDetail['name'];
         $currencySymbol = $currencyDetail['symbol'];
         $currencyIsoNumber = $currencyDetail['isocode'];
         //Check if currency Object already exists
         $currencyObject = Model\Currency::getByName($currencyName);
         if (!$currencyObject instanceof Model\Currency) {
             $currencyObject = new Model\Currency();
             $currencyObject->setSymbol($currencySymbol);
             $currencyObject->setNumericIsoCode($currencyIsoNumber);
             $currencyObject->setIsoCode($currencyCode);
             $currencyObject->setExchangeRate(1);
         }
         $currencyObject->setName($currencyName);
         $currencyObject->save();
         //Check if country Object already exists
         $countryObject = Model\Country::getByIsoCode($iso);
         if (!$countryObject instanceof Model\Country) {
             $countryObject = new Model\Country();
         }
         $countryObject->setName($name);
         $countryObject->setIsoCode($iso);
         $countryObject->setActive(false);
         $countryObject->setCurrency($currencyObject);
         $countryObject->save();
     }
     $this->_helper->json(array("success" => true));
 }
 /**
  * Get current Users Country
  *
  * @return Country|null
  * @throws \Exception
  */
 public static function getCountry()
 {
     $session = self::getSession();
     $country = null;
     if ($session->countryId) {
         $country = Country::getById($session->countryId);
         if ($country instanceof Country) {
             return $country;
         }
     }
     if (self::getSession()->user instanceof User) {
         $user = self::getSession()->user;
         if (count($user->getAddresses()) > 0) {
             $country = $user->getAddresses()->get(0);
         }
     }
     if (!$country instanceof Country) {
         if (file_exists(CORESHOP_CONFIGURATION_PATH . "/GeoIP/GeoIP.dat")) {
             $gi = geoip_open(CORESHOP_CONFIGURATION_PATH . "/GeoIP/GeoIP.dat", GEOIP_MEMORY_CACHE);
             $country = geoip_country_code_by_addr($gi, \Pimcore\Tool::getClientIp());
             geoip_close($gi);
             $country = Country::getByIsoCode($country);
         } else {
             $enabled = Country::getActiveCountries();
             if (count($enabled) > 0) {
                 return $enabled[0];
             } else {
                 throw new \Exception("no enabled countries found");
             }
         }
     }
     if (!$country instanceof Country) {
         //Using Default Country: AT
         //TODO: Default Country configurable thru settings
         $country = Country::getById(7);
         //throw new \Exception("Country with code $country not found");
     }
     $session->countryId = $country->getId();
     return $country;
 }