From 8f1e986768a52063a7a697181f9ea78637eb7c6d Mon Sep 17 00:00:00 2001 From: Vincent Vanwaelscappel Date: Wed, 25 Apr 2018 12:37:50 +0200 Subject: [PATCH] wip #1927 @0:40 --- .../cart/fluidbook.cart.remarkable.js | 64 +++++++++++++------ 1 file changed, 46 insertions(+), 18 deletions(-) diff --git a/js/libs/fluidbook/cart/fluidbook.cart.remarkable.js b/js/libs/fluidbook/cart/fluidbook.cart.remarkable.js index d8bf05e3..6cb43c25 100644 --- a/js/libs/fluidbook/cart/fluidbook.cart.remarkable.js +++ b/js/libs/fluidbook/cart/fluidbook.cart.remarkable.js @@ -75,8 +75,25 @@ FluidbookCartRemarkable.prototype = { getItemsNumbers: function () { return Object.size(this.items); }, + getAllQuantities: function () { + var res = 0; + $.each(this.items, function (ref, quantity) { + res += quantity; + }); + return res; + }, + hasItem: function (itemReference) { + var res = false; + $.each(this.items, function (ref, quantity) { + if (ref == itemReference) { + res = true; + return true; + } + }); + return res; + }, updateIcon: function () { - $(this.fluidbook).trigger('fluidbook.cart.updateIcon', {number: this.getItemsNumbers()}); + $(this.fluidbook).trigger('fluidbook.cart.updateIcon', {number: this.getAllQuantities()}); }, openMenu: function (p1, p2, callback) { @@ -126,21 +143,18 @@ FluidbookCartRemarkable.prototype = { totalttc += ttc; }); - var fpv = 0; - var fp = 'OFFERTS'; + var port = this.getShippingFees(totalht); - if (totalht <= 99) { - fpv = 8.3; - fp = $this.formatPrice(fpv, 'HT'); - } - var htfp = totalht + fpv; - var totalttcfp = totalttc + (fpv * 1.2); + var htfp = totalht + port.value; + var totalttcfp = totalttc + (port.value * 1.2); var tva = totalttcfp - htfp; content += ''; content += ''; content += ''; - content += ''; + if (port.display != 'hidden') { + content += ''; + } content += ''; content += ''; content += ''; @@ -154,6 +168,23 @@ FluidbookCartRemarkable.prototype = { return content; }, + getShippingFees: function (totalht) { + var fpv = 0; + var fp = 'OFFERTS'; + + if (totalht <= 99 && !this.hasItem('COL') && !this.hasItem('CT10')) { + fpv = 8.3; + fp = this.formatPrice(fpv, 'HT'); + } + + if (this.hasItem('MAJCOL') && this.getItemsNumbers() == 1) { + fpv = 0; + fp = 'hidden'; + } + return {value: fpv, display: fp}; + + }, + updateCart: function (getQtyFromField) { if (getQtyFromField == undefined) { getQtyFromField = true; @@ -288,20 +319,17 @@ FluidbookCartRemarkable.prototype = { totalht += ht; }); - var fp = 0; - var fpv = 'OFFERTS'; - if (totalht < 99) { - fp = 8.3; - fpv = this.formatPrice(fp); - } - var totalttcfp = this.formatPrice(totalttc + (fp * 1.2)); + var port = this.getShippingFees(totalht); + + + var totalttcfp = this.formatPrice(totalttc + (port.value * 1.2)); $.ajax({ url: 'https://workshop.fluidbook.com/services/orderRemarkable', method: 'post', data: { 'items': items, - 'fpv': fpv, + 'fpv': port.display, 'totalttc': totalttcfp, 'details': this.fluidbook.cache.get('shipping-details') }, -- 2.39.5
Total HT' + $this.formatPrice(totalht, 'HT') + '
Frais de port' + fp + '
Frais de port' + port.display + '
TVA' + $this.formatPrice(tva) + '
Total TTC' + $this.formatPrice(totalttcfp, 'TTC') + '