From: Vincent Vanwaelscappel Date: Tue, 13 Jan 2026 18:32:17 +0000 (+0100) Subject: wip #7898 @0.75 X-Git-Url: http://git.cubedesigners.com/?a=commitdiff_plain;h=9e6c1fd66ec3a5817a6af8a9f1c6b99a78d556cb;p=fluidbook-html5.git wip #7898 @0.75 --- diff --git a/js/libs/fluidbook/cart/fluidbook.cart.kimplay.js b/js/libs/fluidbook/cart/fluidbook.cart.kimplay.js index 56e78a91..03e32446 100644 --- a/js/libs/fluidbook/cart/fluidbook.cart.kimplay.js +++ b/js/libs/fluidbook/cart/fluidbook.cart.kimplay.js @@ -1,23 +1,43 @@ function FluidbookCartKimplay(cart) { - var $this = this; this.cart = cart; this.fluidbook = this.cart.fluidbook; this.data = this.fluidbook.settings.basketReferences; this.showAddToCartTooltips = false; + this.items = {}; this.init(); } FluidbookCartKimplay.prototype = { init: function () { var $this = this; - this.items = this.fluidbook.cache.get('cart', []); + this.items = this.fluidbook.cache.get('cart', {}); $(document).on(this.fluidbook.input.clickEvent, '.exportCartPDF', function () { $this.exportPDF(); return false; }); + + $(document).on(this.fluidbook.input.clickEvent, '#kimplay-additem button', function () { + let form = $(this).closest('#kimplay-additem'); + $this.items['' + $(this).data('ref')] = { + quantity: $(form).find('[name=qty]').val(), + comment: $(form).find('[name=comment]').val() + }; + $this.fluidbook.tooltip.displayTooltipDuring($this.fluidbook.l10n.__("the item has been added to your cart"), 2500); + $this.fluidbook.menu.closeView(); + $this.save(); + }); }, - addToCart: function (ref, quantity) { + addToCart: function (ref) { + let quantity, comment; + + if (this.items[ref] === undefined) { + quantity = 1; + comment = ''; + } else { + quantity = this.items[ref].quantity; + comment = this.items[ref].comment; + } let view = `
${this.fluidbook.menu.getCaption("", 'small')} @@ -30,23 +50,14 @@ FluidbookCartKimplay.prototype = { Quantité souhaitée :

Commentaire (facultatif) -
- +
+
`; this.fluidbook.menu.openCustomView(view, 'cart-kimplay-qty'); }, - _addToCart: function (ref, quantity) { - if (this.items.indexOf(ref) === -1) { - this.items.push(ref); - this.save(); - } - - return this.fluidbook.l10n.__("the item has been added to your selection"); - }, - removeFromCart: function (key) { this.items.splice(key, 1); this.save(); @@ -59,23 +70,31 @@ FluidbookCartKimplay.prototype = { }, getItems: function () { - var res = []; - var $this = this; - $(this.items).each(function (i, ref) { - if ($this.data[ref] !== undefined && $this.data[ref] !== null) { - res.push(ref); - } - }); - return res; + return this.items; }, + hasItem: function (ref) { + return this.items[ref] !== undefined; + }, getItemsReferences: function () { - return this.getItems(); - }, getItemsNumbers: function () { + let res = []; + $.each(this.getItems(), function (i, item) { + res.push(i); + }); + return res; + }, + + getItemsNumbers: function () { return this.getItems().length; - }, getAllQuantities: function () { - return this.getItemsNumbers(); + }, + + getAllQuantities: function () { + let res = 0; + $.each(this.getItems(), function (i, item) { + res += parseInt(item.quantity); + }); + return res; }, updateCart: function () { diff --git a/js/libs/fluidbook/fluidbook.cart.js b/js/libs/fluidbook/fluidbook.cart.js index b9376351..6d470492 100644 --- a/js/libs/fluidbook/fluidbook.cart.js +++ b/js/libs/fluidbook/fluidbook.cart.js @@ -49,13 +49,13 @@ FluidbookCart.prototype = { } if (refs.indexOf(r) === -1) { refs.push(r); - if ($this.instance.getItems().indexOf(r) === -1) { + if ($this.hasItem(r) === -1) { force = true; } } }); } else { - force = $this.instance.getItems().indexOf(ref) === -1; + force = $this.hasItem(ref) === -1; refs = [ref]; } @@ -92,7 +92,7 @@ FluidbookCart.prototype = { $this.fluidbook.tooltip.displayTooltipDuring(tooltip, 2500, tooltipStyle); } } catch (e) { - + console.log(e); } return false; @@ -104,6 +104,13 @@ FluidbookCart.prototype = { }); }, + hasItem: function (ref) { + if (this.instance.hasItem !== undefined) { + return this.instance.hasItem(ref); + } + return this.instance.getItems().indexOf(ref) + }, + updateLinks: function () { $('a[data-cart-ref]').removeClass('active'); diff --git a/style/cart/kimplay.less b/style/cart/kimplay.less index dd74e93d..1e2627fe 100644 --- a/style/cart/kimplay.less +++ b/style/cart/kimplay.less @@ -1,3 +1,7 @@ +.link a.active[data-cart-ref] { + background-color: rgba(0, 255, 0, 0.5); +} + .mview[data-menu="cart-kimplay-qty"] { background-color: #fff; color: #000; @@ -6,7 +10,7 @@ .caption { height: 30px; - padding:0; + padding: 0; } .caption a.back { @@ -36,9 +40,10 @@ input, textarea { border: 2px solid #000; - margin-bottom: 30px; + margin-bottom: 20px; padding: 2px; font-size: 16px; + font-family: @font; } textarea { @@ -46,11 +51,13 @@ max-width: 100%; height: 58px; max-height: 58px; + padding: 5px; } input { - width: 50px; + width: 70px; background-color: #fff; + text-align: center; } button { @@ -59,10 +66,11 @@ color: #fff; text-transform: uppercase; text-align: center; - padding: 10px 0; + padding: 14px 0; display: block; width: 100%; font-weight: bold; + cursor: pointer; } } } \ No newline at end of file