Page 1 of 1

Country dropdown menu is a mess

Posted: Mon Jun 28, 2021 1:39 pm
by ReneH4
After more than 10 years of usage my country table has become a bit messy.

As a result the dropdown menu in create_account is no longer an alphabetical list.

It shows the countries in order of countries_id.

I would like to fix that and have the list sorted by countries_name.

Anyone has done that?

Re: Country dropdown menu is a mess

Posted: Mon Jun 28, 2021 3:19 pm
by burt
Which v Phoenix (or Frozen, Gold, etc) ?

Re: Country dropdown menu is a mess

Posted: Mon Jun 28, 2021 3:54 pm
by ReneH4
Sure, forgot to mention: 1079 Phoenix

Good to see you back Gary!

burt wrote: Mon Jun 28, 2021 3:19 pm Which v Phoenix (or Frozen, Gold, etc) ?

Re: Country dropdown menu is a mess

Posted: Sat Jul 10, 2021 12:41 pm
by burt
The simplest solution would probably be to add an order by clause in the relevant module;

https://github.com/CE-PhoenixCart/Phoen ... y.php#L184

Should be enough to get you going?

Re: Country dropdown menu is a mess

Posted: Sat Jul 10, 2021 2:11 pm
by ecartz
I would think it would be even simpler to just rebuild the table in the proper order.

I'm pretty sure that it sorts in insertion order, not by ID (it's just that the IDs are also in insertion order). So just export the table (including the IDs), reorder the insertion statements, drop the table, and import the table again.

That might be slightly more work upfront, but then you don't need to modify the code at all. And of course this doesn't limit you to ordering by country name. The order could be entirely arbitrary.

The advantage of not modifying the code is that you don't have to maintain the code going forward.

Re: Country dropdown menu is a mess

Posted: Mon Jul 19, 2021 1:18 pm
by ReneH4
Will look at both options, thanks!

Re: Country dropdown menu is a mess

Posted: Mon Jul 19, 2021 7:26 pm
by ReneH4
I took Gary's advice and changed core. Not that changing core would be Gary's advice :-)

Changed:

Code: Select all

$countries_query = tep_db_query("SELECT countries_id, countries_name FROM countries");
To:

Code: Select all

$countries_query = tep_db_query("SELECT countries_id, countries_name FROM countries ORDER BY countries_name ASC");
burt wrote: Sat Jul 10, 2021 12:41 pm The simplest solution would probably be to add an order by clause in the relevant module;

https://github.com/CE-PhoenixCart/Phoen ... y.php#L184

Should be enough to get you going?

Re: Country dropdown menu is a mess

Posted: Tue Jul 20, 2021 5:57 pm
by ArtcoInc
ecartz wrote: Sat Jul 10, 2021 2:11 pm I would think it would be even simpler to just rebuild the table in the proper order.
...
The advantage of not modifying the code is that you don't have to maintain the code going forward.
Another advantage is that you can place your country of business at the top of the list. For example, I'm in the United States, and most of my customers are. So, it would make sense (to me, at least) to have the USA at the top of the list.

Malcolm

Re: Country dropdown menu is a mess

Posted: Tue Jul 20, 2021 6:38 pm
by Omar_one
ArtcoInc wrote: Tue Jul 20, 2021 5:57 pm
ecartz wrote: Sat Jul 10, 2021 2:11 pm I would think it would be even simpler to just rebuild the table in the proper order.
...
The advantage of not modifying the code is that you don't have to maintain the code going forward.
Another advantage is that you can place your country of business at the top of the list. For example, I'm in the United States, and most of my customers are. So, it would make sense (to me, at least) to have the USA at the top of the list.

Malcolm
You can check @zipurman add-on Favorite Countries app.php/addons/free_addon/favorite_countries/

Re: Country dropdown menu is a mess

Posted: Wed Jul 21, 2021 8:28 pm
by ReneH4
I installed this one too, nice to have!
Omar_one wrote: Tue Jul 20, 2021 6:38 pm You can check @zipurman add-on Favorite Countries app.php/addons/free_addon/favorite_countries/