Country dropdown menu is a mess

Open to all! Ask other shopowners for help.
Post Reply
User avatar
ReneH4
Contributor
Posts: 145
Joined: Mon Oct 26, 2020 12:00 pm
Phoenix Version:
Has thanked: 13 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?


Join The Code Co-op to get access to your library in the Code Co-op Forum
User avatar
burt
Core Team
Posts: 4551
Joined: Tue Oct 29, 2019 9:37 am
Phoenix Version: v1.1.0.8
Has thanked: 252 times
Been thanked: 412 times

Re: Country dropdown menu is a mess

Post by burt »

Which v Phoenix (or Frozen, Gold, etc) ?
I am not here to build for you.
I am here to build with you. Let's help each other.
User avatar
ReneH4
Contributor
Posts: 145
Joined: Mon Oct 26, 2020 12:00 pm
Phoenix Version:
Has thanked: 13 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) ?
User avatar
burt
Core Team
Posts: 4551
Joined: Tue Oct 29, 2019 9:37 am
Phoenix Version: v1.1.0.8
Has thanked: 252 times
Been thanked: 412 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?
I am not here to build for you.
I am here to build with you. Let's help each other.
ecartz
Core Team
Posts: 3084
Joined: Tue Nov 05, 2019 6:02 pm
Phoenix Version:
Has thanked: 4 times
Been thanked: 208 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
Contributor
Posts: 145
Joined: Mon Oct 26, 2020 12:00 pm
Phoenix Version:
Has thanked: 13 times
Been thanked: 17 times

Re: Country dropdown menu is a mess

Post by ReneH4 »

Will look at both options, thanks!
User avatar
ReneH4
Contributor
Posts: 145
Joined: Mon Oct 26, 2020 12:00 pm
Phoenix Version:
Has thanked: 13 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
Contributor
Posts: 119
Joined: Fri Oct 25, 2019 4:19 pm
Phoenix Version: v1.0.3.0
Has thanked: 86 times
Been thanked: 17 times

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
Senior Contributor
Posts: 677
Joined: Fri Oct 25, 2019 5:06 pm
Phoenix Version: v1.0.8.16
Has thanked: 100 times
Been thanked: 56 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
Contributor
Posts: 145
Joined: Mon Oct 26, 2020 12:00 pm
Phoenix Version:
Has thanked: 13 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/


Join The Code Co-op to get access to your library in the Code Co-op Forum
Post Reply