]> _ Git - fluidbook-html5.git/commitdiff
wip #1927 @2.5
authorVincent Vanwaelscappel <vincent@cubedesigners.com>
Fri, 13 Apr 2018 14:55:47 +0000 (16:55 +0200)
committerVincent Vanwaelscappel <vincent@cubedesigners.com>
Fri, 13 Apr 2018 14:55:47 +0000 (16:55 +0200)
js/libs/fluidbook/cart/fluidbook.cart.remarkable.js
js/libs/fluidbook/fluidbook.cart.js
js/libs/fluidbook/fluidbook.nav.js
style/fluidbook.less

index 566c5802469525a62305ed097e3230483d50f790..46f9ab25abb4e2d7a4f2ad774577317600ee8b04 100644 (file)
@@ -85,28 +85,65 @@ FluidbookCartRemarkable.prototype = {
     },
 
     getCartContent: function () {
+        if (this.getItemsNumbers() == 0) {
+            return '<div class="cart-empty">' + this.fluidbook.l10n.__('your cart is empty') + '</div>';
+        }
         var $this = this;
         var content = '<table class="cart-items">';
+        var totalht = 0;
+        var totalttc = 0;
         $.each(this.items, function (ref, quantity) {
             var item = $this.getItemData(ref);
+            var ht = item.price * quantity;
+            var ttc = ht * (1 + item.tax);
             content += '<tr>';
             content += '<td class="name">' + item.name + '</td>';
             content += '<td class="quantity"><input name="' + ref + '" class="cartqty" type="number" min="0" max="100" value="' + quantity + '" step="1" /></td>';
             content += '<td class="price_unit">' + $this.formatPrice(item.price, 'HT') + '</td>';
-            content += '<td class="price_excluding_taxes">' + $this.formatPrice(item.price * quantity, 'HT') + '</td>';
-            content += '<td class="price">' + $this.formatPrice((item.price * quantity) * (1 + item.tax), 'TTC') + '</td>';
-            content += '<td class="delete"><a href="#" data-cart-delete="' + ref + '"></a></td>';
+            content += '<td class="price_excluding_taxes">' + $this.formatPrice(ht, 'HT') + '</td>';
+            content += '<td class="price">' + $this.formatPrice(ttc, 'TTC') + '</td>';
+            content += '<td class="delete"><a href="#" data-cart-delete="' + ref + '">' + getSpriteIcon('interface-close') + '</a></td>';
             content += '</tr>';
+
+            totalht += ht;
+            totalttc += ttc;
         });
+
+        var fpv = 0;
+        var fp = 'OFFERTS';
+
+        if (totalht <= 99) {
+            fpv = 8.3;
+            fp = $this.formatPrice(fpv, 'HT');
+        }
+        var htfp = totalht + fpv;
+        var totalttcfp = totalttc + (fpv * 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>';
+        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>';
         content += '</table>';
         return content;
     },
 
-    updateCart: function () {
+    updateCart: function (getQtyFromField) {
+        if (getQtyFromField == undefined) {
+            getQtyFromField = true;
+        }
         var $this = this;
-        $(".cartqty").each(function () {
-            $this.setQuantity($(this).attr('name'), parseInt($(this).val()), 'set');
-        });
+        if (getQtyFromField) {
+            $(".cartqty").each(function () {
+                $this.setQuantity($(this).attr('name'), parseInt($(this).val()), 'set');
+            });
+        }
+        $('[data-menu="cart"] .content').html(this.getCartContent());
+        $('input[type="number"]').inputNumber();
+        resize();
     },
 
     formatPrice: function (price, suffix) {
index 67df20e8c563bec83f4432b9a4443c2faf8e18f8..ed1242bd9a744706fdf8c3b68c5c1203ed45c385 100644 (file)
@@ -14,6 +14,12 @@ FluidbookCart.prototype = {
         this.enabled = true;
         this.instance = this.createInstance();
 
+        $(document).on('click', '[data-cart-delete]', function () {
+            $this.instance.removeFromCart($(this).data('cart-delete'));
+            $this.instance.updateCart(false);
+            return false;
+        });
+
         $(document).on('click', '[data-cart-ref]', function () {
             $this.instance.addToCart($(this).data('cart-ref'));
             $this.fluidbook.tooltip.displayTooltip($this.fluidbook.l10n.__("the item has been added to your cart"));
index 8aabeeab2e5803d3324c8e23453210b2fdd19189..1769bd1e30ff4692e0b2c5afa4312dd841ac3505 100644 (file)
@@ -404,7 +404,6 @@ FluidbookNav.prototype = {
                         if ($(l).find('span.number').length === 0) {
                             $(l).append('<span class="number"></span>');
                         }
-                        console.log($(l).find('span.number'));
                         $(l).find('span.number').text(n);
                     }
                 });
@@ -532,7 +531,6 @@ FluidbookNav.prototype = {
                     if (foundLink == undefined) {
                         continue;
                     }
-                    console.log(foundLink);
                     link = $(foundLink).find('a').append(linkIcon);
                     if (navType == 'menu') {
                         var tooltip = $(link).data('tooltip');
index 4fec0b546d35aa70e0ab6ce5ee5099072b0d5432..ed813cd6e5718ffa1e640670c39f5d69bff4093d 100644 (file)
@@ -860,6 +860,10 @@ a.bookmark {
 }
 
 [data-menu="cart"] {
+       .cart-empty {
+               padding: 50px;
+       }
+
        table {
                width: 1004px;
                margin-left: 10px;
@@ -874,6 +878,26 @@ a.bookmark {
                        &.price {
                                font-weight: 700;
                        }
+                       &.price, &.price_excluding_taxes, &.price_unit {
+                               text-align: right;
+                       }
+                       &.delete {
+                               a {
+                                       display: inline-block;
+                                       width: 23px;
+                                       height: 23px;
+                                       background-color: @menu-button-background;
+                                       position: relative;
+                                       top: 1px;
+                                       left: -5px;
+                                       padding: 0 6px;
+                                       svg {
+                                               width: 11px;
+                                               height: 11px;
+                                               display: inline-block;
+                                       }
+                               }
+                       }
                }
                .input-number {
                        position: relative;
@@ -899,7 +923,30 @@ a.bookmark {
                                font-size: 30px;
                        }
                }
+
+               &.cart-totals {
+                       width: 250px;
+                       margin: 18px;
+                       float: right;
+                       clear: both;
+                       td.hr {
+                               height: 2px;
+                               background-color: #fff;
+                               padding: 0;
+                       }
+                       tr.total {
+                               td {
+                                       font-weight: 700;
+
+                               }
+                       }
+                       td {
+                               padding: 6px 12px;
+                               text-align: right;
+                       }
+               }
        }
+
 }
 
 // Hack for #1433