From: Vincent Vanwaelscappel Date: Fri, 23 Oct 2020 19:37:54 +0000 (+0200) Subject: wip #3977 @3 X-Git-Url: http://git.cubedesigners.com/?a=commitdiff_plain;h=0f320ba00c0c597dc128a6d439d84153d2094459;p=fluidbook-html5.git wip #3977 @3 --- diff --git a/images/interface.svg b/images/interface.svg index 3523ab3f..4f497c6a 100644 --- a/images/interface.svg +++ b/images/interface.svg @@ -314,4 +314,39 @@ + + + + + + + + + + + + + + + + + + diff --git a/js/libs/fluidbook/cart/fluidbook.cart.puma.js b/js/libs/fluidbook/cart/fluidbook.cart.puma.js new file mode 100644 index 00000000..648722d1 --- /dev/null +++ b/js/libs/fluidbook/cart/fluidbook.cart.puma.js @@ -0,0 +1,427 @@ +function FluidbookCartPuma(cart) { + var $this = this; + this.cart = cart; + this.fluidbook = this.cart.fluidbook; + this.items = this.cart.getSavedData(); + this.data; + this.loggedIn = false; + this.handleTooltips = true; + this.handleTaxes = false; + this.minQuantities = {}; + this.idBySku = {}; + + this.initBaseURL(); + this.init(); +} + +FluidbookCartPuma.prototype = { + initBaseURL: function () { + this.baseURL = window.location.protocol + '//' + window.location.host + '/' + this.fluidbook.l10n.currentLang + '/'; + }, + updateCartData: function (callback) { + var $this = this; + this.sendCookie(); + + $.ajax({ + url: this.baseURL + "customer/section/load/", + dataType: 'json', + cache: false, + xhrFields: {withCredentials: true}, + success: function (data) { + $this.fluidbook.hideLoader(); + $this.updateCartFromData(data.cart, data.customer, callback); + }, + }); + }, + + updateCartFromData: function (data, customer, callback) { + this.data = data; + this.loggedIn = customer.websiteId !== undefined && customer.websiteId !== null; + if (this.dataok()) { + this.updateCart(); + } + this.updateMinQuantities(function () { + if (callback !== undefined) { + callback(); + } + }); + }, + + init: function () { + var $this = this; + + $(document).on('change', '[data-menu="cart"] .input-number', function () { + $this.updateCartFromQuantities(this); + return true; + }); + + this.updateCartData(function () { + + }); + + setTimeout(function () { + $this.updateCartData(function () { + + }); + }, 60000); + + $(window).on('focus', function () { + $this.fluidbook.menu.closeView(function () { + }, true, false); + $this.updateCartData(function () { + + }); + }); + + + }, + + checkLoginSession: function () { + if (!this.loggedIn) { + this.fluidbook.links.triggerLinkById('login'); + return false; + } + return true; + }, + + addToCart: function (ref, quantity) { + var $this = this; + if (!this.checkLoginSession()) { + return; + } + this.fluidbook.displayLoader(); + + this.getProductIDBySKU(ref, function (product_id) { + if (product_id === null) { + var url = this.fluidbook.settings.product_zoom_references[ref][0]; + $this.fluidbook.hideLoader(); + $this.fluidbook.openInPopupIframe(url); + } else { + var minQuantity = $this.minQuantities[ref]; + if (quantity === undefined || isNaN(quantity) || quantity < minQuantity) { + quantity = minQuantity + } + + $.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 () { + $this.fluidbook.menu.openView('cart'); + }); + } + } + }); + } + }); + + return false; + }, + + getMinQuantity: function (sku, callback) { + if (this.minQuantities[sku] !== undefined) { + callback(this.minQuantities[sku]); + return; + } + var $this = this; + console.log('check qty for ' + sku); + this.getProductIDBySKU(sku, function (product_id) { + if ($this.minQuantities[sku] === undefined) { + console.log('no qty for ' + sku); + var e = sku.split('.'); + if (e.length > 1) { + e.pop(); + var nsku = e.join('.') + '.'; + console.log('check qty for ' + nsku); + $this.getProductIDBySKU(nsku, function (product_id) { + if ($this.minQuantities[nsku] === undefined) { + console.log('no qty for ' + nsku); + var ee = nsku.split('.'); + if (ee.length > 1) { + ee.pop(); + ee.pop(); + var nnsku = ee.join('.') + '.'; + console.log('check qty for ' + nnsku); + $this.getProductIDBySKU(nnsku, function (product_id) { + console.log('no qty for ' + nnsku); + if ($this.minQuantities[nnsku] === undefined) { + $this.minQuantities[nnsku] = 1; + } + $this.minQuantities[nsku] = $this.minQuantities[nnsku]; + $this.minQuantities[sku] = $this.minQuantities[nnsku]; + callback($this.minQuantities[nnsku]); + }); + return; + } + } else { + $this.minQuantities[sku] = $this.minQuantities[nsku]; + } + callback($this.minQuantities[nsku]); + }); + return; + } + } else { + callback($this.minQuantities[sku]); + } + }); + }, + + updateMinQuantities: function (callback) { + var skus = []; + $.each(this.data.items, function (index, item) { + skus.push(item.product_sku); + }); + this._updateMinQuantity(skus, callback); + }, + + _updateMinQuantity: function (list, callback) { + if (list.length === 0) { + callback(); + return; + } + var sku = list.pop(); + var $this = this; + this.getMinQuantity(sku, function () { + $this._updateMinQuantity(list, callback); + }); + }, + + getProductIDBySKU: function (sku, callback) { + if (this.idBySku[sku] !== undefined) { + callback(this.idBySku[sku]); + return; + } + var $this = this; + $.ajax({ + url: this.baseURL + 'fastorder/index/search', + cache: false, + data: {product: sku, sort_order: 0}, + method: 'post', + xhrFields: {withCredentials: true}, + dataType: 'json', + success: function (data) { + var product_id; + if (data === null || data === undefined || data === '' || data.length === 0 || !data) { + product_id = null; + } else { + product_id = data[0].product_id; + var min = 1; + if (data[0].min !== undefined) { + min = data[0].min; + } + console.log('set min qty for ' + sku + ' : ' + min) + $this.minQuantities[sku] = min; + } + $this.idBySku[sku] = product_id; + callback(product_id); + }, error: function () { + $this.idBySku[sku] = null; + callback(null); + } + }); + }, + + sendCookie: function () { + }, + + removeFromCart: function (item_id, callback) { + var $this = this; + this.fluidbook.displayLoader(); + $.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 () { + if (!this.dataok()) { + return 0; + } + return this.data.summary_count; + }, + getAllQuantities: function () { + var res = 0; + this.data.find('item quantite').each(function () { + res += parseInt($(this).text()); + }); + return res; + }, + + updateIcon: function () { + $(this.fluidbook).trigger('fluidbook.cart.updateIcon', {number: this.getItemsNumbers()}); + }, + + openMenu: function (p1, p2, callback) { + if (!this.dataok()) { + callback(); + return; + } + this.fluidbook.menu.quickCloseView(); + return this.openCart(p2, callback); + }, + + openCart: function (p2, callback) { + if (!this.checkLoginSession()) { + callback(); + return; + } + if (!this.dataok()) { + callback(); + return; + } + this._endMenu(this.fluidbook.l10n.__('your cart'), this.getCartContent(), function () { + $('input[type="number"]').inputNumber(); + + callback(); + }); + }, + + dataok: function () { + return this.data !== undefined && this.data !== null; + }, + + getCartContent: function () { + if (this.getItemsNumbers() == 0) { + return '
' + this.fluidbook.l10n.__('your cart is empty') + '
'; + } + var $this = this; + var content = ''; + var totalht = 0; + $.each(this.data.items, function (index, item) { + var qty = $this.parseInt(item.qty); + var unit = $this.parseFloat(item.product_price_value); + var ht = unit * qty; + + var options = {}; + $.each(item.options, function (k, opt) { + options[opt.option_id] = opt.option_value; + }); + + content += ''; + content += ''; + var step = $this.minQuantities[item.product_sku]; + if (step === undefined) { + step = 1; + } + content += ''; + content += ''; + content += ''; + content += ''; + content += ''; + + totalht += ht; + }); + + content += '
' + 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') + '
'; + content += ''; + content += ''; + content += ''; + content += '
' + $this.fluidbook.l10n.__('total') + '' + $this.formatPrice($this.parseFloat(this.data.subtotalAmount)) + '
'; + + content += ''; + + return content; + }, + + getFormKey: function () { + return $.cookie('form_key'); + }, + + updateCartFromQuantities: function (el) { + var $this = this; + var input = $(el).find('input.cartqty'); + var item_id = $(input).attr('name'); + var options = $(input).data('options'); + var newVal = $this.parseInt($(input).val()); + + if (newVal === 0) { + this.removeFromCart(item_id, function () { + }); + } else { + this.fluidbook.displayLoader(); + + $.ajax({ + url: $this.baseURL + 'checkout/cart/updateItemOptions/id/' + item_id, + method: "post", + data: {item: item_id, qty: newVal, super_attribute: options, form_key: this.getFormKey()}, + xhrFields: {withCredentials: true}, + success: function () { + $this.updateCartData(function () { + + }); + } + }) + } + }, + + updateCart: function () { + if (!this.dataok()) { + return; + } + $('[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; + }, + + _endMenu: function (title, content, callback) { + var view = this.fluidbook.menu.getCaption(title); + view += '
'; + view += "" + content; + view += '
'; + this.fluidbook.menu.viewWrap(view, 'cart'); + callback(); + }, + + 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); + }, +}; \ No newline at end of file diff --git a/js/libs/fluidbook/fluidbook.cart.js b/js/libs/fluidbook/fluidbook.cart.js index 3324e378..b89910ee 100644 --- a/js/libs/fluidbook/fluidbook.cart.js +++ b/js/libs/fluidbook/fluidbook.cart.js @@ -44,6 +44,8 @@ FluidbookCart.prototype = { return new FluidbookCartRemarkable(this); case 'Mopec': return new FluidbookCartMopec(this); + case 'Puma': + return new FluidbookCartPuma(this); default: return null; } diff --git a/js/libs/fluidbook/fluidbook.video.js b/js/libs/fluidbook/fluidbook.video.js index 1960d460..578aa774 100644 --- a/js/libs/fluidbook/fluidbook.video.js +++ b/js/libs/fluidbook/fluidbook.video.js @@ -112,10 +112,12 @@ FluidbookVideo.prototype = { console.warn('Error disposing player #' + id + ' -- ' + exception.message); } } - - if (fluidbook.settings.mobileVideosPath == '') { - path = "data/links/" + name; + if (name.indexOf('data/') !== -1) { + path = name; + } else { + path = "data/links/" + name; + } } else { path = fluidbook.settings.mobileVideosPath + name; if (!fluidbook.settings.standalone && path.substr(0, 3) == '../') { diff --git a/js/libs/fluidbook/links/fluidbook.links.zoom.js b/js/libs/fluidbook/links/fluidbook.links.zoom.js index 84c527f4..47047c7c 100644 --- a/js/libs/fluidbook/links/fluidbook.links.zoom.js +++ b/js/libs/fluidbook/links/fluidbook.links.zoom.js @@ -188,6 +188,9 @@ FluidbookLinksZoom.prototype = { linkClass = " nolabel"; } + var hash = forge_sha256(data); + var add = ''; + menu += ''; + menu += ' data-multimedia="' + encodeURIComponent(markup) + '"' + } else if (action === 'videofile') { + menu += ' href="#/video/' + hash + '" '; + var markup = '
'; + menu += ' data-video="' + encodeURIComponent(markup) + '"' + } else if (action === 'videogif') { + menu += ' href="#/video/' + hash + '" '; + var markup = '
'; + menu += ' data-video="' + encodeURIComponent(markup) + '"' } menu += 'data-tooltip="' + $this.fluidbook.settings['product_zoom_tooltip_' + j] + '" class="button ' + linkClass + '">' + icon + label + '
'; }