From 525e9f2c73424265ec82898062f09e760a797320 Mon Sep 17 00:00:00 2001 From: soufiane Date: Wed, 28 Jan 2026 15:49:26 +0100 Subject: [PATCH] wip #7957 @9:00 --- .../fluidbook/cart/fluidbook.cart.newheidi.js | 156 +++++++++-- js/libs/fluidbook/fluidbook.input.js | 1 + style/cart/newheidi.less | 248 +++++++++--------- 3 files changed, 259 insertions(+), 146 deletions(-) diff --git a/js/libs/fluidbook/cart/fluidbook.cart.newheidi.js b/js/libs/fluidbook/cart/fluidbook.cart.newheidi.js index b422bd91..e7559fa7 100644 --- a/js/libs/fluidbook/cart/fluidbook.cart.newheidi.js +++ b/js/libs/fluidbook/cart/fluidbook.cart.newheidi.js @@ -4,6 +4,10 @@ function FluidbookCartNewHeidi(cart) { this.data = this.fluidbook.settings.basketReferences; this.showAddToCartTooltips = false; this.items = {}; + this.formDataStorage = {}; + this.totalHT = 0; + this.tva = 0; + this.totalTTC = 0; this.init(); } @@ -11,11 +15,13 @@ FluidbookCartNewHeidi.prototype = { init: function () { var $this = this; this.items = this.fluidbook.cache.get('cart', {}); + this.formDataStorage = this.fluidbook.cache.get('formData', {}); + this.updateTotals() - $(document).on(this.fluidbook.input.changeEvent, '#newheidicart input[name=qty]', function() { + $(document).on(this.fluidbook.input.inputEvent, '#newheidicart input[name=qty]', function() { let ref = $(this).data('ref') - $this.items['' + ref]['quantity'] = $(this).val(); - $this.save(); + $this.updateSubTotal(ref) + $this.updateTotals() }) $(document).on(this.fluidbook.input.clickEvent, '#open-request', function () { @@ -26,6 +32,25 @@ FluidbookCartNewHeidi.prototype = { $(document).on(this.fluidbook.input.clickEvent, '#send-request', function() { $this.sendRequest(); + }); + + $(document).on(this.fluidbook.input.changeEvent, '#kimplay-sendcart-form input, #kimplay-sendcart-form textarea', function() { + $this.formDataStorage[$(this).attr('name')] = $(this).val() + $this.fluidbook.cache.set('formData', $this.formDataStorage); + }); + + $(document).on(this.fluidbook.input.clickEvent, '.quantity-control', function(e) { + let input = $(this).closest('.quantite').find('input'), ref = input.attr('data-ref') + + if($(this).hasClass('decrease')) { + $this.removeQuantity(ref); + }else { + $this.addQuantity(ref); + } + + input.val($this.items[ref].quantity) + $this.updateSubTotal(ref) + $this.updateTotals(); }) }, @@ -37,14 +62,12 @@ FluidbookCartNewHeidi.prototype = { }, addToCart: function (ref) { - let quantity, comment; + let quantity; if (this.items[ref] === undefined) { quantity = 1; - comment = ''; } else { quantity = this.items[ref].quantity; - comment = this.items[ref].comment; } this.items[ref] = { @@ -54,9 +77,11 @@ FluidbookCartNewHeidi.prototype = { price: this.data[ref].price ?? '', }; - this.fluidbook.menu.closeView(); + this.updateSubTotal(ref) + this.updateTotals() this.save(); + this.fluidbook.menu.closeView(); this.fluidbook.menu.openView('cart'); return true @@ -115,8 +140,53 @@ FluidbookCartNewHeidi.prototype = { } }, + updateSubTotal: function(ref) { + let row = $("#newheidicart").find('.row[data-ref='+ref+']') + let inputField = row.find('input[name=qty]') + + let quantity = this.items['' + ref].quantity; + if(inputField.val() !== "") { + quantity = inputField.val(); + } + + if(inputField.length > 0) { + this.items['' + ref]['quantity'] = quantity; + } + + this.save(); + + var subTotal = parseFloat(this.items['' + ref].price) * this.items['' + ref].quantity; + + row.find('.subtotal-text').text(this.normalizePrice(subTotal.toFixed(2), false)) + }, + + updateTotals: function() { + + if(!this.getItems()) { + return false; + } + + this.prices = Object.keys(this.getItems()).map((key) => parseFloat(this.getItems()[key].price) * parseFloat(this.getItems()[key].quantity)); + this.totalHT = this.prices.reduce((acc,currentValue) => acc + currentValue, 0) + this.tva = this.totalHT * 20 / 100; + this.totalTTC = parseFloat(this.totalHT) + parseFloat(this.tva); + + $('#total-ht').text(this.normalizePrice(this.totalHT.toFixed(2))) + $('#tva').text(this.normalizePrice(this.tva.toFixed(2))) + $('#total-ttc').text(this.normalizePrice(this.totalTTC.toFixed(2))) + }, + + removeQuantity: function(ref) { + this.items['' + ref]['quantity'] -= this.items['' + ref].quantity > 1 ? 1 : 0; + this.save(); + }, + + addQuantity: function(ref) { + this.items['' + ref]['quantity'] = parseInt(this.items['' + ref].quantity) + 1; + this.save(); + }, + updateIcon: function () { - console.log(this.getItemsNumbers()); $(this.fluidbook).trigger('fluidbook.cart.updateIcon', {number: this.getItemsNumbers()}); }, @@ -140,34 +210,50 @@ FluidbookCartNewHeidi.prototype = { var content = ''; content += ''; content += ''; - content += ''; content += ''; content += ''; - content += ''; - content += ''; + content += ''; + content += ''; + content += ''; + content += ''; content += ''; content += ''; content += ''; + $.each(this.getItems(), function (i) { var item = $this.items[i]; if (item === undefined || item === null) { return; } - var dataByRef = $this.data[i] - - content += ''; + var subTotal = $this.normalizePrice((parseFloat(item.price) * parseFloat(item.quantity)).toFixed(2), false); + content += ''; content += ''; content += ''; - content += ''; - content += ''; + content += ''; + content += ''; + content += ''; + content += ''; content += ''; content += ''; }); + content += ''; content += '
' + this.fluidbook.l10n.__('réf') + '' + this.fluidbook.l10n.__('désignation') + '' + this.fluidbook.l10n.__('quantité') + '' + this.fluidbook.l10n.__('commentaire') + '' + this.fluidbook.l10n.__('unités
par lot') + '
' + this.fluidbook.l10n.__('prix du lot
(eur ht)') + '
' + this.fluidbook.l10n.__('quantité
(lots)') + '
' + this.fluidbook.l10n.__('sous-total
(eur ht)') + '
' + i + '' + item.name + '' + item.comment + '' + item.batch + '' + $this.normalizePrice(item.price.toFixed(2), false) + '' + subTotal + '' + getSpriteIcon('interface-close') + '
'; content += '