From f9fa25f75c14aa96a742afad98758902d712aff0 Mon Sep 17 00:00:00 2001 From: Stephen Cameron Date: Tue, 10 Sep 2019 19:00:33 +0200 Subject: [PATCH] Done #3024 @1.5 --- app/Models/Product.php | 9 +++++++-- resources/js/components/ProductsFilters.vue | 19 +++++++++++++------ 2 files changed, 20 insertions(+), 8 deletions(-) diff --git a/app/Models/Product.php b/app/Models/Product.php index 2ff9657..4e262af 100644 --- a/app/Models/Product.php +++ b/app/Models/Product.php @@ -400,7 +400,12 @@ class Product extends CubistMagicPageModel $all_matches = []; - $filters = Specification::whereIn('id', $specifications)->get(); + // Ensure that filters are returned in the order they are defined in the backend + // Ref: https://stackoverflow.com/a/26704767 + $spec_IDs_ordered = implode(',', $specifications); + $filters = Specification::whereIn('id', $specifications) + ->orderByRaw("FIELD(id, $spec_IDs_ordered)") + ->get(); $res['filters'] = []; foreach ($filters as $filter) { @@ -513,7 +518,7 @@ class Product extends CubistMagicPageModel $f['matching'] = ['count' => count($matching), 'hits' => $matching]; $all_matches[] = $matching; - $res['filters'][$data->id] = $f; + $res['filters'][] = $f; } if (!count($all_matches)) { diff --git a/resources/js/components/ProductsFilters.vue b/resources/js/components/ProductsFilters.vue index 437a161..9663d6f 100644 --- a/resources/js/components/ProductsFilters.vue +++ b/resources/js/components/ProductsFilters.vue @@ -7,7 +7,7 @@
-
+

@@ -64,9 +64,9 @@