Hello,
1.
When I view the $new_usable_rates array they are actually in the proper order, but for some reason it picks "UPS Next Day" as the default. Probably because it is the first listed in the [methods] array within the shipping_params ?
I just tested it myself and you were right, the shipping services were sorted after the onShippingDisplay call, so to prevent it you should edit the "administrator\components\com_hikashop\classes\shipping.php" file and change that line :
uasort($usable_methods, array($this, "sortShipping"));
By :
//uasort($usable_methods, array($this, "sortShipping"));
2.
To accomplish what you want you'll need to add these lines :
function array_sort($array, $on, $type, $order = SORT_ASC){
if(empty($array))
return array();
$new_array = array();
$sortable_array = array();
foreach ($array as $key => $value) {
if($value->shipping_type == $type)
$sortable_array[$key] = $value->shipping_price;
}
switch ($order) {
case SORT_ASC:
asort($sortable_array);
break;
case SORT_DESC:
arsort($sortable_array);
break;
}
foreach ($sortable_array as $k => $v) {
$new_array[$k] = $array[$k];
}
return $new_array;
}
Just after these lines :
And to add this line :
$new_usable_rates = $this->array_sort($new_usable_rates, 'shipping_price', 'ups', SORT_DESC);
Just before these lines :
foreach($new_usable_rates as $i => $usable_rate) {
if(isset($usable_rate->shipping_price_orig) || isset($usable_rate->shipping_currency_id_orig)){
if($usable_rate->shipping_currency_id_orig == $usable_rate->shipping_currency_id)
$usable_rate->shipping_price_orig = $usable_rate->shipping_price;
else
$usable_rate->shipping_price_orig = $currencyClass->convertUniquePrice($usable_rate->shipping_price, $usable_rate->shipping_currency_id, $usable_rate->shipping_currency_id_orig);
}
$usable_rates[$usable_rate->shipping_id] = $usable_rate;
$cache_usable_rates[$usable_rate->shipping_id] = $usable_rate;
}
Note that you can change that line :
$new_usable_rates = $this->array_sort($new_usable_rates, 'shipping_price', 'ups', SORT_DESC);
To :
$new_usable_rates = $this->array_sort($new_usable_rates, 'shipping_price', 'ups', SORT_ASC);
If you want your shipping services to be sorted from the lower to the highest shipping price.