private function buildOptions() { $countries = Country::getActiveCountries(); $options = array(); foreach ($countries as $country) { $options[] = array("key" => $country->getName(), "value" => $country->getId()); } $this->setOptions($options); }
/** * 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; }
public function countries() { $countries = Country::getActiveCountries(); return $countries; }