]> _ Git - cubeextranet.git/commitdiff
wip #4682 @0.5
authorvincent@cubedesigners.com <vincent@cubedesigners.com@f5622870-0f3c-0410-866d-9cb505b7a8ef>
Mon, 15 Nov 2021 13:32:04 +0000 (13:32 +0000)
committervincent@cubedesigners.com <vincent@cubedesigners.com@f5622870-0f3c-0410-866d-9cb505b7a8ef>
Mon, 15 Nov 2021 13:32:04 +0000 (13:32 +0000)
inc/ws/Util/class.ws.util.php
inc/ws/Util/html5/master/class.ws.html5.compiler.php

index 78a78fbbc2f110ea0f55126aebfc869538d543f6..06f27ded0412cf0489c14b8153dc67f3e2115e2e 100644 (file)
@@ -80,6 +80,47 @@ class wsUtil
         return $res;\r
     }\r
 \r
+    public static function excelToArrayIndexKeyVars($excelFile, $reader = 'Excel2007', $skipEmptyId = false)\r
+    {\r
+        global $core;\r
+\r
+        $e = explode('#', $excelFile);\r
+        $excelFile = $e[0];\r
+\r
+        $worksheets = self::excelToArray($excelFile, false, $reader);\r
+\r
+        if (isset($e[1])) {\r
+            $sheetName = trim($e[1]);\r
+        }\r
+\r
+        if (isset($sheetName, $worksheets[$sheetName])) {\r
+            $worksheet = $worksheets[$sheetName];\r
+        } else {\r
+            $worksheet = array_shift($worksheets);\r
+        }\r
+\r
+        $res = [];\r
+        foreach ($worksheet as $i => $line) {\r
+            if ($i === 0) {\r
+                $vars = [];\r
+                foreach ($line as $j => $varname) {\r
+                    $vars[$j] = $varname;\r
+                }\r
+            } else {\r
+                if (trim(implode('', $line)) == '') {\r
+                    continue;\r
+                }\r
+                $r = [];\r
+                foreach ($vars as $j => $varname) {\r
+                    $r[$varname] = trim($line[$j]);\r
+                }\r
+                $res[] = $r;\r
+            }\r
+        }\r
+\r
+        return $res;\r
+    }\r
+\r
     public static function excelToArrayKeyVars($excelFile, $reader = 'Excel2007', $skipEmptyId = false)\r
     {\r
         global $core;\r
@@ -97,9 +138,11 @@ class wsUtil
         if (isset($sheetName, $worksheets[$sheetName])) {\r
             $worksheet = $worksheets[$sheetName];\r
         } else {\r
-            $worksheet = array_unshift($worksheets);\r
+            $worksheet = array_shift($worksheets);\r
         }\r
 \r
+\r
+\r
         $res = [];\r
         foreach ($worksheet as $i => $line) {\r
             if ($i === 0) {\r
index 4aa34128934f6de28961bb50ddf0deb339e22744..851d51e0e3977d5c6ad5b42f6184756bfb95bce0 100644 (file)
@@ -670,7 +670,10 @@ class wsHTML5Compiler
         $this->addVideoJs();
 
         $this->config->basketReferences = wsUtil::excelToArrayKeyVars($this->wdir . 'commerce/' . $this->book->parametres->basketReferences);
-        $this->config->eanReferences = wsUtil::excelToArrayKeyVars($this->wdir . 'commerce/ean.xlsx');
+        $eanFile = $this->wdir . 'commerce/ean.xlsx';
+        if (file_exists($eanFile)) {
+            $this->config->eanReferences = wsUtil::excelToArrayIndexKeyVars($eanFile);
+        }
 
         wsLinks::getLinksAndRulersFromFile($this->book_id, $links, $rulers);
         foreach ($links as $link) {