/** * @return int */ public function getCountry() { if (!$this->country instanceof CountryModel) { $this->country = CountryModel::getById($this->country); } return $this->country; }
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)); }
protected function buildOptions() { $countries = Country::getActiveCountries(); $options = array(); foreach ($countries as $country) { $options[] = array("key" => $country->getName(), "value" => $country->getId()); } $this->setOptions($options); }
/** * Get the assets from database * * @return array */ public function load() { $currencies = array(); $currenciesData = $this->db->fetchAll("SELECT id FROM coreshop_country" . $this->getCondition() . $this->getOrder() . $this->getOffsetLimit(), $this->model->getConditionVariables()); foreach ($currenciesData as $currencyData) { if ($currency = Model\Country::getById($currencyData["id"])) { $currencies[] = $currency; } } $this->model->setCountries($currencies); return $currencies; }
/** * 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; }
/** * @see Object\ClassDefinition\Data::getDataForQueryResource * @param Country $data * @param null|Model\Object\AbstractObject $object * @return integer|null */ public function getDataForQueryResource($data, $object = null) { if ($data instanceof Country) { return $data->getId(); } return null; }
public function addressAction() { $this->view->redirect = $this->getParam("redirect", $this->view->url(array("lang" => $this->language, "action" => "addresses"), "coreshop_user", true)); $update = $this->getParam("address"); $this->view->isNew = false; foreach ($this->session->user->getAddresses() as $address) { if ($address->getName() === $update) { $this->view->address = $address; } } if (!$this->view->address instanceof CoreShopUserAddress) { $this->view->address = new CoreShopUserAddress(); $this->view->isNew = true; } if ($this->getRequest()->isPost()) { $params = $this->getAllParams(); $addressParams = array(); foreach ($params as $key => $value) { if (startsWith($key, "address_")) { $addressKey = str_replace("address_", "", $key); $addressParams[$addressKey] = $value; } } $adresses = $this->session->user->getAddresses(); if (!$adresses instanceof Object\Fieldcollection) { $adresses = new Object\Fieldcollection(); } if ($update) { for ($i = 0; $i < count($this->session->user->getAddresses()); $i++) { if ($this->session->user->getAddresses()->get($i)->getName() == $update) { //$this->session->user->getAddresses()->remove($i); break; } } } $this->view->address->setValues($addressParams); //TODO: Check if country exists and is valid $this->view->address->setCountry(Country::getById($addressParams['country'])); if ($this->view->isNew) { $adresses->add($this->view->address); } $this->session->user->save(); if (array_key_exists("_redirect", $params)) { $this->_redirect($params['_redirect']); } else { $this->_redirect("/de/shop"); } } }
public function countries() { $countries = Country::getActiveCountries(); return $countries; }
public function removeAction() { $id = $this->getParam("id"); $country = Country::getById($id); if ($country instanceof Country) { $country->delete(); $this->_helper->json(array("success" => true)); } $this->_helper->json(array("success" => false)); }