From: Stephen Cameron Date: Wed, 17 Jul 2019 08:54:06 +0000 (+0200) Subject: Fix exceptions on product detail pages. WIP #2768 @0.25 X-Git-Url: http://git.cubedesigners.com/?a=commitdiff_plain;h=418cc1b56fe777e944c683f5cd5a9fbde953245e;p=pmi.git Fix exceptions on product detail pages. WIP #2768 @0.25 --- diff --git a/app/Http/Controllers/ProductController.php b/app/Http/Controllers/ProductController.php index 9dab2d9..5859053 100644 --- a/app/Http/Controllers/ProductController.php +++ b/app/Http/Controllers/ProductController.php @@ -39,8 +39,10 @@ class ProductController extends CubistFrontController $this->data['title'] = $product->name; $this->data['product'] = $product->getPageData(); $this->data['related'] = []; - foreach (Product::whereIn('id', $product->related)->limit(4)->get() as $rel) { - $this->data['related'][] = $rel->getPageData(); + if (is_array($product->related) && count($product->related) > 0) { + foreach (Product::whereIn('id', $product->related)->limit(4)->get() as $rel) { + $this->data['related'][] = $rel->getPageData(); + } } return view('pages.product-detail', $this->data); } diff --git a/app/Models/Product.php b/app/Models/Product.php index 14ae328..0dbf938 100644 --- a/app/Models/Product.php +++ b/app/Models/Product.php @@ -261,6 +261,11 @@ class Product extends CubistMagicModel $specEntity = $allspecs[$spec]; $val = Json::decodeRecursive($this->{'s_' . Str::snake($specEntity->name)}, Json::TYPE_ARRAY); + + if (null === $val) { + continue; + } + $specValue = ' - '; if ($specEntity->type == 'numeric' || $specEntity->type == 'numeric_list') { $specValue = $specEntity->prefix;