]> _ Git - pmi.git/commitdiff
wip #3506 @0:10
authorVincent Vanwaelscappel <vincent@cubedesigners.com>
Tue, 17 Mar 2020 16:14:02 +0000 (17:14 +0100)
committerVincent Vanwaelscappel <vincent@cubedesigners.com>
Tue, 17 Mar 2020 16:14:02 +0000 (17:14 +0100)
app/Models/Product.php

index 2394b9833113c1c8d225b6bf461c7013b202b850..0680da95f0944461e0218f018aab9601544d9117 100644 (file)
@@ -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...