Kryptronic Software Support Forum

You are viewing this forum as a guest. Login to an existing account, or create a new account, to reply to topics and to create new topics.

#1 09-03-2026 03:13:55

Graham
Member
Registered: 09-30-2004
Posts: 1020
Website

State Province sort order

A long time ago I changed my code so that the State / Province order was sorted to have Not Applicable at the top, then the UK Counties, then the US States.

I've just had a customer from Switzerland say they can't create an account because it's requiring this field, but there's no applicable options available to them and I discovered that, following one of the updates, something must have changed because it's gone back to the default alphabetical order.

Unfortunately I can't find the code I used, so can someone please tell me how I can:

1) Set Not Applicable as the default

2) Sort the States and Provinces used in the stateprov field into the order I want.

Thanks.

Last edited by Graham (09-03-2026 08:08:11)

Offline

 

#2 09-12-2026 04:22:47

Graham
Member
Registered: 09-30-2004
Posts: 1020
Website

Re: State Province sort order

Anyone...?

Offline

 

#3 09-16-2026 09:19:27

webmaster
Administrator
From: York, PA
Registered: 04-20-2001
Posts: 20000
Website

Re: State Province sort order

You can't explicitly set a default for the state/province fields as the default is the user's session value for state/province, if set.  Getting it to sort to the top should be good enough, though.

To set the sort order for states/provinces, use System / Locations / States/Provinces.  They are sorted by their sort order field (which you can update) then alphabetically.  You'll find the default sort orders are set to sort them in the following manner:

US states sort order 100 then alphabetically
CA provinces sort order 200 then alphabetically
US APOs sort order 300 then alphabetically
UK counties sort order 400 then alphabetically
Not Applicable sort order 999

To make Not Applicable first, simple update it's sort order and set it to 1.  Or any number under 100.  All the rest will remain in line behind it.


Nick Hendler

Offline

 

#4 09-16-2026 10:30:53

Graham
Member
Registered: 09-30-2004
Posts: 1020
Website

Re: State Province sort order

Unfortunately that's not working.

This is the stateprov.csv file: https://www.affordableleather.co.uk/stateprov-1.jpg

This is what is shown in the Shipping Estimator: https://www.affordableleather.co.uk/stateprov-2.jpg

BTW I've tried sorting stateprov.csv by sortorder and uploading that, but it still presents the results in alphabetical order.

Offline

 

#5 09-17-2026 08:49:27

webmaster
Administrator
From: York, PA
Registered: 04-20-2001
Posts: 20000
Website

Re: State Province sort order

I've looked at this in dev and verified that the sort order is based on the sort order for the states/provinces then alphabetical.  So that means you're either using older software that used a different sort order or you have a mod hardcoded into your install that is sorting them alphabetically or you didn't upload those CSV file changes.  What version are you using?  Have you made any mods to the {private}/core/CORE_App/CORE_App.php file?  Specifically in the get_stateprov_info() function which should pull the list using this:

Code:

$result = $this->CORE_DB->sql_do(array('sql' => $sql, 'table' => 'core_stateprov', 'order' => array('sortorder' => 'ASC', 'id' => 'ASC')));

Nick Hendler

Offline

 

#6 09-17-2026 19:40:48

Graham
Member
Registered: 09-30-2004
Posts: 1020
Website

Re: State Province sort order

I have checked using System/ Database/ Raw Database Admin and the modified stateprov.csv file I uploaded appears to be the one in use.

I've just looked through the document where I list all the modifications I've made to the code and found this which I must have copied from a reply you sent to me sometime between 2022-10-31 and 2023-02-06 (I'm not sure of the exact date, but those are the dates above and below this text in my document)

* * * * *

We've noticed this as an issue on updated installs. To correct, we've modified the logic which will be available in our next update. Here's a rundown of the change so you can do it now:

Modify {private}/core/CORE_App/CORE_App.php. In the functions get_country_info() and get_stateprov_info(), change the order for the SQL call to read:
array('sortorder' => 'ASC', 'id' => 'ASC')

That will get everything sorted the way you want, and if there are any minor adjustments to be made, adjust the sort order for Countries and States/Provinces using the System / Locations admin functions.

* * * *

I searched for the code you gave in your reply above in the get_stateprov_info() function in {private}/custom/core/CORE_App/CORE_App.php file and found this:

Code:

//HACK
// edited line below to add array('sortorder' => 'ASC', 'id' => 'ASC') ???
$result = $this->CORE_DB->sql_do(array('sql' => $sql, 'table' => 'core_stateprov', 'order' => array('id' => 'ASC')));

// $result = $this->CORE_DB->sql_do(array('sql' => $sql, 'table' => 'core_stateprov', 'order' => array('sortorder' => 'ASC', 'id' => 'ASC')));

I presume that it's this which is causing the anomalous behaviour, so can I just swap the commented line and the uncommented line to get it to work, or is there something else I need to do?

Offline

 

#7 09-18-2026 08:55:32

webmaster
Administrator
From: York, PA
Registered: 04-20-2001
Posts: 20000
Website

Re: State Province sort order

That's it.  You have:

Code:

$result = $this->CORE_DB->sql_do(array('sql' => $sql, 'table' => 'core_stateprov', 'order' => array('id' => 'ASC')));

Which is incorrect.  The mod you were provided (which was incorporated sometime ago into the stock code) is there, but disabled.  Remove the first three lines you posted and uncomment the fourth line:

Code:

$result = $this->CORE_DB->sql_do(array('sql' => $sql, 'table' => 'core_stateprov', 'order' => array('sortorder' => 'ASC', 'id' => 'ASC')));

Nick Hendler

Offline

 

#8 09-18-2026 14:19:15

Graham
Member
Registered: 09-30-2004
Posts: 1020
Website

Re: State Province sort order

That seems to be working now, thanks.

Offline

 

Board footer