this.data;
this.handleTooltips = true;
this.handleTaxes = false;
+ this.initBaseURL();
this.init();
}
FluidbookCartMopec.prototype = {
+ initBaseURL: function () {
+ this.baseURL = window.location.protocol + '//' + window.location.host + '/' + this.fluidbook.l10n.currentLang + '/';
+ },
updateCartData: function (callback) {
var $this = this;
this.sendCookie();
init: function () {
var $this = this;
+
$(document).on('change', '[data-menu="cart"] .input-number', function () {
- $this.updateCartFromQuantities();
+ $this.updateCartFromQuantities(this);
return true;
});
});
});
- this.baseURL = 'http://www.mopec.es/' + this.fluidbook.l10n.currentLang + '/';
+
},
addToCart: function (ref, quantity) {
var $this = this;
this.fluidbook.displayLoader();
- if (quantity == undefined) {
+ if (quantity === undefined) {
quantity = 1;
}
+ this.getProductIDBySKU(ref, function (product_id) {
+ $.ajax({
+ url: $this.baseURL + 'checkout/cart/add',
+ cache: false,
+ data: {product: product_id, qty: quantity, form_key: $this.getFormKey()},
+ method: 'post',
+ xhrFields: {withCredentials: true},
+ dataType: 'json',
+ success: function (data) {
+ if (data.backUrl) {
+ $this.fluidbook.hideLoader();
+ $this.fluidbook.openInPopupIframe(data.backUrl);
+ } 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;
+
+ },
+
+ getProductIDBySKU: function (sku, callback) {
$.ajax({
- url: 'https://www.remarkable.fr/boutique/com_act.cfm?code_lg=lg_fr&idsite=1',
+ url: this.baseURL + 'fastorder/index/search',
cache: false,
- data: {ref: ref, qte: quantity, ref_fille: '', radio_bloc: 'on'},
+ data: {product: sku, sort_order: 0},
method: 'post',
xhrFields: {withCredentials: true},
+ dataType: 'json',
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 () {
-
- });
-
+ var product_id = data[0].product_id;
+ callback(product_id);
}
- })
- return false;
-
+ });
},
sendCookie: function () {
- // $.cookie("fsremarkablefr=4lnqzxer2votqppqbw6", 1, {
- // expires: 10,
- // path: '/',
- // domain: 'remarkable.fr',
- // secure: true
- // });
},
- removeFromCart: function (ref, callback) {
+ removeFromCart: function (item_id, 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;
+ $.ajax({
+ url: $this.baseURL + 'checkout/sidebar/removeItem',
+ method: 'post',
+ data: {item_id: item_id, form_key: this.getFormKey()},
+ xhrFields: {withCredentials: true},
+ success: function () {
+ $this.updateCartData(callback);
}
- });
+ })
},
getItemsNumbers: function () {
return this.data.summary_count;
});
return res;
},
- hasItem: function (itemReference) {
- var res = false;
- 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.getItemsNumbers()});
},
var content = '<table class="cart-items">';
var totalht = 0;
$.each(this.data.items, function (index, item) {
- var ref = item.product_sku;
var qty = $this.parseInt(item.qty);
var unit = $this.parseFloat(item.product_price_value);
var ht = unit * qty;
content += '<tr>';
- content += '<td class="name">' + item.product_name + '<div class="m">Prix unitaire: ' + $this.formatPrice(unit);
- content += '<br />Prix : ' + $this.formatPrice(ht, 'HT') + '</div></td>';
- content += '<td class="quantity"><input name="' + ref + '" class="cartqty" type="number" min="0" max="10000" value="' + qty + '" step="1" /></td>';
+ content += '<td class="name">' + item.product_name + '<div class="m">' + $this.fluidbook.l10n.__('unit price') + ': ' + $this.formatPrice(unit);
+ content += '<br />' + $this.fluidbook.l10n.__('price') + ': ' + $this.formatPrice(ht) + '</div></td>';
+ content += '<td class="quantity"><input name="' + item.item_id + '" class="cartqty" type="number" min="0" max="10000" value="' + qty + '" step="1" /></td>';
content += '<td class="price_unit">' + $this.formatPrice(unit) + '</td>';
content += '<td class="price_excluding_taxes">' + $this.formatPrice(ht) + '</td>';
- content += '<td class="delete"><a href="#" data-cart-delete="' + ref + '">' + getSpriteIcon('interface-close') + '</a></td>';
+ content += '<td class="delete"><a href="#" data-cart-delete="' + item.item_id + '">' + getSpriteIcon('interface-close') + '</a></td>';
content += '</tr>';
totalht += ht;
content += '</table>';
content += '<table class="cart-totals">';
content += '<tr><td colspan="2" class="hr"></td></tr>';
- content += '<tr class="total"><td>Total</td><td>' + $this.formatPrice(this.data.subtotalAmount) + '</td></tr>';
+ content += '<tr class="total"><td>' + $this.fluidbook.l10n.__('total') + '</td><td>' + $this.formatPrice($this.parseFloat(this.data.subtotalAmount)) + '</td></tr>';
content += '</table>';
content += '<div class="cart-footer">';
- 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 class="fonctions"><a href="#/closeview" class="back">' + $this.fluidbook.l10n.__('continue shopping') + '</a><a href="' + this.baseURL + 'checkout/cart" target="_blank">' + $this.fluidbook.l10n.__('proceed to checkout') + '</a></div>';
content += '</div>';
return content;
},
- 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++;
- });
+ getFormKey: function () {
+ return $.cookie('form_key');
+ },
- if (del != '') {
- this.removeFromCart(del, function () {
+ updateCartFromQuantities: function (el) {
+ var $this = this;
+ var input = $(el).find('input.cartqty');
+ var item_id = $(input).attr('name');
+ var newVal = $this.parseInt($(input).val());
+ if (newVal === 0) {
+ this.removeFromCart(item_id, function () {
});
- return;
+ } else {
+ this.fluidbook.displayLoader();
+ $.ajax({
+ url: $this.baseURL + 'checkout/cart/updateItemOptions/id/' + item_id,
+ method: "post",
+ data: {item: item_id, qty: newVal, form_key: this.getFormKey()},
+ xhrFields: {withCredentials: true},
+ success: function () {
+ $this.updateCartData(function () {
+
+ });
+ }
+ })
}
-
- 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 () {
},
parseFloat: function (s) {
+ if (typeof s === 'number') {
+ return s;
+ }
+ if (s === undefined || s === null || s === '') {
+ return 0;
+ }
s = s.replace(/\s/g, '');
return parseFloat(s);
},
parseInt: function (s) {
+ if (typeof s === 'number') {
+ return Math.round(s);
+ }
+ if (s === undefined || s === null || s === '') {
+ return 0;
+ }
s = s.replace(/\s/g, '');
return parseInt(s);
},
this.openSlideshow(param1, cb);
} else if (view === 'iframe') {
this.openIframe(param1, cb);
+ } else if (view === 'freeiframe') {
+ this.openFreeiframe(param1, cb);
} else if (view === 'search') {
this.openSearch(param1, cb);
} else if (view === 'print') {
}, 420);
},
- viewWrap: function (content, menu, attributes, cls,replace) {
+ viewWrap: function (content, menu, attributes, cls, replace) {
if (attributes === undefined) {
attributes = '';
}
cls = '';
}
var res = '<div class="mview ' + cls + '" data-menu="' + menu + '" role="dialog" aria-labelledby="mview-dialog-title"' + attributes + '>' + content + '</div>';
- if(replace===true){
+ if (replace === true) {
$("#view").html(res);
- }else {
+ } else {
$("#view").append(res);
}
},
}
},
- openIframe: function (iframe, callback) {
+ openFreeiframe: function (url, callback) {
+ var markup = '<div class="iframeContainer" data-type="free">';
+ markup += '<iframe src="' + url + '" width="100%" height="100%" frameborder="0" marginwidth="0" marginheight="0" scrolling="auto" allowfullscreen mozallowfullscreen="true" webkitallowfullscreen="true" onmousewheel=""></iframe>';
+ markup += '</div>';
+ this._openiframe(markup, '', callback);
+ },
+
+ _openiframe: function (markup, maxWidth, callback) {
+
var $this = this;
- var href = '#/iframe/' + iframe;
- var a = $('a[href="' + href + '"]');
- if ($(a).length === 0) {
- a = this.fluidbook.links.getLinkByHref(href);
- }
- var markup = decodeURIComponent($(a).attr('data-iframe'));
+
var view = this.getCaption();
view += '<div class="content noscroll"><div class="iframeHolder">';
view += markup;
view += '</div></div>';
- var maxWidth = '';
- if ($(a).data('max-width')) {
- maxWidth = ' data-max-width="' + $(a).data('max-width') + '"';
- }
-
this.viewWrap(view, 'iframe', maxWidth + ' dir="ltr"');
if (callback != undefined) {
callback();
});
},
+ openIframe: function (iframe, callback) {
+ var href = '#/iframe/' + iframe;
+ var a = $('a[href="' + href + '"]');
+ if ($(a).length === 0) {
+ a = this.fluidbook.links.getLinkByHref(href);
+ }
+ var markup = decodeURIComponent($(a).attr('data-iframe'));
+
+ var maxWidth = '';
+ if ($(a).data('max-width')) {
+ maxWidth = ' data-max-width="' + $(a).data('max-width') + '"';
+ }
+ this._openiframe(markup, maxWidth, callback);
+ },
+
openVideo: function (video, callback) {
var a = $('a[href="#/video/' + video + '"]');
var markup = decodeURIComponent($(a).attr('data-video'));