Country dropdown menu is a mess

Ask the community for help and support.
Post Reply
User avatar
ReneH4
Posts: 154
Joined: Mon Oct 26, 2020 12:00 pm
Has thanked: 12 times
Been thanked: 17 times

Country dropdown menu is a mess

Post 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?
burt
Lead Developer
Lead Developer
Posts: 2423
Joined: Tue Oct 29, 2019 9:37 am
Has thanked: 49 times
Been thanked: 137 times

Re: Country dropdown menu is a mess

Post by burt »

Which v Phoenix (or Frozen, Gold, etc) ?
Gamechanger Addon: Queued Emails, try before you buy.
User avatar
ReneH4
Posts: 154
Joined: Mon Oct 26, 2020 12:00 pm
Has thanked: 12 times
Been thanked: 17 times

Re: Country dropdown menu is a mess

Post 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) ?
burt
Lead Developer
Lead Developer
Posts: 2423
Joined: Tue Oct 29, 2019 9:37 am
Has thanked: 49 times
Been thanked: 137 times

Re: Country dropdown menu is a mess

Post 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?
Gamechanger Addon: Queued Emails, try before you buy.
ecartz
Lead Developer
Lead Developer
Posts: 2637
Joined: Tue Nov 05, 2019 6:02 pm
Has thanked: 4 times
Been thanked: 181 times

Re: Country dropdown menu is a mess

Post 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.
User avatar
ReneH4
Posts: 154
Joined: Mon Oct 26, 2020 12:00 pm
Has thanked: 12 times
Been thanked: 17 times

Re: Country dropdown menu is a mess

Post by ReneH4 »

Will look at both options, thanks!
User avatar
ReneH4
Posts: 154
Joined: Mon Oct 26, 2020 12:00 pm
Has thanked: 12 times
Been thanked: 17 times

Re: Country dropdown menu is a mess

Post 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?
ArtcoInc
VIP Member
VIP Member
Posts: 17
Joined: Fri Oct 25, 2019 4:19 pm

Re: Country dropdown menu is a mess

Post 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
Omar_one
VIP Member
VIP Member
Posts: 481
Joined: Fri Oct 25, 2019 5:06 pm
Has thanked: 48 times
Been thanked: 27 times

Re: Country dropdown menu is a mess

Post 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/
User avatar
ReneH4
Posts: 154
Joined: Mon Oct 26, 2020 12:00 pm
Has thanked: 12 times
Been thanked: 17 times

Re: Country dropdown menu is a mess

Post 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/
Post Reply