From: Vincent Vanwaelscappel Date: Thu, 29 Aug 2019 14:28:55 +0000 (+0200) Subject: fix #2991 @0:10 X-Git-Url: http://git.cubedesigners.com/?a=commitdiff_plain;h=259aa748bb47b0e99db81173ed2abaa5e610d9c2;p=pmi.git fix #2991 @0:10 --- diff --git a/app/Models/Product.php b/app/Models/Product.php index fbc4f34..64c2840 100644 --- a/app/Models/Product.php +++ b/app/Models/Product.php @@ -370,7 +370,8 @@ class Product extends CubistMagicPageModel } - public static function getFilteredProducts($product_type, $filter_values = []) { + public static function getFilteredProducts($product_type, $filter_values = []) + { $res = []; $type = ProductType::find($product_type); @@ -403,8 +404,8 @@ class Product extends CubistMagicPageModel $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 = []; @@ -492,7 +493,14 @@ class Product extends CubistMagicPageModel $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; }