]> _ Git - fluidbook-html5.git/commitdiff
wip #1927 @0:40
authorVincent Vanwaelscappel <vincent@cubedesigners.com>
Wed, 25 Apr 2018 10:37:50 +0000 (12:37 +0200)
committerVincent Vanwaelscappel <vincent@cubedesigners.com>
Wed, 25 Apr 2018 10:37:50 +0000 (12:37 +0200)
js/libs/fluidbook/cart/fluidbook.cart.remarkable.js

index d8bf05e3c05bb27e9c855bdf67a604e6f58912bd..6cb43c25e5cc5692617af26627a83a3a7ceafb48 100644 (file)
@@ -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 += '</table>';
         content += '<table class="cart-totals">';
         content += '<tr><td>Total HT</td><td>' + $this.formatPrice(totalht, 'HT') + '</td></tr>';
-        content += '<tr><td>Frais de port</td><td>' + fp + '</td></tr>';
+        if (port.display != 'hidden') {
+            content += '<tr><td>Frais de port</td><td>' + port.display + '</td></tr>';
+        }
         content += '<tr><td>TVA</td><td>' + $this.formatPrice(tva) + '</td></tr>';
         content += '<tr><td colspan="2" class="hr"></td></tr>';
         content += '<tr class="total"><td>Total TTC</td><td>' + $this.formatPrice(totalttcfp, 'TTC') + '</td></tr>';
@@ -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')
             },