]> _ Git - fluidbook-html5.git/commitdiff
wip #4060 @1
authorVincent Vanwaelscappel <vincent@cubedesigners.com>
Fri, 13 Nov 2020 16:48:35 +0000 (17:48 +0100)
committerVincent Vanwaelscappel <vincent@cubedesigners.com>
Fri, 13 Nov 2020 16:48:35 +0000 (17:48 +0100)
js/libs/fluidbook/cart/fluidbook.cart.mif.js
js/libs/fluidbook/cart/fluidbook.cart.puma.js

index d0ab9b53377f01cece910ab4f449d4f5c566ac26..ce6189b99c6c6c539d2c3343d7e9436523e9775f 100644 (file)
@@ -38,14 +38,26 @@ FluidbookCartMIF.prototype = {
     },
 
     save: function () {
-        this.fluidbook.cache.set('cart', this.items);
+        this.fluidbook.cache.set('cart', this.getItems());
         this.fluidbook.cart.updateLinks();
     },
+
+    getItems: function () {
+        var res = [];
+        $(this.getItems()).each(function (i, ref) {
+            if ($this.data[ref] !== undefined && $this.data[ref] !== null) {
+                res.push(ref);
+            }
+        });
+        return res;
+    },
+
+
     getItemsReferences: function () {
-        return this.items;
+        return this.getItems();
     },
     getItemsNumbers: function () {
-        return this.items.length;
+        return this.getItems().length;
     },
     getAllQuantities: function () {
         return this.getItemsNumbers();
@@ -88,7 +100,7 @@ FluidbookCartMIF.prototype = {
         content += '<th></th>';
         content += '</tr></thead>';
         content += '<tbody>';
-        $.each(this.items, function (i, ref) {
+        $.each(this.getItems(), function (i, ref) {
             var item = $this.data[ref];
             if (item === undefined) {
                 return;
@@ -123,7 +135,7 @@ FluidbookCartMIF.prototype = {
         var subject = 'Ma liste de Noël'
         var body = 'Ma liste de Noël : ' + "\n\n";
 
-        $.each(this.items, function (i, ref) {
+        $.each(this.getItems(), function (i, ref) {
             var item = $this.fluidbook.settings.basketReferences[ref];
             if (item === undefined) {
                 return;
index 6f0df7ca85667f1e767213c07ff7697a33058a69..601be27ebf68c19d591743a37e01b34f3cebb92c 100644 (file)
@@ -25,11 +25,14 @@ FluidbookCartPuma.prototype = {
     },
 
     addToCart: function (ref, quantity) {
-        if (this.items.indexOf(ref) === -1) {
+        if (this.items.getItems().indexOf(ref) === -1) {
             this.items.push(ref);
             this.save();
+            return true;
+        } else {
+            this.removeFromCart(ref);
+            return false;
         }
-        return true;
     },
 
     removeFromCart: function (key) {
@@ -38,14 +41,14 @@ FluidbookCartPuma.prototype = {
     },
 
     save: function () {
-        this.fluidbook.cache.set('cart', this.items);
+        this.fluidbook.cache.set('cart', this.getItems());
         this.fluidbook.cart.updateLinks();
     },
     getItemsReferences: function () {
-        return this.items;
+        return this.getItems();
     },
     getItemsNumbers: function () {
-        return this.items.length;
+        return this.getItems().length;
     },
     getAllQuantities: function () {
         return this.getItemsNumbers();
@@ -76,6 +79,16 @@ FluidbookCartPuma.prototype = {
         return ['Catalogue', 'Catégorie', 'Ligne', 'Sexe', 'Modèle', 'Couleur', 'Désignation', 'Tarif', 'PVC', 'Image', 'PACK'];
     },
 
+    getItems: function () {
+        var res = [];
+        $(this.getItems()).each(function (i, ref) {
+            if ($this.data[ref] !== undefined && $this.data[ref] !== null) {
+                res.push(ref);
+            }
+        });
+        return res;
+    },
+
     getCartContent: function () {
         if (this.getItemsNumbers() == 0) {
             return '<div class="cart-empty">' + this.fluidbook.l10n.__('your cart is empty') + '</div>';
@@ -91,7 +104,7 @@ FluidbookCartPuma.prototype = {
         content += '<th></th>';
         content += '</tr></thead>';
         content += '<tbody>';
-        $.each(this.items, function (i, ref) {
+        $.each(this.getItems(), function (i, ref) {
             content += '<tr>';
             $.each(columns, function (k, v) {
                 var value = $this.data[ref][v];
@@ -186,7 +199,7 @@ FluidbookCartPuma.prototype = {
         });
 
         sheet.columns = columns;
-        $.each(this.items, function (i, ref) {
+        $.each(this.getItems(), function (i, ref) {
             var row = {};
             $.each(columnsLabels, function (k, v) {
                 if (v === 'Image') {