Jump to content

How can I change order of list of States by ISO code in address fields?


tatamimimi

Recommended Posts

Hi!!!

I'm making prestashop shopping site in Japanese.
I want to change order of "states" in the page of address registration or change address .

It's now in alphabetical order, but I want to make it order by ISO code.

I can't find which file should I change...
Please help me!

Thank you in advance.

Link to comment
Share on other sites

Have you tried to change that in getCountries() method in Country.php class file?

 

/classes/Country.php

 

It is better to create override class and then change it in the override class

/override/classes/Country.php

 

 

 

    public static function getCountries($id_lang, $active = false, $contain_states = false, $list_states = true)
    {
        $countries = array();
        $result = Db::getInstance(_PS_USE_SQL_SLAVE_)->ExecuteS('
SELECT cl.*,c.*, cl.`name` country, z.`name` zone
FROM `'._DB_PREFIX_.'country` c '.Shop::addSqlAssociation('country', 'c').'
LEFT JOIN `'._DB_PREFIX_.'country_lang` cl ON (c.`id_country` = cl.`id_country` AND cl.`id_lang` = '.(int)$id_lang.')
LEFT JOIN `'._DB_PREFIX_.'zone` z ON (z.`id_zone` = c.`id_zone`)
WHERE 1'.($active ? ' AND c.active = 1' : '').($contain_states ? ' AND c.`contains_states` = '.(int)$contain_states : '').'
ORDER BY cl.name ASC');
        foreach ($result as $row) {
            $countries[$row['id_country']] = $row;
        }
  • Like 1
Link to comment
Share on other sites

Thank you shokinro for your quick reply!

I tried to change the Country.php and put it in override foulder.

 

As my version is 1.6.1.4, actually the code was not same.
It was like below.
 

  if ($list_states) {
            $result = Db::getInstance(_PS_USE_SQL_SLAVE_)->ExecuteS('SELECT * FROM `'._DB_PREFIX_.'state` ORDER BY `name` ASC');
            foreach ($result as $row) {
                if (isset($countries[$row['id_country']]) && $row['active'] == 1) { /* Does not keep the state if its country has been disabled and not selected */
                        $countries[$row['id_country']]['states'][] = $row;
                }
            }
        }
        return $countries;

I changed the part of"name" to "iso_code".

 

It works now perfectly!
Thank you sooooooo much!!

Link to comment
Share on other sites

  • 4 years later...

Anyone know how to do this in 1.7.6.4?

I did that same as above, but the Japanese version of my store in unchanged. The states are still ordered alphabetically. Anywhere else I need to fix the code?

Specifically, I'm looking at the addresses on the account page. 

Thanks

Link to comment
Share on other sites

On 12/19/2020 at 10:07 AM, MojoSwift said:

Anyone know how to do this in 1.7.6.4?

I did that same as above, but the Japanese version of my store in unchanged. The states are still ordered alphabetically. Anywhere else I need to fix the code?

Specifically, I'm looking at the addresses on the account page. 

Thanks

Never mind. There are 2 similar areas where the code needs to be edited (Line 220 and 254). I missed the 1st one.  😋

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...