}
- public static function getFilteredProducts($product_type, $filter_values = []) {
+ public static function getFilteredProducts($product_type, $filter_values = [])
+ {
$res = [];
$type = ProductType::find($product_type);
$spec_name = 's_' . Str::snake($filter->name);
$data = $filter->getPageData();
$f = ['label' => $data->label,
- 'id' => $data->id,
- 'type' => $data->type,
+ 'id' => $data->id,
+ 'type' => $data->type,
];
$matching = [];
$res['filters'][$data->id] = $f;
}
- $intersection = call_user_func_array('array_intersect', $all_matches);
+ if (!count($all_matches)) {
+ $intersection = [];
+ } elseif (count($all_matches) == 1) {
+ $intersection = $all_matches[0];
+ } else {
+ $intersection = call_user_func_array('array_intersect', $all_matches);
+ }
+
$res['results'] = ['count' => count($intersection), 'hits' => $intersection];
return $res;
}