]> _ Git - fluidbook-toolbox.git/commitdiff
wip #6864
authorVincent Vanwaelscappel <vincent@cubedesigners.com>
Tue, 16 Apr 2024 09:35:54 +0000 (11:35 +0200)
committerVincent Vanwaelscappel <vincent@cubedesigners.com>
Tue, 16 Apr 2024 09:35:54 +0000 (11:35 +0200)
app/Fluidbook/Compiler/Cart.php
app/Models/Traits/PublicationSettings.php

index 16d28177e3099bff4adb9ceacca3455b611e08f8..505dca27d5c403f6fb2b2916a1c4e3a6031ef019 100644 (file)
@@ -564,6 +564,81 @@ trait Cart
         }
     }
 
+    /**
+     * @throws \Exception
+     */
+    public function writeBastideResahCart()
+    {
+
+        $this->lessVariables['import-cart-styles'] = 'bastide-resah';
+
+        $this->addJsLib('bastide', 'js/libs/fluidbook/cart/fluidbook.cart.bastide-resah.js');
+
+
+        if (!empty($this->config->basketReferences)) {
+            if (file_exists($this->config->basketReferences) || Url::isDistant($this->config->basketReferences)) {
+                $referencesFile = $this->config->basketReferences;
+            } else {
+                $referencesFile = $this->wdir . 'commerce/' . $this->config->basketReferences;
+            }
+        }
+
+        $references = [];
+
+        if (file_exists($referencesFile) || Url::isDistant($referencesFile)) {
+            $rows = ExcelToArray::excelToArrayFirstSheet($referencesFile);
+
+            // Expected headings are: n° page, Chapitre, Article Code, Article, Conditionnement
+            $column_headings = array_shift($rows); // We assume the first row will be the headings, so we slice it off
+            $column_headings = array_map(function ($heading) { // Normalise the headings, removing extra spaces and line breaks
+                return trim(strtoupper(preg_replace('/\s+/', ' ', $heading)));
+            }, $column_headings);
+
+            foreach ($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);
+
+                // The ARTICLE CODE is required, so if it doesn't exist, we can assume it's not a valid row
+                if (empty($row['ARTICLE CODE'])) {
+                    continue;
+                }
+
+                $references[$row['ARTICLE CODE']] = $row;
+            }
+
+        }
+
+        $this->config->basketReferences = $references;
+
+        // Allow individual Fluidbooks to override the columns shown in the cart
+        $extra = Link::parseExtras($this->config->cartExtraSettings, true);
+
+        if (!empty($extra['cart_columns'])) {
+            // In the "Paramètres panier" field (cartExtraSettings), the cart columns can be defined in this format:
+            // cart_columns=XLS COL NAME|Display name,XLS COL 2|Display name 2
+            // This setting needs to be trimmed and converted into an associative array with column_name => display_name
+            // Split by commas, then by pipes |
+            $columns = array_map(function ($heading) {
+                return explode('|', $heading);
+            }, explode(',', $extra['cart_columns']));
+            $processed_columns = [];
+            foreach ($columns as $column) {
+                $processed_columns[strtoupper(trim($column[0]))] = trim($column[1] ?? '');
+            }
+
+            // Ensure that special QUANTITY and DELETE columns are present (see getColumns() in fluidbook.cart.bastide.js)
+            $processed_columns['QUANTITY'] = $processed_columns['QUANTITY'] ?? 'Quantité';
+            $processed_columns['DELETE'] = '';
+
+            $this->config->cartColumns = $processed_columns;
+        }
+    }
+
+
 
     public function writeCartConfig()
     {
@@ -614,6 +689,9 @@ trait Cart
                 case 'Bastide':
                     $this->writeBastideCart();
                     break;
+                case 'BastideResah':
+                    $this->writeBastideResahCart();
+                    break;
                 default:
                     break;
             }
index 8361d803fd436df7d26a42dfd5ec77752683d453..8461d50ac5aa171055c71f73d5ab537e039b4c02 100644 (file)
@@ -1690,6 +1690,7 @@ trait PublicationSettings
                 'Thiriet' => 'Thiriet',
                 'CFOC' => 'CFOC',
                 'Bastide' => 'Bastide',
+                'BastideResah' => 'Bastide Resah'
             ],
             'default' => 'com.fluidbook.player.basket.BasketManager',
         ]);