From: Vincent Vanwaelscappel Date: Fri, 18 Sep 2020 09:12:51 +0000 (+0200) Subject: wip #3828 @1 X-Git-Url: http://git.cubedesigners.com/?a=commitdiff_plain;h=0558ae9a684601e08499adfba2dbd7b324613c9d;p=fluidbook-html5.git wip #3828 @1 --- diff --git a/js/libs/fluidbook/cart/fluidbook.cart.mopec.js b/js/libs/fluidbook/cart/fluidbook.cart.mopec.js index 64d77cdc..fbb66a0c 100644 --- a/js/libs/fluidbook/cart/fluidbook.cart.mopec.js +++ b/js/libs/fluidbook/cart/fluidbook.cart.mopec.js @@ -75,26 +75,32 @@ FluidbookCartMopec.prototype = { } 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 () { - $this.fluidbook.menu.openView('cart'); - }); + if (product_id === null) { + var url = this.fluidbook.settings.product_zoom_references[ref]; + $this.fluidbook.hideLoader(); + $this.fluidbook.openInPopupIframe(url); + } else { + $.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; @@ -110,8 +116,15 @@ FluidbookCartMopec.prototype = { xhrFields: {withCredentials: true}, dataType: 'json', success: function (data) { - var product_id = data[0].product_id; + var product_id; + if (data === null || data === undefined || data === '' || data.length === 0 || !data) { + product_id = null; + } else { + product_id = data[0].product_id; + } callback(product_id); + }, error: function () { + callback(null); } }); },