]> _ Git - cubeextranet.git/commitdiff
wait #5307
authorvincent@cubedesigners.com <vincent@cubedesigners.com@f5622870-0f3c-0410-866d-9cb505b7a8ef>
Tue, 7 Jun 2022 19:52:24 +0000 (19:52 +0000)
committervincent@cubedesigners.com <vincent@cubedesigners.com@f5622870-0f3c-0410-866d-9cb505b7a8ef>
Tue, 7 Jun 2022 19:52:24 +0000 (19:52 +0000)
inc/ws/Util/class.ws.tools.php
inc/ws/Util/html5/master/class.ws.html5.compiler.php
inc/ws/Util/html5/master/class.ws.html5.links.php

index bd2aa013200690d720e0efdb375e55a807b298a3..57701cfbc264da838c350462427abbe0784f626c 100644 (file)
@@ -82,10 +82,16 @@ class wsTools
             $svg = file_get_contents($in);
         }
         $svg = self::_disablePreserveRatio($svg);
+        $svg = self::_removeForeignObjects($svg);
         file_put_contents($out, $svg);
         return $out;
     }
 
+    protected static function _removeForeignObjects($svg)
+    {
+        return preg_replace('/<foreignObject(.*)\/>/U', '', $svg);
+    }
+
     protected static function _disablePreserveRatio($in)
     {
         $str = 'preserveAspectRatio="none"';
index f3d829951ff1d2536ec8dee5426744da8458d7de..1058b78ae073e5df39151b62305db82c28264d69 100644 (file)
@@ -756,6 +756,68 @@ class wsHTML5Compiler
         $this->addJsLib('thiriet', 'js/libs/fluidbook/cart/fluidbook.cart.thiriet.js');
     }
 
+    public function writeCFOCCart()
+    {
+
+        $this->lessVariables['import-cart-styles'] = 'cfoc';
+
+        $this->addJsLib('cfoc', 'js/libs/fluidbook/cart/fluidbook.cart.cfoc.js');
+
+        // NOTE: $this->config->basketReferences initially contains the uploaded filename and if we don't
+        // modify it, the writeCartConfig() function will replace it with the extracted data from the spreadsheet 🤐
+        // It would be much better if the extracted data had its own variable but it would break too many things to
+        // change it now, so we'll follow the same approach.
+
+        if (!empty($this->config->basketReferences)) {
+            if (file_exists($this->config->basketReferences) || CubeIT_Util_Url::isDistant($this->config->basketReferences)) {
+                $referencesFile = $this->config->basketReferences;
+            } else {
+                $referencesFile = $this->wdir . 'commerce/' . $this->config->basketReferences;
+            }
+        }
+
+        $references = [];
+
+        if (file_exists($referencesFile) || CubeIT_Util_Url::isDistant($referencesFile)) {
+            $raw_data = wsUtil::excelToArray($referencesFile);
+            $first_sheet_rows = reset($raw_data); // First sheet's data will be returned since it's the first array element
+
+            // Expected headings are: EXCLU, LIGNE, EAN, REF, DESIGNATION, COULEUR, QTE MINI, PRIX TTC
+            $column_headings = array_shift($first_sheet_rows); // We assume the first row will be the headings, so we slice it off
+            $column_headings = array_map(function ($heading) { // Clean the headings a bit
+                return trim(strtoupper($heading));
+            }, $column_headings);
+
+            foreach ($first_sheet_rows as $row) {
+
+                // First, trim values in case there are any stray spaces
+                $row = array_map('trim', $row);
+
+                // Next, set the headings as keys to make it easier to refer to the row values by name
+                $row = array_combine($column_headings, $row);
+
+                // For the 'EXCLU' field, this should be converted to a boolean
+                $row['EXCLU'] = ('exclu boutique' === $row['EXCLU']);
+
+                // The EAN and REF are required, so if they don't exist, we can assume it's not a valid row
+                if (empty($row['EAN']) || empty($row['REF'])) {
+                    continue;
+                }
+
+                $references[$row['REF']][$row['EAN']] = $row;
+            }
+
+        }
+
+        $this->config->basketReferences = $references;
+
+        // It's possible to use the cartExtraSettings field in the parameters to define publication specific settings,
+        // such as the subject line used in the e-mail that is sent from the cart validation
+        $extra = wsHTML5Link::parseExtras($this->book->parametres->cartExtraSettings, true);
+
+        $this->config->cartEmailSubject = $extra['email_subject'] ?? 'Récapitulatif de votre commande CFOC';
+    }
+
     public function writeCartConfig()
     {
         if ($this->book->parametres->cartLinkAppearance == 'overlay') {
@@ -789,6 +851,9 @@ class wsHTML5Compiler
                     $this->addJsLib('cookie', 'js/libs/jquery/jquery.cookie.js');
                     $this->addJsLib('mopec', 'js/libs/fluidbook/cart/fluidbook.cart.mopec.js');
                     break;
+                case 'CFOC':
+                    $this->writeCFOCCart();
+                    break;
                 default:
                     break;
             }
@@ -2091,7 +2156,7 @@ height="0" width="0" style="display:none;visibility:hidden"></iframe></noscript>
                 $dupData = $linkData;
                 $dupData['image'] = '';
                 $dupData['animation'] = '';
-                $dupData['to'] = $linkData['image'];
+                $dupData['to'] = self::_SVGCleanAsset($linkData['image']);
                 if ($dupData['image_rollover'] != 'none' && !stristr($dupData['image_rollover'], '=')) {
                     $dupData['rollover'] = $dupData['image_rollover'];
                 }
@@ -2623,6 +2688,22 @@ height="0" width="0" style="display:none;visibility:hidden"></iframe></noscript>
         }
     }
 
