RasdyCute Posted May 14, 2015 Share Posted May 14, 2015 I want to create a separate Country and State Dropdown for my new experimenting module but the countries are empty, can you somebody can help me here. Thanks in advance Link to comment Share on other sites More sharing options...
PascalVG Posted May 14, 2015 Share Posted May 14, 2015 ?? Aren't they already separated? Look how they do it in the controllers/front/AddressController.php file Link to comment Share on other sites More sharing options...
RasdyCute Posted May 18, 2015 Author Share Posted May 18, 2015 How can I make on a TPL can you help me about that? Link to comment Share on other sites More sharing options...
PascalVG Posted May 18, 2015 Share Posted May 18, 2015 Not sure if I understand your question. Normally either in the controller you add the list of countries to a smarty variable, or if you have a module , you can do this in the function: public function getContent() Where you can get all countries and all states. Then you need some javascript in the tpl file to filter the states according to the country chosen. I think it's all in the controllers/front/AddressController and the themes/<your theme folder>/Address.tpl files, as well as the javascript file themes/<your theme folder/js/tools/statesManagement.js', In AddressController, get the countries, and assign to smarty variable: protected function assignCountries() { $this->id_country = (int)Tools::getCountry($this->_address); // Generate countries list if (Configuration::get('PS_RESTRICT_DELIVERED_COUNTRIES')) $countries = Carrier::getDeliveredCountries($this->context->language->id, true, true); else $countries = Country::getCountries($this->context->language->id, true); // @todo use helper $list = ''; foreach ($countries as $country) { $selected = ((int)$country['id_country'] === $this->id_country) ? ' selected="selected"' : ''; $list .= '<option value="'.(int)$country['id_country'].'"'.$selected.'>'.htmlentities($country['name'], ENT_COMPAT, 'UTF-8').'</option>'; } // Assign vars $this->context->smarty->assign(array( 'countries_list' => $list, 'countries' => $countries, 'sl_country' => (int)$this->id_country, )); } And in the function: protected function processSubmitAddress() They check if the country has states, and if so, if a state was chosen etc. Have a look in the file for this code how they do it. In the Address.tpl file, they use the assigned variables: {if $field_name eq 'Country:name' || $field_name eq 'country'} <div class="required form-group"> <label for="id_country">{l s='Country'} <sup>*</sup></label> <select id="id_country" class="form-control" name="id_country">{$countries_list}</select> </div> {/if} Same for state: {if $field_name eq 'State:name'} {assign var="stateExist" value=true} <div class="required id_state form-group"> <label for="id_state">{l s='State'} <sup>*</sup></label> <select name="id_state" id="id_state" class="form-control"> <option value="">-</option> </select> </div> {/if} The javascript glues the country an state lists together (i.e. make them dependent) If this is not what you needed, please explain one more time more clearly what you need. pascal Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now