Sort Order For Order Status In Orders.manage 4.x

We have over 20 order status' in our system and it is driving me nuts that they are not in order in the drop down button in orders.manage. I'm trying to figure out how to sort the array that feeds this. Anyone have some insight into where it is and the syntax of the code to get it to sort?

Can't you just click the "Status" header and have it sort by that.

Sort the list on the button, not the list of orders. Pic should explain.

sort.jpg

You might try using the 'get_statuses_post' hook from fn_get_statuses() functionin fn.common.php. You could then sort the resulting list however you wanted.

It would make more sense if they provided a 'position' setting for the statuses so that the statuses could be ordered based on operational needs versus sorted by name or status letter. You could add this column and modify the admin environment to allow you to set it, then use the 'get_statuses_pre' hook to have the DB return the data in that order.

Adding a position column would make sense.

Looks like this is where they query the tables

$statuses = db_get_hash_array(
"SELECT ?:statuses.*, ?:status_descriptions.*"
. " FROM ?:statuses"
. $join
. " WHERE 1 $condition",
'status'
);
I tried a few ideas to add an "order by ?:status_descriptions.description" as we are trying to sort the array by the description column in the status_descriptions table. No matter where and how I put it, it seems to kill the page. Any ideas?

Here is the code from statuses.php in 3.x

$status_data = db_get_row("SELECT ?:statuses.*, ?:status_descriptions.* FROM ?:statuses LEFT JOIN ?:status_descriptions ON ?:statuses.status = ?:status_descriptions.status AND ?:statuses.type = ?:status_descriptions.type AND ?:status_descriptions.lang_code = ?s WHERE ?:statuses.status = ?s AND ?:statuses.type = ?s ORDER BY ?:status_descriptions.description", DESCR_SL, $_REQUEST['status'], $_REQUEST['type']);

Much more complicated in 4.x

This code works for me:

    $statuses = db_get_hash_array(
        "SELECT ?:statuses.*, ?:status_descriptions.*"
        . " FROM ?:statuses"
        . $join
        . " WHERE 1 $condition"
        . " ORDER BY ?:status_descriptions.description ASC",
        'status'
    );

Interesting. Not working here. Even exact copy and paste. Still getting an HTTP 500 error.

Working now. When I just added the one line, it did not work, even copy and paste. When copied and pasted it worked. Compared the text and it was exactly the same. Very strange.

If you use Windoz, sometimes it will add special characters to copy/paste that are not visible but do get pasted along with the intended data.