From 3629efa76e51026a8a2cf4af40e625a4afc90dd1 Mon Sep 17 00:00:00 2001 From: Vincent Vanwaelscappel Date: Fri, 23 Aug 2019 12:16:05 +0200 Subject: [PATCH] fix #2959 @1 --- app/Models/Product.php | 18 ++++++++++++++---- app/Templates/Catalog.php | 4 ++-- 2 files changed, 16 insertions(+), 6 deletions(-) diff --git a/app/Models/Product.php b/app/Models/Product.php index a87c8ba..2204c89 100644 --- a/app/Models/Product.php +++ b/app/Models/Product.php @@ -14,6 +14,11 @@ class Product extends CubistMagicPageModel protected static $_productTypes = null; protected static $_specificationFields = null; + /** + * @var array + */ + protected $_slugFields = ['slug', 'reference+name']; + protected $table = 'catalog_products'; protected $_options = ['name' => 'product', @@ -279,7 +284,9 @@ class Product extends CubistMagicPageModel } else if ($specEntity->type == 'text') { $specValue = trim($val); } else if ($specEntity->type == 'range') { - + if (!$val['first'] && !$val['second']) { + continue; + } $specValue = $val['first'] . ' ' . __('à') . ' ' . $val['second'] . ' ' . $specEntity->unit; } else if ($specEntity->type == 'list') { $option = Json::decodeRecursive($specEntity->options, Json::TYPE_ARRAY)[$val]; @@ -301,7 +308,8 @@ class Product extends CubistMagicPageModel * Custom accessor to return fallback image * by accessing $product->image_fallback... */ - public function getImageFallbackAttribute() { + public function getImageFallbackAttribute() + { return asset('images/product-details/product-placeholder.svg'); } @@ -309,7 +317,8 @@ class Product extends CubistMagicPageModel * Custom accessor to return main product image (or fallback) * by accessing $product->image... */ - public function getImageAttribute() { + public function getImageAttribute() + { if ($this->images) { $image = $this->getFirstMediaUrl($this->images); @@ -327,7 +336,8 @@ class Product extends CubistMagicPageModel * Fetch selected product data for use in cart Vue component * @return array */ - public static function getCartData() { + public static function getCartData() + { $cart_items = session('cart_items', []); diff --git a/app/Templates/Catalog.php b/app/Templates/Catalog.php index c37ea76..52fd70d 100644 --- a/app/Templates/Catalog.php +++ b/app/Templates/Catalog.php @@ -49,7 +49,7 @@ class Catalog extends TemplateAbstract $category = new Item(); $category->setTitle($productType->name); - $category->setHref($productType->slug); + $category->setHref($productType->getSlugOrTitleAttribute()); $category->setId('product_type_' . $productType->id); $category->setController(['controller' => 'ProductController', 'action' => 'productList', 'params' => ['id' => $productType->id]]); @@ -63,7 +63,7 @@ class Catalog extends TemplateAbstract } $detail = new Item(); $detail->setTitle($product->name); - $detail->setHref($product->slug); + $detail->setHref($product->getSlugOrTitleAttribute()); $detail->setId('product/' . $product->id); $detail->setController(['controller' => 'ProductController', 'action' => 'productDetails', 'params' => ['id' => $product->id]]); $category->addChild($detail); -- 2.39.5