]> _ Git - fluidbook-html5.git/commitdiff
wait #4682 @2
authorVincent Vanwaelscappel <vincent@cubedesigners.com>
Mon, 15 Nov 2021 13:32:18 +0000 (14:32 +0100)
committerVincent Vanwaelscappel <vincent@cubedesigners.com>
Mon, 15 Nov 2021 13:32:18 +0000 (14:32 +0100)
js/libs/fluidbook/cart/fluidbook.cart.puma.js

index e317206f602bea537dffd40aed81c54478be3b7c..7254be2aae50bcc3dc17d40d193a24ae322a912b 100644 (file)
@@ -23,6 +23,14 @@ FluidbookCartPuma.prototype = {
             }
             return false;
         });
+        $(document).on(this.fluidbook.input.clickEvent, '.exportEANXLS', function () {
+            try {
+                $this.exportEANXLS();
+            } catch (err) {
+                console.log(err);
+            }
+            return false;
+        });
 
         $(document).on(this.fluidbook.input.clickEvent, '.emptyCart', function () {
             $.confirm({
@@ -82,12 +90,15 @@ FluidbookCartPuma.prototype = {
         this.fluidbook.cache.set('cart', this.getItems());
         this.fluidbook.cart.updateLinks();
     },
+
     getItemsReferences: function () {
         return this.getItems();
     },
+
     getItemsNumbers: function () {
         return this.getItems().length;
     },
+
     getAllQuantities: function () {
         return this.getItemsNumbers();
     },
@@ -121,7 +132,6 @@ FluidbookCartPuma.prototype = {
         return ['Image', 'Catalogue', 'Catégorie', 'Ligne', 'Sexe', 'Modèle', 'Couleur', 'Désignation', 'Tailles', 'Tarif', 'PVC', 'PACK'];
     },
 
-
     getItems: function () {
         var res = [];
         var $this = this;
@@ -183,12 +193,17 @@ FluidbookCartPuma.prototype = {
         content += '</tbody>';
         content += '</table>';
         content += '<div class="cart-footer">';
-        content += '<div class="fonctions"><a href="#" class="emptyCart">Empty my cart</a><a href="#" class="exportCartPDF">Export my cart (PDF)</a><a href="#" class="exportCartXLS">Export my cart (XLS)</a></div>';
+        var ean = '';
+        if (this.fluidbook.settings.eanReferences) {
+            ean = '<a href="#" class="exportEANXLS">EAN Export (XLS)</a>';
+        }
+        content += '<div class="fonctions"><a href="#" class="emptyCart">Empty my cart</a><a href="#" class="exportCartPDF">Export (PDF)</a><a href="#" class="exportCartXLS">Export (XLS)</a>' + ean + '</div>';
         content += '</div>';
 
         return content;
     },
 
+
     exportPDF: function () {
 
         var element = $('#pumacarttable').get(0);
@@ -209,9 +224,60 @@ FluidbookCartPuma.prototype = {
         }, 2000);
     },
 
-    getExportFileName: function () {
+    getExportFileName: function (label) {
+        if (label === undefined) {
+            label = 'Cart';
+        }
         var date = new Date();
-        return this.fluidbook.settings.title + ' - Cart - ' + date.getFullYear() + '-' + date.getMonth() + '-' + date.getDate();
+        return this.fluidbook.settings.title + ' - ' + label + ' - ' + date.getFullYear() + '-' + date.getMonth() + '-' + date.getDate();
+    },
+
+    exportEANXLS: function () {
+        var $this = this;
+        const workbook = new ExcelJS.Workbook();
+        const sheet = workbook.addWorksheet(this.fluidbook.settings.title);
+        sheet.views = [
+            {state: 'frozen', xSplit: 0, ySplit: 1, topLeftCell: 'A2', activeCell: 'A2'}
+        ];
+        sheet.properties.defaultRowHeight = 15;
+        var columnsLabels = ['Reference', 'Size Description', 'EAN13', 'Season Description', 'Rbu', 'Family', 'Article', 'Model Id', 'Color Id'];
+        var columns = [];
+
+        $.each(columnsLabels, function (k, v) {
+            columns.push({
+                header: v,
+                key: v,
+                numFmt: '@',
+                style: {numFmt: '@', alignment: {vertical: 'middle', horizontal: 'left'}},
+                width: 25,
+            });
+        });
+
+        sheet.columns = columns;
+        $.each(this.getItems(), function (i, ref) {
+            $.each($this.fluidbook.settings.eanReferences, function (k, v) {
+                if (v.Reference === ref) {
+                    var row = {};
+                    $.each(columnsLabels, function (kk, vv) {
+                        row[vv] = v[vv];
+                    });
+                    sheet.addRow(row);
+                }
+            });
+        });
+        $.each(columnsLabels, function (k, v) {
+            sheet.getColumn(k + 1).numFmt = '@';
+        });
+
+        workbook.xlsx.writeBuffer().then(function (data) {
+            var blob = new Blob([data], {type: "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"});
+            const url = window.URL.createObjectURL(blob);
+            const anchor = document.createElement('a');
+            anchor.href = url;
+            anchor.download = $this.getExportFileName('EAN') + '.xlsx';
+            anchor.click();
+            window.URL.revokeObjectURL(url);
+        });
     },
 
     exportXLS: function () {