From: Vincent Vanwaelscappel Date: Thu, 3 Sep 2020 16:39:49 +0000 (+0200) Subject: wip #3828 @6 X-Git-Url: http://git.cubedesigners.com/?a=commitdiff_plain;h=24274d2b9d70746b87b0b27c8eedbe2de884a17a;p=fluidbook-html5.git wip #3828 @6 --- diff --git a/_index.html b/_index.html index 17d7f920..5ce8c44c 100644 --- a/_index.html +++ b/_index.html @@ -103,7 +103,7 @@
-
+ diff --git a/js/libs/fluidbook/cart/fluidbook.cart.mopec.js b/js/libs/fluidbook/cart/fluidbook.cart.mopec.js index b9225628..44782f34 100644 --- a/js/libs/fluidbook/cart/fluidbook.cart.mopec.js +++ b/js/libs/fluidbook/cart/fluidbook.cart.mopec.js @@ -6,10 +6,14 @@ function FluidbookCartMopec(cart) { 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(); @@ -36,8 +40,9 @@ FluidbookCartMopec.prototype = { init: function () { var $this = this; + $(document).on('change', '[data-menu="cart"] .input-number', function () { - $this.updateCartFromQuantities(); + $this.updateCartFromQuantities(this); return true; }); @@ -57,64 +62,72 @@ FluidbookCartMopec.prototype = { }); }); - 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; @@ -126,18 +139,8 @@ FluidbookCartMopec.prototype = { }); 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()}); }, @@ -163,18 +166,17 @@ FluidbookCartMopec.prototype = { var content = ''; 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 += ''; - content += ''; - content += ''; + content += ''; + content += ''; content += ''; content += ''; - content += ''; + content += ''; content += ''; totalht += ht; @@ -183,51 +185,43 @@ FluidbookCartMopec.prototype = { content += '
' + item.product_name + '
Prix unitaire: ' + $this.formatPrice(unit); - content += '
Prix : ' + $this.formatPrice(ht, 'HT') + '
' + item.product_name + '
' + $this.fluidbook.l10n.__('unit price') + ': ' + $this.formatPrice(unit); + content += '
' + $this.fluidbook.l10n.__('price') + ': ' + $this.formatPrice(ht) + '
' + $this.formatPrice(unit) + '' + $this.formatPrice(ht) + '' + getSpriteIcon('interface-close') + '' + getSpriteIcon('interface-close') + '
'; content += ''; content += ''; - content += ''; + content += ''; content += '
Total' + $this.formatPrice(this.data.subtotalAmount) + '
' + $this.fluidbook.l10n.__('total') + '' + $this.formatPrice($this.parseFloat(this.data.subtotalAmount)) + '
'; content += ''; 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 () { @@ -262,11 +256,23 @@ FluidbookCartMopec.prototype = { }, 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); }, diff --git a/js/libs/fluidbook/fluidbook.cart.js b/js/libs/fluidbook/fluidbook.cart.js index 8f0c72c9..3324e378 100644 --- a/js/libs/fluidbook/fluidbook.cart.js +++ b/js/libs/fluidbook/fluidbook.cart.js @@ -22,7 +22,7 @@ FluidbookCart.prototype = { $(document).on('click', '[data-cart-ref]', function () { var qty = 1; - if ($(this).attr('data-cart-qty') !== null) { + if ($(this).data('cart-qty') !== null) { qty = parseInt($(this).attr('data-cart-qty')); } diff --git a/js/libs/fluidbook/fluidbook.js b/js/libs/fluidbook/fluidbook.js index 5b6e4ac0..5728e511 100644 --- a/js/libs/fluidbook/fluidbook.js +++ b/js/libs/fluidbook/fluidbook.js @@ -391,7 +391,7 @@ Fluidbook.prototype = { } } - $(this).trigger('fluidbook.hashchange',[args.slice()]); + $(this).trigger('fluidbook.hashchange', [args.slice()]); if (args[1] === 'closeview') { return this.setCurrentPage(this.currentPage); @@ -945,6 +945,7 @@ Fluidbook.prototype = { win = window; } + console.log('target'); if (target == undefined) { target = '_self'; @@ -991,6 +992,10 @@ Fluidbook.prototype = { replace = undefined; } // Open the window + if (mtarget === '_popupiframe') { + $this.openInPopupIframe(url); + return false; + } var w; if (options == undefined && replace == undefined) { if (this.support.IE == 0) { @@ -1018,6 +1023,14 @@ Fluidbook.prototype = { return w; }, + openInPopupIframe: function (url, callback) { + this.menu.openView('freeiframe', url, '', function () { + if (callback !== undefined) { + callback(); + } + }); + }, + setFlag: function (name, value) { if (value === undefined) { value = true; diff --git a/js/libs/fluidbook/fluidbook.menu.js b/js/libs/fluidbook/fluidbook.menu.js index 98978945..b6d08269 100644 --- a/js/libs/fluidbook/fluidbook.menu.js +++ b/js/libs/fluidbook/fluidbook.menu.js @@ -105,6 +105,8 @@ FluidbookMenu.prototype = { 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') { @@ -157,7 +159,7 @@ FluidbookMenu.prototype = { }, 420); }, - viewWrap: function (content, menu, attributes, cls,replace) { + viewWrap: function (content, menu, attributes, cls, replace) { if (attributes === undefined) { attributes = ''; } @@ -165,9 +167,9 @@ FluidbookMenu.prototype = { cls = ''; } var res = ''; - if(replace===true){ + if (replace === true) { $("#view").html(res); - }else { + } else { $("#view").append(res); } }, @@ -222,24 +224,22 @@ FluidbookMenu.prototype = { } }, - openIframe: function (iframe, callback) { + openFreeiframe: function (url, callback) { + var markup = '
'; + markup += ''; + markup += '
'; + 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 += '
'; view += markup; view += '
'; - 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(); @@ -259,6 +259,21 @@ FluidbookMenu.prototype = { }); }, + 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')); diff --git a/js/libs/fluidbook/links/fluidbook.links.zoom.js b/js/libs/fluidbook/links/fluidbook.links.zoom.js index 05d5ca0e..33e4f763 100644 --- a/js/libs/fluidbook/links/fluidbook.links.zoom.js +++ b/js/libs/fluidbook/links/fluidbook.links.zoom.js @@ -171,8 +171,14 @@ FluidbookLinksZoom.prototype = { for (var i = from; increment === 1 ? i <= to : i >= to; i += increment) { var data = zoomLink.data('d-' + i); - if (data !== undefined) { - var j = i + 1; + + var j = i + 1; + var action = $this.fluidbook.settings['product_zoom_action_' + j]; + + if (!action) { + action = 'link'; + } + if (data !== undefined || action === 'addtocart') { var label = $this.fluidbook.settings['product_zoom_label_' + j]; var icon = getSpriteIcon($this.fluidbook.settings['product_zoom_icon_' + j]) !== 'none' ? getSpriteIcon($this.fluidbook.settings['product_zoom_icon_' + j]) : ''; var linkClass = ""; @@ -182,31 +188,27 @@ FluidbookLinksZoom.prototype = { linkClass = " nolabel"; } - var action = $this.fluidbook.settings['product_zoom_action_' + j]; - if (!action) { - action = 'link'; - } - - if (!data) { - continue; - } - menu += '' + icon + label + ''; }