/** * Get a country ID with its iso code * * @param string $iso_code Country iso code * @return integer Country ID */ public static function getByIso($iso_code) { if (!JeproshopTools::isLanguageIsoCode($iso_code)) { die(Tools::displayError()); } $db = JFactory::getDBO(); $query = "SELECT " . $db->quoteName('country_id') . " FROM " . $db->quoteName('#__jeproshop_country') . " WHERE " . $db->quoteName('iso_code') . " = " . $db->quote(strtoupper($iso_code)); $db->setQuery($query); $result = $db->loadObject(); return $result->country_id; }
/** * Assign template vars related to countries display */ protected function assignCountries() { $context = JeproshopContext::getContext(); $app = JFactory::getApplication(); $country_id = $app->input->get('country_id'); // Get selected country if (isset($country_id) && !is_null($country_id) && is_numeric($country_id)) { $selected_country = (int) $country_id; } else { if (isset($this->address) && isset($this->address->country_id) && !empty($this->address->country_id) && is_numeric($this->address->country_id)) { $selected_country = (int) $this->address->country_id; } else { if (isset($_SERVER['HTTP_ACCEPT_LANGUAGE'])) { // get all countries as language (xy) or language-country (wz-XY) $array = array(); preg_match("#(?<=-)\\w\\w|\\w\\w(?!-)#", $_SERVER['HTTP_ACCEPT_LANGUAGE'], $array); if (!JeproshopTools::isLanguageIsoCode($array[0]) || !($selected_country = JeproshopCountryModelCountry::getByIso($array[0]))) { $selected_country = (int) JeproshopSettingModelSetting::getValue('default_country'); } } else { $selected_country = (int) JeproshopSettingModelSetting::getValue('default_country'); } } } // Generate countries list if (JeproshopSettingModelSetting::getValue('restrict_delivered_countries')) { $countries = JeproshopCarrierModelCarrier::getDeliveredCountries($context->language->lang_id, true, true); } else { $countries = JeproshopCountryModelCountry::getCountries($context->language->lang_id, true); } // @todo use helper $list = ''; foreach ($countries as $country) { $selected = $country->country_id == $selected_country ? 'selected="selected"' : ''; $list .= '<option value="' . (int) $country->country_id . '" ' . $selected . '>' . htmlentities(ucfirst($country->name)) . '</option>'; } // Assign vars $this->assignRef('countries_list', $list); $this->assignRef('countries', $countries); }