wp-e-commerce / WP-e-Commerce

WP eCommerce - The most popular independent eCommerce platform for WordPress
https://wpecommerce.org
GNU General Public License v2.0
216 stars 216 forks source link

States (regions) become unsorted by frontend JS #2351

Open leewillis77 opened 7 years ago

leewillis77 commented 7 years ago

In a standard installation, the states (regions) of countries are created in such a way that they are alphabetically ordered with incrementing IDs. However, if you were to modify the names of regions, or add new regions but do not add them in alphabetical order then they will be displayed incorrectly on the frontend.

The easiest way to reproduce is to add some additional regions to wp_wpsc_region_tax table in non-alphabetical sequence.

In my example, I added some regions to the United Kingdom:

| 65 |        223 | North west                | NW   |   0 |
| 66 |        223 | East                      | E    |   0 |
| 67 |        223 | West                      | W    |   0 |
| 68 |        223 | South                     | S    |   0 |
| 69 |        223 | North East                | NE   |   0 |

As you can see, these were not added in alphabetical order.

If you visit the checkout process, with the United Kingdom as your country, but with Javascript disabled then the region list shows correctly.

screenshot 2017-11-06 09 40 55

However, if you visit checkout with Javascript enabled, then the Javascript that rebuilds the region list according to the selected country outputs the regions in ID order:

screenshot 2017-11-06 09 43 42

The relevant code appears to be wpsc_update_regions_list_to_match_country() in wp-e-commerce.js