private function assignCountries() { // Select the most appropriate country $app = JFactory::getApplication(); $country_id = $app->input->get('country_id'); if (isset($country_id) && is_numeric($country_id)) { $selectedCountry = (int) $country_id; } if (!isset($selectedCountry)) { $selectedCountry = (int) JeproshopSettingModelSetting::getValue('default_country'); } if (JeproshopSettingModelSetting::getValue('restrict_delivered_countries')) { $countries = JeproshopCarrierModelCarrier::getDeliveredCountries($this->context->language->lang_id, true, true); print_r($countries); } else { $countries = JeproshopCountryModelCountry::getCountries($this->context->language->lang_id, true); } $zones = JeproshopZoneModelZone::getZones(); $this->assignRef('zones', $zones); $this->assignRef('countries', $countries); $registrationProcessType = JeproshopSettingModelSetting::getValue('registration_process_type'); $this->assignRef('registration_process_type', $registrationProcessType); $selectedCountry = isset($selectedCountry) ? $selectedCountry : 0; $this->assignRef('selected_country', $selectedCountry); $vatNumberManagement = JeproshopSettingModelSetting::getValue('vat_number_management'); $this->assignRef('vat_management', $vatNumberManagement); }
/** * 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); }