]> _ Git - fluidbook-html5.git/commitdiff
wip #2150 @4
authorVincent Vanwaelscappel <vincent@cubedesigners.com>
Thu, 19 Jul 2018 15:38:52 +0000 (17:38 +0200)
committerVincent Vanwaelscappel <vincent@cubedesigners.com>
Thu, 19 Jul 2018 15:38:52 +0000 (17:38 +0200)
js/libs/fluidbook/cart/fluidbook.cart.remarkable.js
js/libs/fluidbook/fluidbook.cart.js
style/fluidbook.less

index baf46b1c067f85812494fe7cc29776b85d672d94..2340a1cf8458941e10f8f094e7483ffb118a1b69 100644 (file)
@@ -3,110 +3,129 @@ function FluidbookCartRemarkable(cart) {
     this.cart = cart;
     this.fluidbook = this.cart.fluidbook;
     this.items = this.cart.getSavedData();
-    this.formInstance;
-    this.database;
-    $.each(this.fluidbook.datas.basketReferences, function (k, v) {
-        $this.database = {};
-        $.each(v, function (index, line) {
-            $this.database[line[0]] = {
-                ref: line[0],
-                name: line[1],
-                price: parseFloat(line[2]),
-                tax: parseFloat(line[3]) / 100
-            }
-        });
-        return true;
-    });
+    this.data;
+    this.handleTooltips = true;
     this.init();
-    this.parseCart();
 }
 
 FluidbookCartRemarkable.prototype = {
-    parseCart: function () {
+    updateCartData: function (callback) {
         var $this = this;
-        $.cookie("fsremarkablefr=4lnqzxer2votqppqbw6", 1, {
-            expires : 10,
-            path    : '/',
-            domain  : 'remarkable.fr',
-            secure  : true
-        });
+        this.sendCookie();
 
         $.ajax({
             url: "https://www.remarkable.fr/boutique/api/api.cfm?method=getPanier&object=panier&code_lg=lg_fr&idsite=1",
-            dataType: 'text',
+            dataType: 'xml',
             cache: false,
-            xhrFields: { withCredentials: true },
+            xhrFields: {withCredentials: true},
             success: function (data) {
-                console.log(data);
+                $this.fluidbook.hideLoader();
+                $this.updateCartFromData($(data), callback);
             },
         })
     },
 
+    updateCartFromData: function (data, callback) {
+        this.data = $(data);
+        this.updateCart();
+        if (callback !== undefined) {
+            callback();
+        }
+    },
+
     init: function () {
         var $this = this;
         $(document).on('change', '[data-menu="cart"] .input-number', function () {
-            $this.updateCart();
+            $this.updateCartFromQuantities();
             return true;
         });
 
-        $(document).on('click', '.cart-shipping-form .submit', function () {
-            $this.saveShipping();
-            if ($this.formInstance.validate()) {
-                $this.sendOrder(function (data) {
-                    window.location.hash = "#/cart/confirm";
-                }, function (data) {
-                    window.location.hash = "#/cart/error";
-                });
+        this.updateCartData(function () {
 
-            }
-            return false;
+        });
+        setTimeout(function () {
+            $this.updateCartData(function () {
+
+            });
+        }, 60000);
+
+        $(window).on('focus', function () {
+            $this.updateCartData(function () {
+
+            });
         });
     },
     addToCart: function (ref, quantity) {
-        this.setQuantity(ref, quantity, 'add');
-    },
-    removeFromCart: function (ref) {
-        this.setQuantity(ref, 0, 'set');
-    },
-    setQuantity: function (ref, quantity, operator) {
-        if (operator === undefined) {
-            operator = 'set';
-        }
-        if (quantity === undefined) {
+        var $this = this;
+        this.fluidbook.displayLoader();
+        if (quantity == undefined) {
             quantity = 1;
         }
-        if (this.items[ref] == null) {
-            this.items[ref] = 0;
-        }
-        var q = this.items[ref];
-        if (operator == 'set') {
-            q = quantity;
-        } else if (operator == 'add') {
-            q += quantity;
-        }
 
-        if (q <= 0) {
-            delete this.items[ref];
-        } else {
-            this.items[ref] = q;
-        }
-        this.cart.saveData(this.items);
-        this.updateIcon();
+        $.ajax({
+            url: 'https://www.remarkable.fr/boutique/com_act.cfm?code_lg=lg_fr&idsite=1',
+            cache: false,
+            data: {ref: ref, qte: quantity, ref_fille: '', radio_bloc: 'on'},
+            method: 'post',
+            xhrFields: {withCredentials: true},
+            success: function (data) {
+                var alert = $(data).find('#texte_message_alert').text();
+                if (alert !== '') {
+                    $this.fluidbook.tooltip.displayTooltip($(data).find('#texte_message_alert').text(), 'error');
+                } else {
+                    $this.fluidbook.tooltip.displayTooltip($this.fluidbook.l10n.__("the item has been added to your cart"), 'invert');
+                }
+                $this.fluidbook.hideLoader();
+                $this.updateCartData(function () {
+
+                });
+
+            }
+        })
+        return false;
+
+    },
+
+    sendCookie: function () {
+        // $.cookie("fsremarkablefr=4lnqzxer2votqppqbw6", 1, {
+        //     expires: 10,
+        //     path: '/',
+        //     domain: 'remarkable.fr',
+        //     secure: true
+        // });
+    },
+
+    removeFromCart: function (ref, callback) {
+        var $this = this;
+        this.fluidbook.displayLoader();
+        this.data.find('item reference').each(function () {
+            if ($(this).text() === ref) {
+                $.ajax({
+                    url: 'https://www.remarkable.fr/boutique/com_act.cfm?ModeEdit=delete&line=' + $(this).closest('item').attr('id'),
+                    xhrFields: {withCredentials: true},
+                    success: function () {
+                        $this.fluidbook.hideLoader();
+                        $this.updateCartData(callback);
+                    }
+                })
+                return true;
+            }
+        });
     },
     getItemsNumbers: function () {
-        return Object.size(this.items);
+        return this.data.find('item').length;
     },
     getAllQuantities: function () {
         var res = 0;
-        $.each(this.items, function (ref, quantity) {
-            res += quantity;
+        this.data.find('item quantite').each(function () {
+            res += parseInt($(this).text());
         });
         return res;
     },
     hasItem: function (itemReference) {
         var res = false;
-        $.each(this.items, function (ref, quantity) {
-            if (ref == itemReference) {
+        this.data.find('item reference').each(function () {
+            if ($(this).text() == itemReference) {
                 res = true;
                 return true;
             }
@@ -114,20 +133,13 @@ FluidbookCartRemarkable.prototype = {
         return res;
     },
     updateIcon: function () {
-        $(this.fluidbook).trigger('fluidbook.cart.updateIcon', {number: this.getAllQuantities()});
+        //$(this.fluidbook).trigger('fluidbook.cart.updateIcon', {number: this.getAllQuantities()});
+        $(this.fluidbook).trigger('fluidbook.cart.updateIcon', {number: this.getItemsNumbers()});
     },
 
     openMenu: function (p1, p2, callback) {
         this.fluidbook.menu.quickCloseView();
-        if (p1 == 'shipping') {
-            return this.openShipping(p2, callback);
-        } else if (p1 == 'confirm') {
-            return this.openConfirm(p2, callback);
-        } else if (p1 == 'error') {
-            return this.openError(p2, callback);
-        } else {
-            return this.openCart(p2, callback);
-        }
+        return this.openCart(p2, callback);
     },
 
     openCart: function (p2, callback) {
@@ -140,6 +152,11 @@ FluidbookCartRemarkable.prototype = {
     },
 
     getCartContent: function () {
+        var aff = '';
+        if ($_GET['affilie'] !== undefined && $_GET['affilie'] !== null && $_GET['affilie']) {
+            aff = '?affilie=' + $_GET['affilie'];
+        }
+
         if (this.getItemsNumbers() == 0) {
             return '<div class="cart-empty">' + this.fluidbook.l10n.__('your cart is empty') + '</div>';
         }
@@ -147,14 +164,22 @@ FluidbookCartRemarkable.prototype = {
         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);
+        this.data.find('item').each(function () {
+            var ref = $(this).find('reference').text();
+            var unit = parseFloat($(this).find('prix_unitaire').text());
+            var remise = 0;
+            if ($(this).find('valeur_remise').length > 0) {
+                remise = parseFloat($(this).find('valeur_remise').text());
+            }
+            unit -= remise;
+            var ht = parseFloat($(this).find('prix_total_article').text());
+            var ttc = ht * (1 + (parseFloat($(this).find('taux_tva').text())) / 100);
+
             content += '<tr>';
-            content += '<td class="name">' + item.name + '<div class="m">Prix unitaire : ' + $this.formatPrice(item.price, 'HT') + '<br />Prix HT : ' + $this.formatPrice(ht, 'HT') + '<br />Prix TTC : ' + $this.formatPrice(ttc, 'TTC') + '</div></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="name">' + $(this).find('designation').text() + '<div class="m">Prix unitaire : ' + $this.formatPrice(unit, 'HT');
+            content += '<br />Prix HT : ' + $this.formatPrice(ht, 'HT') + '<br />Prix TTC : ' + $this.formatPrice(ttc, 'TTC') + '</div></td>';
+            content += '<td class="quantity"><input name="' + ref + '" class="cartqty" type="number" min="0" max="10000" value="' + parseInt($(this).find('quantite').text()) + '" step="1" /></td>';
+            content += '<td class="price_unit">' + $this.formatPrice(unit, 'HT') + '</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>';
@@ -164,64 +189,82 @@ FluidbookCartRemarkable.prototype = {
             totalttc += ttc;
         });
 
-        var port = this.getShippingFees(totalht);
-
-        var htfp = totalht + port.value;
-        var totalttcfp = totalttc + (port.value * 1.2);
-        var tva = totalttcfp - htfp;
+        var fp = parseFloat(this.data.find('frais_port').text());
+        if (fp === 0) {
+            fp = this.data.find('total_frais_port').text();
+        } else {
+            fp = this.formatPrice(fp);
+        }
 
         content += '</table>';
         content += '<table class="cart-totals">';
-        content += '<tr><td>Total HT</td><td>' + $this.formatPrice(totalht, 'HT') + '</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>Total HT</td><td>' + $this.formatPrice(parseFloat(this.data.find('prix_sous_total').text()), 'HT') + '</td></tr>';
+        content += '<tr><td>Frais de port</td><td>' + fp + '</td></tr>';
+        content += '<tr><td>TVA</td><td>' + $this.formatPrice(parseFloat(this.data.find('total_tva_commande_ht').text())) + '</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 += '<tr class="total"><td>Total TTC</td><td>' + $this.formatPrice(parseFloat(this.data.find('total').text()), 'TTC') + '</td></tr>';
         content += '</table>';
 
         content += '<div class="cart-footer">';
         content += '<p>Frais de port 8,30 € HT*, offerts à partir de 99 € HT d’achat<br/>*Hors métropole, nous contacter</p>';
-        content += '<div class="fonctions"><a href="#/closeview" class="back">Continuer mes achats</a><a href="#/cart/shipping">Valider</a></div>';
+        content += '<div class="fonctions"><a href="#/closeview" class="back">Continuer mes achats</a><a href="https://www.remarkable.fr/boutique/panierb.cfm' + aff + '" target="_blank">Valider</a></div>';
         content += '</div>';
 
         return content;
     },
 
-    getShippingFees: function (totalht) {
-        var fpv = 0;
-        var fp = 'OFFERTS';
+    updateCartFromQuantities: function () {
+        var $this = this;
+        var data = {ModeEdit: 'update'};
+        var i = 1;
+
+        var del = '';
+        $(".cartqty").each(function () {
+            var v = parseInt($(this).val());
+            if (v === 0) {
+                del = $(this).attr('name');
+                return true;
+            }
+            data['Item_' + i] = v;
+            i++;
+        });
+
+        if (del != '') {
+            this.removeFromCart(del, function () {
 
-        if (totalht <= 99 && !this.hasItem('COL') && !this.hasItem('CT10')) {
-            fpv = 8.3;
-            fp = this.formatPrice(fpv, 'HT');
+            });
+            return;
         }
 
-        if (this.hasItem('MAJCOL') && this.getItemsNumbers() == 1) {
-            fpv = 0;
-            fp = 'hidden';
-        }
-        return {value: fpv, display: fp};
+        this.fluidbook.displayLoader();
+        $.ajax({
+            url: 'https://www.remarkable.fr/boutique/com_act.cfm?pay=35&code_lg=lg_fr',
+            method: "post",
+            data: data,
+            xhrFields: {withCredentials: true},
+            success: function () {
+                $this.updateCartData(function () {
 
+                });
+            }
+        })
     },
 
-    updateCart: function (getQtyFromField) {
-        if (getQtyFromField == undefined) {
-            getQtyFromField = true;
-        }
+    updateCart: function () {
+
         var $this = this;
-        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();
+        this.updateIcon();
         resize();
     },
 
     formatPrice: function (price, suffix) {
+        if (typeof price == 'number') {
+            price = parseFloat(price);
+        }
+
         if (suffix == undefined) {
             suffix = '';
         }
@@ -229,94 +272,6 @@ FluidbookCartRemarkable.prototype = {
         return price.toLocaleString("fr-FR", {style: "currency", currency: "EUR"}) + ' ' + suffix;
     },
 
-    getItemData: function (ref) {
-        return this.database[ref];
-    },
-
-    openShipping: function (p2, callback) {
-        var $this = this;
-        this._endMenu(this.fluidbook.l10n.__('your contact details'), this.getShippingContent(), function () {
-            callback();
-            var saved = $this.fluidbook.cache.get('shipping-details', {});
-            $(".cart-shipping-form input").each(function () {
-                if (saved[$(this).attr('name')] != null) {
-                    $(this).val(saved[$(this).attr('name')]);
-                }
-            });
-            $this.formInstance = $(".cart-shipping-form").parsley();
-        });
-    },
-
-    getShippingContent: function () {
-        var res = '<form class="cart-shipping-form" action="" method="post">';
-        res += '<div class="col col-left">';
-        res += '<input type="text" name="firstname" placeholder="Prénom" tabindex="100" required>';
-        res += '<input type="text" name="lastname" placeholder="Nom" tabindex="101" required>';
-        res += '</div>';
-
-        res += '<div class="col col-right">';
-        res += '<input type="tel" name="phone" placeholder="Téléphone" tabindex="102" pattern="[0-9\+\.\ \-]+" required>';
-        res += '<input type="email" name="email" placeholder="E-mail" tabindex="103" required>';
-        res += '</div>';
-
-        res += '<div class="col col-left">';
-        res += '<p>Adresse de facturation : </p>';
-        res += '<input type="text" name="billing_company" placeholder="Nom de la société"  tabindex="104" required>';
-        res += '<input type="text" name="billing_address" placeholder="Adresse" tabindex="105" required>';
-        res += '<input type="text" name="billing_zip" placeholder="Code postal" pattern="[0-9]{5}" tabindex="106" required>';
-        res += '<input type="text" name="billing_city" placeholder="Ville" tabindex="107" required>';
-        res += '</div>';
-
-        res += '<div class="col col-right">';
-        res += '<p>Adresse de livraison - Enseigne (si différente) : </p>';
-        res += '<input type="text" name="shipping_company" placeholder="Nom de la société"  tabindex="108">';
-        res += '<input type="text" name="shipping_address" placeholder="Adresse" tabindex="109">';
-        res += '<input type="text" name="shipping_zip" placeholder="Code postal"  pattern="[0-9]{5}" tabindex="110">';
-        res += '<input type="text" name="shipping_city" placeholder="Ville" tabindex="111">';
-        res += '</div>';
-
-        res += '<div class="cart-footer"><p>Tous les champs sont obligatoires</p><div class="fonctions"><a href="#" class="submit">Envoyer la demande</a></div></div>';
-        res += '</form>';
-        return res;
-    },
-    saveShipping: function () {
-        var data = {};
-        $(".cart-shipping-form input").each(function () {
-            data[$(this).attr('name')] = $(this).val();
-        });
-        this.fluidbook.cache.set('shipping-details', data);
-    },
-
-    openConfirm: function (p2, callback) {
-        var content = '<div class="cart-confirmation">';
-        content += "Nous vous remercions pour votre commande, elle sera traitée dans les plus brefs délais.<br>\n" +
-            "<br>\n" +
-            "Pour toute information complémentaire, <strong>contactez-nous au 04 67 59 12 81</strong>.<br>\n" +
-            "<br>\n" +
-            "<br>\n" +
-            "LIVRAISON<br>\n" +
-            "Livraison 72 h par transporteur<br>\n" +
-            "<br>\n" +
-            " <br>\n" +
-            "<br>\n" +
-            "MODES DE REGLEMENT<br>\n" +
-            "<br>\n" +
-            "Attendez de recevoir votre commande pour régler votre facture.<br>\n" +
-            "<br>\n" +
-            "Par chèque : à retourner à l’adresse indiquée.<br>\n" +
-            "<br>\n" +
-            "Par virement : toutes les informations en bas de la facture";
-        content += "</div>";
-        this._endMenu('Confirmation', content, callback);
-    },
-
-    openError: function (p2, callback) {
-        var content = '<div class="cart-confirmation">';
-        content += "Une erreur s'est produite. Votre commande n'a pas pu être transmise.";
-        content += "</div>";
-        this._endMenu('Erreur', content, callback);
-    },
-
     _endMenu: function (title, content, callback) {
         var view = '<div class="caption">' + this.fluidbook.menu.closeButton() + '<h2>' + title + '</h2></div>';
         view += '<div class="content">';
@@ -325,42 +280,4 @@ FluidbookCartRemarkable.prototype = {
         $("#view").append('<div class="mview" data-menu="cart">' + view + '</div>');
         callback();
     },
-
-    sendOrder: function (success, error) {
-        var $this = this;
-        var items = [];
-        var totalttc = 0;
-        var totalht = 0;
-        $.each(this.items, function (ref, quantity) {
-            var item = $this.getItemData(ref);
-            var ht = item.price * quantity;
-            var ttc = ht * (1 + item.tax);
-            items.push([ref, item.name, $this.formatPrice(item.price), quantity, $this.formatPrice(ht)]);
-            totalttc += ttc;
-            totalht += ht;
-        });
-
-        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': port.display,
-                'totalttc': totalttcfp,
-                'details': this.fluidbook.cache.get('shipping-details')
-            },
-            success: function (data) {
-                success(data);
-            },
-            error: function (data) {
-                error(data);
-            }
-        });
-    },
-
 };
\ No newline at end of file
index ed6134729ed26e0c0d8f02ae53bf6acfb8168fde..e8d7b4f2eed9266c6c833588942418740fd4c9e8 100644 (file)
@@ -21,8 +21,14 @@ FluidbookCart.prototype = {
         });
 
         $(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"), 'invert');
+            var qty = 1;
+            if ($(this).attr('data-cart-qty') !== null) {
+                qty = parseInt($(this).attr('data-cart-qty'));
+            }
+
+            if($this.instance.addToCart($(this).data('cart-ref'), qty)){
+                $this.fluidbook.tooltip.displayTooltip($this.fluidbook.l10n.__("the item has been added to your cart"), 'invert');
+            }
             return false;
         });
     },
@@ -114,7 +120,7 @@ FluidbookCart.prototype = {
             v = Math.min(v, this.max);
             v = Math.round(v / this.step) * this.step;
             if (v < origV && this.errorMax !== null) {
-                alert(this.errorMax);
+
             }
             return v;
         },
index 6b71b102ea4931d22961ca9ba2c2d69c8166da5a..865ff94c93651aea71eefb1ec0f709de50722e25 100644 (file)
@@ -961,11 +961,11 @@ a.bookmark {
                }
                .input-number {
                        position: relative;
-                       width: 160px;
+                       width: 170px;
                        height: 44px;
                        input {
                                height: 44px;
-                               width: 60px;
+                               width: 70px;
                                display: inline-block;
                                margin: 0 2px;
                                border: 0;
@@ -1302,7 +1302,7 @@ html.ios body.portrait #interface {
                        }
                }
 
-               &.fs{
+               &.fs {
                        a, div {
                                &.button.back {
                                        top: 0px;
@@ -1311,17 +1311,16 @@ html.ios body.portrait #interface {
                        }
                }
 
-               .iframeContainer,.iframeHolder{
+               .iframeContainer, .iframeHolder {
                        height: 100%;
                }
 
-               .content{
+               .content {
                        overflow: hidden;
                }
        }
 
        &
-
        &[data-menu="externalchapters"] {
                .caption {
                        a, div {
@@ -2421,6 +2420,24 @@ ul.chapters {
                }
        }
 
+       &[data-style="error"] {
+               font-weight: 700;
+               background-color: #cc0000;
+               color: #fff;
+
+               &[data-pos-y="n"] {
+                       &:after {
+                               border-bottom-color: #cc0000;
+                       }
+               }
+
+               &[data-pos-y="s"] {
+                       &:after {
+                               border-top-color: #cc0000;
+                       }
+               }
+       }
+
        &:after {
                content: "";
                position: absolute;