$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;
+ }
}
}
+
}
$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'] = '';
$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);
}
}
- } 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) {
$matching[] = $product->id;
}
}
- } else if ($data->type == 'numeric_list') {
+ } else if ($data->type === 'numeric_list') {
if (!is_array($v)) {
$v = [$v];
}
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)];
<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('=');