From b3553a556a2f10fba93ab8d54b661dcf119cf6d3 Mon Sep 17 00:00:00 2001 From: Vincent Vanwaelscappel Date: Fri, 13 Nov 2020 17:48:35 +0100 Subject: [PATCH] wip #4060 @1 --- js/libs/fluidbook/cart/fluidbook.cart.mif.js | 22 +++++++++++---- js/libs/fluidbook/cart/fluidbook.cart.puma.js | 27 ++++++++++++++----- 2 files changed, 37 insertions(+), 12 deletions(-) diff --git a/js/libs/fluidbook/cart/fluidbook.cart.mif.js b/js/libs/fluidbook/cart/fluidbook.cart.mif.js index d0ab9b53..ce6189b9 100644 --- a/js/libs/fluidbook/cart/fluidbook.cart.mif.js +++ b/js/libs/fluidbook/cart/fluidbook.cart.mif.js @@ -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 += ''; content += ''; content += ''; - $.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; diff --git a/js/libs/fluidbook/cart/fluidbook.cart.puma.js b/js/libs/fluidbook/cart/fluidbook.cart.puma.js index 6f0df7ca..601be27e 100644 --- a/js/libs/fluidbook/cart/fluidbook.cart.puma.js +++ b/js/libs/fluidbook/cart/fluidbook.cart.puma.js @@ -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 '
' + this.fluidbook.l10n.__('your cart is empty') + '
'; @@ -91,7 +104,7 @@ FluidbookCartPuma.prototype = { content += ''; content += ''; content += ''; - $.each(this.items, function (i, ref) { + $.each(this.getItems(), function (i, ref) { content += ''; $.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') { -- 2.39.5