From: Vincent Vanwaelscappel Date: Tue, 17 Mar 2020 16:31:07 +0000 (+0100) Subject: done #3506 @0:20 X-Git-Url: http://git.cubedesigners.com/?a=commitdiff_plain;h=52fbd8ac780f01ea14e5022f951d661223497724;p=pmi.git done #3506 @0:20 --- diff --git a/app/Models/Product.php b/app/Models/Product.php index 0680da9..87d9587 100644 --- a/app/Models/Product.php +++ b/app/Models/Product.php @@ -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)]; diff --git a/resources/js/components/ProductsFilters.vue b/resources/js/components/ProductsFilters.vue index c740cd5..0675f63 100644 --- a/resources/js/components/ProductsFilters.vue +++ b/resources/js/components/ProductsFilters.vue @@ -14,7 +14,7 @@

{{ filter.label }}

-