]> _ Git - pmi.git/commitdiff
done #3506 @0:20
authorVincent Vanwaelscappel <vincent@cubedesigners.com>
Tue, 17 Mar 2020 16:31:07 +0000 (17:31 +0100)
committerVincent Vanwaelscappel <vincent@cubedesigners.com>
Tue, 17 Mar 2020 16:31:07 +0000 (17:31 +0100)
app/Models/Product.php
resources/js/components/ProductsFilters.vue

index 0680da95f0944461e0218f018aab9601544d9117..87d95878b0114c21f38000376696a64ee40637dd 100644 (file)
@@ -479,33 +479,40 @@ class Product extends CubistMagicPageModel
 
             $matching = [];
 
-            if ($data->type == 'list') {
+            if ($data->type === 'list' || $data->type === 'mlist') {
                 $options = [];
                 $values = [];
 
                 foreach ($products as $product) {
 
-                    $v = $product->get($spec_name);
+                    $pv = $product->get($spec_name);
 
-                    if (is_array($v)) {
-                        $v = null;
+                    if (is_array($pv) && $data->type === 'list') {
+                        $pv = null;
                     }
-                    if (null === $v) {
-                        $v = '-';
+                    if (null === $pv) {
+                        $pv = '-';
                     }
 
-                    if (!isset($values[$v])) {
-                        $values[$v] = 0;
+                    if (!is_array($pv)) {
+                        $pv = [$pv];
                     }
-                    $values[$v]++;
-                    if (null === $filter_value) {
-                        $matching[] = $product->id;
-                    } else {
-                        if (in_array($v, $filter_value)) {
+
+                    foreach ($pv as $v) {
+                        if (!isset($values[$v])) {
+                            $values[$v] = 0;
+                        }
+                        $values[$v]++;
+                        if (null === $filter_value) {
                             $matching[] = $product->id;
+                        } else {
+                            if (in_array($v, $filter_value)) {
+                                $matching[] = $product->id;
+                            }
                         }
                     }
 
+
                 }
 
 
@@ -526,14 +533,14 @@ class Product extends CubistMagicPageModel
                     $options['-'] = ['label' => 'Non défini', 'value' => '-', 'nb_products' => $values['-']];
                 }
                 $f['options'] = $options;
-            } else if ($data->type == 'numeric' || $data->type == 'range' || $data->type == 'numeric_list') {
+            } else if ($data->type === 'numeric' || $data->type === 'range' || $data->type === 'numeric_list') {
                 $f['min'] = INF;
                 $f['max'] = -INF;
                 $f['unit'] = $data->unit;
                 $f['type'] = 'range';
                 $f['scale'] = $data->logarithmic_scale ? 'log' : 'linear';
 
-                if ($data->type == 'numeric' || $data->type == 'numeric_list') {
+                if ($data->type === 'numeric' || $data->type === 'numeric_list') {
                     $f['prefix'] = $data['prefix'];
                 } else {
                     $f['prefix'] = '';
@@ -556,12 +563,12 @@ class Product extends CubistMagicPageModel
                         $fvmin = PHP_INT_MIN;
                     }
 
-                    if ($f['scale'] == 'log') {
+                    if ($f['scale'] === 'log') {
                         $fvmax = safeExp($fvmax);
                         $fvmin = safeExp($fvmin);
                     }
 
-                    if ($data->type == 'range') {
+                    if ($data->type === 'range') {
                         $f['min'] = min($f['min'], $v['first'] ?? INF, $v['second'] ?? INF);
                         $f['max'] = max($f['max'], $v['first'] ?? -INF, $v['second'] ?? -INF);
 
@@ -575,7 +582,7 @@ class Product extends CubistMagicPageModel
                             }
 
                         }
-                    } else if ($data->type == 'numeric') {
+                    } else if ($data->type === 'numeric') {
                         $f['min'] = min($f['min'], $v);
                         $f['max'] = max($f['max'], $v);
                         if (null !== $filter_value) {
@@ -583,7 +590,7 @@ class Product extends CubistMagicPageModel
                                 $matching[] = $product->id;
                             }
                         }
-                    } else if ($data->type == 'numeric_list') {
+                    } else if ($data->type === 'numeric_list') {
                         if (!is_array($v)) {
                             $v = [$v];
                         }
@@ -622,10 +629,10 @@ class Product extends CubistMagicPageModel
 
         if (!count($all_matches)) {
             $intersection = [];
-        } elseif (count($all_matches) == 1) {
+        } elseif (count($all_matches) === 1) {
             $intersection = $all_matches[0];
         } else {
-            $intersection = call_user_func_array('array_intersect', $all_matches);
+            $intersection = array_intersect(...$all_matches);
         }
 
         $res['results'] = ['count' => count($intersection), 'hits' => $intersection, 'notmatching' => array_diff($allids, $intersection)];
index c740cd5536e7fd67600e52efb3efbd73dfb4a989..0675f63f2aadfe7b8a80fc3e068c5dd1cb9d138f 100644 (file)
@@ -14,7 +14,7 @@
 
                     <h3 class="text-base mb-2 whitespace-normal">{{ filter.label }}</h3>
 
-                    <ul v-if="filter.type === 'list'">
+                    <ul v-if="filter.type === 'list' || filter.type === 'mlist'">
                         <li v-for="(option, option_index) in filter.options" :key="option_index"
                             class="flex justify-between py-1 text-sm">
 
                 const querystring = location.search.substring(1); // Get querystring minus first character (?)
 
                 if (querystring.length > 0) {
-                    querystring.split('&').forEach(function(pair) {
+                    querystring.split('&').forEach(function (pair) {
 
                         let [key, value] = pair.split('=');