]> _ Git - fluidbook-toolbox.git/commitdiff
wip #6554 @2
authorVincent Vanwaelscappel <vincent@cubedesigners.com>
Tue, 19 Dec 2023 19:05:54 +0000 (20:05 +0100)
committerVincent Vanwaelscappel <vincent@cubedesigners.com>
Tue, 19 Dec 2023 19:05:54 +0000 (20:05 +0100)
app/Fluidbook/Compiler/Cart.php
app/Fluidbook/Link/Cart/PumaCartLink.php

index 6ebd0f7c90d006f0c05c73eff84e35aa0dfa237c..722bfd866c3f3e8a5bd1f95d74d05d66ec78ff6e 100644 (file)
@@ -260,16 +260,32 @@ trait Cart
     }
 
 
+    public function writePumaSECart()
+    {
+
+        $this->lessVariables['import-cart-styles'] = 'puma-se';
+        $this->addJsLib('puma-se', 'js/libs/fluidbook/cart/fluidbook.cart.puma-se.js');
+
+        $this->_commonPuma();
+
+    }
+
+
     /**
      * @throws \Exception
      */
     public function writePumaCart()
     {
         $this->lessVariables['import-cart-styles'] = 'puma';
+        $this->addJsLib('puma', 'js/libs/fluidbook/cart/fluidbook.cart.puma.js');
 
+        $this->_commonPuma();
+    }
+
+    protected function _commonPuma()
+    {
         $this->addJsLib('parsley', 'js/libs/parsley.min.js');
         $this->addJsLib('cookie', 'js/libs/jquery/jquery.cookie.js');
-        $this->addJsLib('puma', 'js/libs/fluidbook/cart/fluidbook.cart.puma.js');
         $this->addJsLib('html2pdf', 'js/libs/html2pdf/html2pdf.min.js');
         $this->addJsLib('exceljs', 'js/libs/exceljs.min.js');
         $this->addVideoJs();
@@ -324,6 +340,50 @@ trait Cart
         }
         $this->log('Puma product zoom done');
 
+
+        $aliases = [];
+        if (file_exists($this->wdir . 'commerce/aliases.txt')) {
+            $lines = explode("\n", file_get_contents($this->wdir . 'commerce/aliases.txt'));
+            foreach ($lines as $line) {
+                $bases = [];
+                $refs = explode('/', trim($line));
+                foreach ($cartReferences as $ref => $d) {
+                    if (str_starts_with($ref, $refs[0])) {
+                        $bases[] = $ref;
+                    }
+                }
+                if (!count($bases)) {
+                    continue;
+                }
+
+                for ($i = 1; $i < count($refs); $i++) {
+                    foreach ($cartReferences as $ref => $d) {
+                        if (!str_starts_with($ref, $refs[$i])) {
+                            continue;
+                        }
+                        $foundColor = false;
+                        foreach ($bases as $base) {
+                            if (substr($ref, -2) === substr($base, -2)) {
+                                $aliases[$ref] = $base;
+                                $foundColor = true;
+                                break;
+                            }
+                        }
+                        if (!$foundColor) {
+                            $aliases[$ref] = $bases[0];
+                        }
+                    }
+                }
+            }
+        }
+
+        foreach ($aliases as $alias => $base) {
+            $cartReferences[$alias]['zoom_image'] = $cartReferences[$base]['zoom_image'];
+            $cartReferences[$alias]['zoom_image_ratio'] = $cartReferences[$base]['zoom_image_ratio'];
+        }
+
+        $this->log('Puma aliases handled');
+
         $this->config->setRaw('product_zoom_references', $productZoomReferences);
         $this->config->setRaw('basketReferences', $cartReferences);
 
@@ -472,6 +532,7 @@ trait Cart
         }
     }
 
+
     public function writeCartConfig()
     {
         if ($this->fluidbookSettings->cartLinkAppearance == 'overlay') {
@@ -490,6 +551,9 @@ trait Cart
                 case 'Puma':
                     $this->writePumaCart();
                     return;
+                case 'Puma-SE':
+                    $this->writePumaSECart();
+                    return;
                 case 'MIF':
                     $this->writeMIFCart();
                     return;
index f5277c3a339a3578fa7cb5afb5b9d9ca181b2567..48e27a8f93df8e463a5e3f39360b83854cf13e44 100644 (file)
@@ -4,7 +4,7 @@ namespace App\Fluidbook\Link\Cart;
 
 use Fluidbook\Tools\Links\CartLink;
 
-class PumaCartLink extends cartLink
+class PumaCartLink extends CartLink
 {
     public function getInnerContent()
     {
@@ -30,10 +30,14 @@ class PumaCartLink extends cartLink
 </svg>';
     }
 
+
     public function getAdditionnalContent()
     {
+        $removeTooltip = $this->to === 'auto:all_in_page' ? 'remove all page products from cart' : 'remove from cart';
+
         $res = parent::getAdditionnalContent();
-        $res .= ' data-tooltip-conditional="' . htmlspecialchars(json_encode(['.active' => 'remove from cart'])) . '" ';
+        $res .= ' data-tooltip-conditional="' . htmlspecialchars(json_encode(['.active' => $removeTooltip])) . '" ';
+
         return $res;
     }
 }