From 28b8a483d79a4b36273b67c9d6b6d3046fe9946b Mon Sep 17 00:00:00 2001 From: Grzegorz Bogusz Date: Fri, 9 Feb 2018 13:32:28 +0100 Subject: [PATCH] Move sorting to new method --- .../Model/Layer/Filter/Attribute.php | 25 ++++++++++++++++--- 1 file changed, 22 insertions(+), 3 deletions(-) diff --git a/src/module-elasticsuite-catalog/Model/Layer/Filter/Attribute.php b/src/module-elasticsuite-catalog/Model/Layer/Filter/Attribute.php index 8288b6661..df70ffeae 100644 --- a/src/module-elasticsuite-catalog/Model/Layer/Filter/Attribute.php +++ b/src/module-elasticsuite-catalog/Model/Layer/Filter/Attribute.php @@ -267,11 +267,30 @@ private function addOptionsData(array $items) } } - usort($items, function ($item1, $item2) { - return $item1['adminSortIndex'] <= $item2['adminSortIndex'] ? -1 : 1; - }); + $items = $this->sortOptionsData($items); } return $items; } + + /** + * Sort items by adminSortIndex key. + * + * @param array $items to be sorted. + * + * @return array + */ + private function sortOptionsData(array $items) + { + + usort($items, function ($item1, $item2) { + if (!isset($item1['adminSortIndex']) or !isset($item2['adminSortIndex'])) { + return 0; + } + + return $item1['adminSortIndex'] <= $item2['adminSortIndex'] ? -1 : 1; + }); + + return $items; + } }