/** * @return int */ public function getCountry() { if (!$this->country instanceof CountryModel) { $this->country = CountryModel::getById($this->country); } return $this->country; }
/** * 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::getDataFromResource * @param integer $data * @return Country */ public function getDataFromResource($data) { if (intval($data) > 0) { return Country::getById($data); } 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 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)); }