+    protected function _SVGCleanAsset($a)
+    {
+        if (!stristr($a, '.svg')) {
+            return $a;
+        }
+        $clean = str_replace('.svg', '.o.svg', $a);
+        $path = $this->wdir . '/' . $a;
+        $opt = $this->wdir . '/' . $clean;
+
+        if (!file_exists($opt) || !filesize($opt) || filemtime($path) > filemtime($opt)) {
+            wsTools::_optimizeSVG($path, $opt);
+        }
+        return $clean;
+
+    }
+
     public function supportSVG()
     {
         if (!$this->phonegap) {
index 710f1326dac3aadd95b3d5c5af42f14097c1bf9a..0b79db4ef3de0674d00cb61d6504755869493624 100644 (file)
@@ -177,14 +177,13 @@ class wsHTML5Link
                 return new webVideoLink($id, $init, $compiler);
             case 11:
                 return new actionLink($id, $init, $compiler);
-            case 12:
-                if ($compiler->book->parametres->basketManager === 'Puma' || $compiler->book->parametres->basketManager === 'MIF' || $compiler->book->parametres->basketManager === 'Flexipan') {
-                    return new zoomProductLink($id, $init, $compiler);
-                }
+            case 12: // Basket / Cart links
                 if ($compiler->book->parametres->product_zoom_references !== '') {
                     return new zoomProductLink($id, $init, $compiler);
                 }
                 switch ($compiler->book->parametres->basketManager) {
+                    case 'CFOC':
+                        return new CFOCCartLink($id, $init, $compiler);
                     case 'GrandVision':
                         return new grandVisionCartLink($id, $init, $compiler);
                     case 'GrandPavois':
@@ -196,6 +195,9 @@ class wsHTML5Link
                     case 'Remarkable':
                         return new remarkableCartLink($id, $init, $compiler);
                     case 'ZoomProductLink':
+                    case 'Flexipan':
+                    case 'Puma':
+                    case 'MIF':
                         return new zoomProductLink($id, $init, $compiler);
                     default :
                         return new cartLink($id, $init, $compiler);
@@ -1737,6 +1739,24 @@ class cartLink extends normalLink
     }
 }
 
+class CFOCCartLink extends normalLink
+{
+    public function getUrl()
+    {
+        return '#/cart/add/' . $this->to;
+    }
+
+    // public function getAdditionnalContent()
+    // {
+    //     return parent::getAdditionnalContent() . ' data-cfoc-ref="' . $this->to . '" ';
+    // }
+
+    public function getTooltip()
+    {
+        return 'Ajouter à ma sélection';
+    }
+}
+
 class remarkableCartLink extends cartLink
 {
 
@@ -1744,7 +1764,7 @@ class remarkableCartLink extends cartLink
 
 class layerLink extends imageLink
 {
-    protected $maxzoom_default = 2;
+    protected $maxzoom_default = 1;
     public $defaultZIndex = 31;
 
     public function ignore()