From 2e38e16d2cea38a3f0ea2fce9376be530e353281 Mon Sep 17 00:00:00 2001 From: Vincent Vanwaelscappel Date: Tue, 17 Mar 2020 17:14:02 +0100 Subject: [PATCH] wip #3506 @0:10 --- app/Models/Product.php | 36 ++++++++++++++++++++++++++++-------- 1 file changed, 28 insertions(+), 8 deletions(-) diff --git a/app/Models/Product.php b/app/Models/Product.php index 2394b98..0680da9 100644 --- a/app/Models/Product.php +++ b/app/Models/Product.php @@ -317,17 +317,21 @@ class Product extends CubistMagicPageModel continue; } $options = Json::decodeRecursive($specEntity->options, Json::TYPE_ARRAY); - if (!isset($options[$val])) { + $specValue = $this->_optionValue($options, $val); + if (null === $specValue) { continue; } - $option = $options[$val]; - - $locale = App::getLocale(); - if (!isset($option[$locale]) || !$option[$locale]) { - $specValue = $option['fr'] ?? ''; - } else { - $specValue = $option[$locale]; + } else if ($specEntity->type === 'mlist') { + $options = Json::decodeRecursive($specEntity->options, Json::TYPE_ARRAY); + $thisSpecs = []; + foreach ($val as $v) { + $r = $this->_optionValue($options, $v); + if ($r === null) { + continue; + } + $thisSpecs[] = $r; } + $specValue = implode(', ', $thisSpecs); } $res[$specEntity->label] = $specValue; } @@ -335,6 +339,22 @@ class Product extends CubistMagicPageModel } + protected function _optionValue($options, $val) + { + if (!isset($options[$val])) { + return null; + } + $option = $options[$val]; + + $locale = App::getLocale(); + if (!isset($option[$locale]) || !$option[$locale]) { + $specValue = $option['fr'] ?? ''; + } else { + $specValue = $option[$locale]; + } + return $specValue; + } + /** * Custom accessor to return URL to product detail * page by accessing $product->URL... -- 2.39.5