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;
}
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) {
},
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>';
}
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>';
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 = '';
}
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">';
$("#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