Jump to content

States dropdown names ordering in alphabetical


Recommended Posts

I am using 1.3.1 and the address drop down list are sorted correctly by name.
which version are you using? And which page (front store/back office) is the problem occurs?

By the way, checked by database, the state ID is not in order of state name, but they are still displayed correctly.
If you can tell me more detail, maybe I can take look at it.

Link to comment
Share on other sites

I'm using version 1.3.1.1, and states are displayed exactly like ID.
I have no clue where I need to watch for solution. :(

And sh, I check your site registration - with USA states as default all is ok, but Canada states are not in alphabetical order.

Link to comment
Share on other sites

You are right, but it is really weird, it is good at my Development Environment on my home computer.
I am using exactly database and code with public site. You can see it at attached screen shot.

I guess it must be something to do with environment setting. I am checking with it, hope I can find out something.

Thank you for point out the problem on my site. I never thought this could be happening.

31165_pT7tJW9QKzbAvwg7sH8a_t

Link to comment
Share on other sites

Thanks Rocky for pointing out the fixes.

Based on my investigation, this issue only happens on some browsers, not all browsers. I confirmed that IE displays correctly and FireFox does not.

The temporary solution to fix this issue it to re-arrange the States data in a correct alphabetical order.
I have fixed my data and so I think it should be displayed correctly for all browsers now.

For your reference, here you can find some more information.

Link to comment
Share on other sites

rocky, how can I fix it on my v1.3.1?

I think the temporary fix for this issue is to fix your data to make their IDs in a correct order.
When you input new data, input them in alphabetical order.

If this is a fix to your problem, please mark this thread as "SOLVED"
Link to comment
Share on other sites

You need to change line 16 of address.tpl (in PrestaShop v1.3.1) from:

countries[{$country.id_country|intval}]['{$state.id_state}'] = '{$state.name|escape:'htmlall':'UTF-8'}';



to:

countries[{$country.id_country|intval}].push({ldelim}'id' : '{$state.id_state}', 'name' : '{$state.name|escape:'htmlall':'UTF-8'}'{rdelim});



and line 14 of authentication.tpl from:

countries[{$country.id_country|intval}]['{$state.id_state|intval}'] = '{$state.name|escape:'htmlall':'UTF-8'}';



to:

countries[{$country.id_country|intval}].push({ldelim}'id' : '{$state.id_state}', 'name' : '{$state.name|escape:'htmlall':'UTF-8'}'{rdelim});



and lines 16-21 of js/tools/statesManagement.js in your theme's directory from:

for (indexState in states)
{
   //ie bug fix
   if (indexState != 'indexOf')
       $('select#id_state').append(''+states[indexState]+'');
}



to:

$(states).each(function (key, item){
   $('select#id_state').append(''+item.name+'');
});



I think that's everything, but I may have missed something. It is better to fully upgrade to PrestaShop v1.3.2 than try to upgrade just parts.

Link to comment
Share on other sites

This is great rocky, for now I'm stick to v1.3.1 and it fix this problem, only need to change in 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');



emmmm... I have small problem. Maybe someone knows how to make some name to be in end of list. In my example all is ok, but I need to make state with name "Other" and make it in end of the list(I try to write -Other- but it's shows first) maybe someone have soliton? :)

Link to comment
Share on other sites

  • 2 months later...

This helped me find a solution to a different problem in 1.4.0.4. I was disabling certain states in the ps_state table since I don't ship to them, but they were still appearing in the address drop down. I noticed in the /classes/Country.php that the ORDER BY code is now delivered, but I had to add a clause to check the "active" state. So, I made an addition around line 163 that changed:

       $states = Db::getInstance(_PS_USE_SQL_SLAVE_)->ExecuteS('
       SELECT s.*
       FROM `'._DB_PREFIX_.'state` s
       ORDER BY s.`name` ASC');


to:

       $states = Db::getInstance(_PS_USE_SQL_SLAVE_)->ExecuteS('
       SELECT s.*
       FROM `'._DB_PREFIX_.'state` s
       '.($active ? 'WHERE s.active = 1' : '').'
       ORDER BY s.`name` ASC');


Hope this will help someone too.

Link to comment
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...