Shipping sort order in admin

When setting up shipping in amdin in weight order, after saving the sort order gets all messed up, see attached.
I d rather it sort by weight ascending, or even by price ascending if possible.makes it easier to edit in future
so
weight
12kg - 23.99kg
24kg - 35.99kg
36kg - 47.99kg
and so on
see attached messed up Screenshot by Lightshot

Hi!

Try replacing the following code:

        if (rateValues && rateValuesKeys.length > 0) {
            rateValuesKeys.sort().forEach(key => {
                data.rateValue = rateValues[key];
                fn_add_tr_to_table_conditions(data, $newConditionTable, false);
            });

with this code:

        if (rateValues && rateValuesKeys.length > 0) {
            var collator = new Intl.Collator(undefined, {numeric: true, sensitivity: 'base'});
            rateValuesKeys.sort(collator.compare).forEach(key => {
                data.rateValue = rateValues[key];
                fn_add_tr_to_table_conditions(data, $newConditionTable, false);
            });

in the js/tygh/backend/shipping_rates.js file. Then clear the cache of your installation and check if sorting is working as intended.

Thanks, but just a word of warning, it seems this will delete all exisiting rates, so they will need to be added again’

When I was trying these changes in my installation, it haven’t affected existing rates. And overall these changes could not affect existing data. Unfortunately I don’t know what happened in your case.

OK thanks, Ill take a look

You are correct the alteration works fine, I deleted another line by mistake

thanks

1 Like

This topic was automatically closed 12 hours after the last reply. New replies are no longer allowed.

This issue has been fixed in the upcoming CS-Cart 4.18.2.

It is possible to manually apply the fix to CS-Cart 4.18.1 by using the attached DIFF file:
https://gist.github.com/csavoronin/e121be0afd6d595a81a8914b665b6e9e

Here is how to apply a DIFF file:
https://docs.cs-cart.com/latest/upgrade/apply_diff_file.html

This fix is different from what was suggested above. If you applied the previous solution, you shouldn’t apply this one.