From 60fcce24744852544d936e380496525ad380f767 Mon Sep 17 00:00:00 2001 From: Vincent Vanwaelscappel Date: Thu, 19 Jul 2018 17:38:52 +0200 Subject: [PATCH] wip #2150 @4 --- .../cart/fluidbook.cart.remarkable.js | 401 +++++++----------- js/libs/fluidbook/fluidbook.cart.js | 12 +- style/fluidbook.less | 29 +- 3 files changed, 191 insertions(+), 251 deletions(-) diff --git a/js/libs/fluidbook/cart/fluidbook.cart.remarkable.js b/js/libs/fluidbook/cart/fluidbook.cart.remarkable.js index baf46b1c..2340a1cf 100644 --- a/js/libs/fluidbook/cart/fluidbook.cart.remarkable.js +++ b/js/libs/fluidbook/cart/fluidbook.cart.remarkable.js @@ -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 '
' + this.fluidbook.l10n.__('your cart is empty') + '
'; } @@ -147,14 +164,22 @@ FluidbookCartRemarkable.prototype = { var content = ''; 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 += ''; - content += ''; - content += ''; - content += ''; + content += ''; + content += ''; + content += ''; content += ''; content += ''; content += ''; @@ -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 += '
' + item.name + '
Prix unitaire : ' + $this.formatPrice(item.price, 'HT') + '
Prix HT : ' + $this.formatPrice(ht, 'HT') + '
Prix TTC : ' + $this.formatPrice(ttc, 'TTC') + '
' + $this.formatPrice(item.price, 'HT') + '' + $(this).find('designation').text() + '
Prix unitaire : ' + $this.formatPrice(unit, 'HT'); + content += '
Prix HT : ' + $this.formatPrice(ht, 'HT') + '
Prix TTC : ' + $this.formatPrice(ttc, 'TTC') + '
' + $this.formatPrice(unit, 'HT') + '' + $this.formatPrice(ht, 'HT') + '' + $this.formatPrice(ttc, 'TTC') + '' + getSpriteIcon('interface-close') + '
'; content += ''; - content += ''; - if (port.display != 'hidden') { - content += ''; - } - content += ''; + content += ''; + content += ''; + content += ''; content += ''; - content += ''; + content += ''; content += '
Total HT' + $this.formatPrice(totalht, 'HT') + '
Frais de port' + port.display + '
TVA' + $this.formatPrice(tva) + '
Total HT' + $this.formatPrice(parseFloat(this.data.find('prix_sous_total').text()), 'HT') + '
Frais de port' + fp + '
TVA' + $this.formatPrice(parseFloat(this.data.find('total_tva_commande_ht').text())) + '
Total TTC' + $this.formatPrice(totalttcfp, 'TTC') + '
Total TTC' + $this.formatPrice(parseFloat(this.data.find('total').text()), 'TTC') + '
'; content += ''; 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 = '
'; - res += '
'; - res += ''; - res += ''; - res += '
'; - - res += '
'; - res += ''; - res += ''; - res += '
'; - - res += '
'; - res += '

Adresse de facturation :

'; - res += ''; - res += ''; - res += ''; - res += ''; - res += '
'; - - res += '
'; - res += '

Adresse de livraison - Enseigne (si différente) :

'; - res += ''; - res += ''; - res += ''; - res += ''; - res += '
'; - - res += ''; - res += '
'; - 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 = '
'; - content += "Nous vous remercions pour votre commande, elle sera traitée dans les plus brefs délais.
\n" + - "
\n" + - "Pour toute information complémentaire, contactez-nous au 04 67 59 12 81.
\n" + - "
\n" + - "
\n" + - "LIVRAISON
\n" + - "Livraison 72 h par transporteur
\n" + - "
\n" + - "
\n" + - "
\n" + - "MODES DE REGLEMENT
\n" + - "
\n" + - "Attendez de recevoir votre commande pour régler votre facture.
\n" + - "
\n" + - "Par chèque : à retourner à l’adresse indiquée.
\n" + - "
\n" + - "Par virement : toutes les informations en bas de la facture"; - content += "
"; - this._endMenu('Confirmation', content, callback); - }, - - openError: function (p2, callback) { - var content = '
'; - content += "Une erreur s'est produite. Votre commande n'a pas pu être transmise."; - content += "
"; - this._endMenu('Erreur', content, callback); - }, - _endMenu: function (title, content, callback) { var view = '
' + this.fluidbook.menu.closeButton() + '

' + title + '

'; view += '
'; @@ -325,42 +280,4 @@ FluidbookCartRemarkable.prototype = { $("#view").append('
' + view + '
'); 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 diff --git a/js/libs/fluidbook/fluidbook.cart.js b/js/libs/fluidbook/fluidbook.cart.js index ed613472..e8d7b4f2 100644 --- a/js/libs/fluidbook/fluidbook.cart.js +++ b/js/libs/fluidbook/fluidbook.cart.js @@ -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; }, diff --git a/style/fluidbook.less b/style/fluidbook.less index 6b71b102..865ff94c 100644 --- a/style/fluidbook.less +++ b/style/fluidbook.less @@ -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; -- 2.39.5