]> _ Git - pmi.git/commitdiff
Do not filter product with unfilled numeric or range values | wip #2962 @0:10
authorVincent Vanwaelscappel <vincent@cubedesigners.com>
Tue, 3 Sep 2019 15:10:51 +0000 (17:10 +0200)
committerVincent Vanwaelscappel <vincent@cubedesigners.com>
Tue, 3 Sep 2019 15:10:51 +0000 (17:10 +0200)
app/Models/Product.php

index 89d183b49448177171f9a7b9b3d0ab110f35870f..dbede64a97d5c7b449d9b7c6b40ab01442b233ca 100644 (file)
@@ -359,7 +359,7 @@ class Product extends CubistMagicPageModel
             $cart_data[] = [
                 'id' => $product->id,
                 'name' => $product->name,
-                'reference'=>$product->reference,
+                'reference' => $product->reference,
                 'category' => $product->type->name,
                 'quantity' => $cart_items[$product->id],
                 'image' => $product->image,
@@ -383,8 +383,10 @@ class Product extends CubistMagicPageModel
 
         $raw_products = Product::where('product_type', $product_type)->where('online', 1)->where('public', 1)->get();
         $products = [];
+        $allids = [];
         foreach ($raw_products as $idx => $raw_product) {
             $products[$idx] = $raw_product->getPageData();
+            $allids[] = $products[$idx]->id;
         }
         $locale = App::getLocale();
 
@@ -461,14 +463,21 @@ class Product extends CubistMagicPageModel
 
                 foreach ($products as $product) {
                     $v = $product->get($spec_name);
+
+                    if(null===$v){
+                        $matching[] = $product->id;
+                        continue;
+                    }
+
                     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);
+
                         if (null !== $filter_value && !($v['first'] == '' && $v['second'] == '')) {
                             $min = min($v['first'], $v['second']);
                             $max = max($v['first'], $v['second']);
 
-                            if ($min <= $filter_value[1] && $max >= $filter_value[0]) {
+                            if (null===$v || ($min <= $filter_value[1] && $max >= $filter_value[0])) {
                                 $matching[] = $product->id;
                             }
                         }
@@ -476,7 +485,7 @@ class Product extends CubistMagicPageModel
                         $f['min'] = min($f['min'], $v);
                         $f['max'] = min($f['max'], $v);
                         if (null !== $filter_value) {
-                            if ($v >= $filter_value[0] && $v <= $filter_value[0]) {
+                            if (null===$v || ($v >= $filter_value[0] && $v <= $filter_value[0])) {
                                 $matching[] = $product->id;
                             }
                         }
@@ -502,7 +511,7 @@ class Product extends CubistMagicPageModel
             $intersection = call_user_func_array('array_intersect', $all_matches);
         }
 
-        $res['results'] = ['count' => count($intersection), 'hits' => $intersection];
+        $res['results'] = ['count' => count($intersection), 'hits' => $intersection, 'notmatching' => array_diff($allids, $intersection)];
         return $res;
     }