From 8367a649fd61bd31dd8fa8c363170203c426807b Mon Sep 17 00:00:00 2001 From: Mark Hamstra Date: Mon, 18 May 2026 17:16:20 +0200 Subject: [PATCH] Improve distance sorting in store locator Currently, the distance sort is comparing by strings. 17,123km distance appears before 2,123 distance because 1 comes before 2 in a string sort. (This might be locale dependent where it might work correctly currently if a period is used as decimal separator). This patch corrects that, using an explicit float sort with the spaceship operator to ensure distances make sense. --- .../model/googlestorelocator/googlestorelocator.class.php | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/core/components/googlestorelocator/model/googlestorelocator/googlestorelocator.class.php b/core/components/googlestorelocator/model/googlestorelocator/googlestorelocator.class.php index 4102674..8a6c38f 100644 --- a/core/components/googlestorelocator/model/googlestorelocator/googlestorelocator.class.php +++ b/core/components/googlestorelocator/model/googlestorelocator/googlestorelocator.class.php @@ -58,6 +58,11 @@ public function sortBy($stores, $sortby = 'menuindex', $direction = 'asc') if (!is_array($stores)) return false; usort($stores, function($a, $b) use ($sortby) { + if ($sortby === 'distance') { + $a = floatval(str_replace(',', '.', $a[$sortby])); + $b = floatval(str_replace(',', '.', $b[$sortby])); + return $a <=> $b; + } return strcmp($a[$sortby], $b[$sortby]); });