public static function ShippingMethod::sort in Commerce Shipping 8.2
Helper callback for uasort() to sort shipping methods by weight and label.
Parameters
\Drupal\commerce_shipping\Entity\ShippingMethodInterface $a: The first shipping method to sort.
\Drupal\commerce_shipping\Entity\ShippingMethodInterface $b: The second shipping method to sort.
Return value
int The comparison result for uasort().
File
- src/
Entity/ ShippingMethod.php, line 255
Class
- ShippingMethod
- Defines the shipping method entity class.
Namespace
Drupal\commerce_shipping\EntityCode
public static function sort(ShippingMethodInterface $a, ShippingMethodInterface $b) {
$a_weight = $a
->getWeight();
$b_weight = $b
->getWeight();
if ($a_weight == $b_weight) {
$a_label = $a
->label();
$b_label = $b
->label();
return strnatcasecmp($a_label, $b_label);
}
return $a_weight < $b_weight ? -1 : 1;
}