You are here

protected function ShipmentManager::sortRates in Commerce Shipping 8.2

Sorts the given rates.

Parameters

\Drupal\commerce_shipping\ShippingRate[] $rates: The rates.

Return value

\Drupal\commerce_shipping\ShippingRate[] The sorted rates.

1 call to ShipmentManager::sortRates()
ShipmentManager::calculateRates in src/ShipmentManager.php
Calculates rates for the given shipment.

File

src/ShipmentManager.php, line 145

Class

ShipmentManager

Namespace

Drupal\commerce_shipping

Code

protected function sortRates(array $rates) {

  // Sort by original_amount ascending.
  uasort($rates, function (ShippingRate $first_rate, ShippingRate $second_rate) {
    return $first_rate
      ->getOriginalAmount()
      ->compareTo($second_rate
      ->getOriginalAmount());
  });
  return $rates;
}