From aa561fd078ba35bfc420b0338a04d6335e5d5824 Mon Sep 17 00:00:00 2001 From: Vincent Vanwaelscappel Date: Tue, 3 Sep 2019 17:10:51 +0200 Subject: [PATCH] Do not filter product with unfilled numeric or range values | wip #2962 @0:10 --- app/Models/Product.php | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/app/Models/Product.php b/app/Models/Product.php index 89d183b..dbede64 100644 --- a/app/Models/Product.php +++ b/app/Models/Product.php @@ -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; } -- 2.39.5