]> _ Git - pmi.git/commitdiff
fix #2991 @0:10
authorVincent Vanwaelscappel <vincent@cubedesigners.com>
Thu, 29 Aug 2019 14:28:55 +0000 (16:28 +0200)
committerVincent Vanwaelscappel <vincent@cubedesigners.com>
Thu, 29 Aug 2019 14:28:55 +0000 (16:28 +0200)
app/Models/Product.php

index fbc4f34311a84e60ae2afba26f36aff2983d5859..64c28404f763fea37d4276d495ee7658baf62d83 100644 (file)
@@ -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;
     }