bartman Posted May 26, 2010 Share Posted May 26, 2010 this has bugged me for a whileif i decide to add states to a country, they display fine in the state dropdown, but the order becomes incorrect if you enter new states, it looks like like the display is pulled from the db and sorted by id_state is it possible to change this so it is sorted on name so they alway appear alphabeticallyregardsCHris Link to comment Share on other sites More sharing options...
rocky Posted May 27, 2010 Share Posted May 27, 2010 You must be using PrestaShop v1.2.5 or earlier, since this bug was fixed in PrestaShop v1.3. The solution was to change lines 81-84 of classes/Country.php from: $states = Db::getInstance()->ExecuteS(' SELECT s.* FROM `'._DB_PREFIX_.'state` s '); to: $states = Db::getInstance()->ExecuteS(' SELECT s.* FROM `'._DB_PREFIX_.'state` s ORDER BY s.`name` ASC'); Link to comment Share on other sites More sharing options...
bartman Posted May 27, 2010 Author Share Posted May 27, 2010 nope usinhg 1.3 final on a new sitehttp://firestriker.co.ukjust add three states to UKin this orderKent, Surrey, Berkshireand the dropdown in authentication.php when creating an accountshows them in the order they were enteredchecked in classes/country.php and the code is as stated by Rocky, but its not working in authentication.php KentSurreyBerkshireregardsChris Link to comment Share on other sites More sharing options...
bartman Posted May 27, 2010 Author Share Posted May 27, 2010 just dropped back to the default theme and i am still getting the same problem Link to comment Share on other sites More sharing options...
bartman Posted May 27, 2010 Author Share Posted May 27, 2010 updatethe problem only seems to occur in firefox, which still renders the states in the order entered, in IE8 they display alphabetically Link to comment Share on other sites More sharing options...
bartman Posted May 27, 2010 Author Share Posted May 27, 2010 just some findings in firefoxscript in header shows [removed] // <![CDATA[ idSelectedCountry = false; valueDni = false; countries = new Array(); countriesNeedIDNumber = new Array(); countries[4] = new Array(); countries[4]['56'] = 'Alberta'; countries[4]['55'] = 'British Columbia'; Snip --------------------- countriesNeedIDNumber.push(6); countries[17] = new Array(); countries[17]['68'] = 'BerkShire'; countries[17]['66'] = 'Kent'; countries[17]['67'] = 'Surrey'; Snip -------- countries[21]['47'] = 'Washington'; countries[21]['48'] = 'West Virginia'; countries[21]['49'] = 'Wisconsin'; countries[21]['50'] = 'Wyoming'; //]]> [removed] so it shows them in the correct order in the arraywhen it is called into this code it ends up back in id order State - * just trying to figure out how it gets transposed by firefox, in a matter of fact how does the array get input into the dropdown box is beyond me at the momentregardsChris Link to comment Share on other sites More sharing options...
bartman Posted May 27, 2010 Author Share Posted May 27, 2010 chrome has the same problem Link to comment Share on other sites More sharing options...
rocky Posted May 27, 2010 Share Posted May 27, 2010 It appears to be this part of js/tools/statesManagement.js that populates the state dropdown: for (indexState in states) { //ie bug fix if (indexState != 'indexOf') $('select#id_state').append(''+states[indexState]+''); } The states seem to be sorted by array index rather than name.I suggest that you sort the array by name by changing lines 10-20 of authentication.tpl in your theme's directory from: {foreach from=$countries item='country'} {if isset($country.states)} countries[{$country.id_country|intval}] = new Array(); {foreach from=$country.states item='state' name='states'} countries[{$country.id_country|intval}]['{$state.id_state|intval}'] = '{$state.name|escape:'htmlall':'UTF-8'}'; {/foreach} {/if} {if $country.need_identification_number} countriesNeedIDNumber.push({$country.id_country|intval}); {/if} {/foreach} to: {foreach from=$countries item='country'} {if isset($country.states)} countries[{$country.id_country|intval}] = new Array(); {foreach from=$country.states item='state' name='states'} countries[{$country.id_country|intval}]['{$state.id_state|intval}'] = '{$state.name|escape:'htmlall':'UTF-8'}'; {/foreach} countries[{$country.id_country|intval}].sort(); {/if} {if $country.need_identification_number} countriesNeedIDNumber.push({$country.id_country|intval}); {/if} {/foreach} Hopefully, that will sort the array elements by name instead of country ID. Link to comment Share on other sites More sharing options...
bartman Posted May 27, 2010 Author Share Posted May 27, 2010 The fix workslmany thanks again for your help Link to comment Share on other sites More sharing options...
Pixel Posted June 11, 2010 Share Posted June 11, 2010 This fix may also be usefully employed in themes/yourtheme/address.tpl so the states also sort alpha when the customer adds/changes their address. Many thanks Rocky. Link to comment Share on other sites More sharing options...
tmocide Posted October 4, 2010 Share Posted October 4, 2010 This didnt fix the problem for me it just ordered the ids so when i clicked on ie: Hertfordshire it would display as Ohio, weird any ideaS? Link to comment Share on other sites More sharing options...
rocky Posted October 5, 2010 Share Posted October 5, 2010 Try the default PrestaShop v1.3.2 theme. I can see the state code has been changed. Link to comment Share on other sites More sharing options...
cidmacenter Posted November 4, 2010 Share Posted November 4, 2010 Help!!!!!!!!!!!1, I have pres6a and a 3rd of my customers are from DC, I’ve only had 2 orders placed trhu my website and today I lost one because of this issue can anyone please help me to solve this problem??!!! thanks Link to comment Share on other sites More sharing options...
GoldenLolo Posted August 1, 2013 Share Posted August 1, 2013 La solución para el problema es tan sencillo como ir a Países, seleccionar el país en cuestión y marcar la opción "Contiene estados". Así podréis seleccionar las provincias españolas, previamente entradas claro. Script para insertar provincias : http://www.prestashop.com/forums/topic/189941-aporte-agregar-provincias-espanolas-en-version-15/ Link to comment Share on other sites More sharing options...
vekia Posted August 1, 2013 Share Posted August 1, 2013 GoldenLolo can you please write in english here? i will be gratefull, moreover it's a bit old topic 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