From: Vincent Vanwaelscappel Date: Mon, 21 Sep 2020 10:16:35 +0000 (+0200) Subject: wait #3891 @2 X-Git-Url: http://git.cubedesigners.com/?a=commitdiff_plain;h=766c6d717ad40d340b5bf06c4acc5a6cefcddb0a;p=fluidbook-html5.git wait #3891 @2 --- diff --git a/js/libs/fluidbook/cart/fluidbook.cart.mopec.js b/js/libs/fluidbook/cart/fluidbook.cart.mopec.js index f65bf77e..ce0a0436 100644 --- a/js/libs/fluidbook/cart/fluidbook.cart.mopec.js +++ b/js/libs/fluidbook/cart/fluidbook.cart.mopec.js @@ -4,6 +4,7 @@ function FluidbookCartMopec(cart) { this.fluidbook = this.cart.fluidbook; this.items = this.cart.getSavedData(); this.data; + this.loggedIn = false; this.handleTooltips = true; this.handleTaxes = false; this.minQuantities = {}; @@ -22,19 +23,20 @@ FluidbookCartMopec.prototype = { this.sendCookie(); $.ajax({ - url: this.baseURL + "customer/section/load/?sections=cart&update_section_id=false", + url: this.baseURL + "customer/section/load/", dataType: 'json', cache: false, xhrFields: {withCredentials: true}, success: function (data) { $this.fluidbook.hideLoader(); - $this.updateCartFromData(data.cart, callback); + $this.updateCartFromData(data.cart, data.customer, callback); }, }); }, - updateCartFromData: function (data, callback) { + updateCartFromData: function (data, customer, callback) { this.data = data; + this.loggedIn = customer.websiteId !== undefined && customer.websiteId !== null; if (this.dataok()) { this.updateCart(); } @@ -71,8 +73,20 @@ FluidbookCartMopec.prototype = { }, + + 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) { @@ -85,7 +99,7 @@ FluidbookCartMopec.prototype = { if (quantity === undefined || isNaN(quantity) || quantity < minQuantity) { quantity = minQuantity } - + $.ajax({ url: $this.baseURL + 'checkout/cart/add', cache: false, @@ -224,6 +238,10 @@ FluidbookCartMopec.prototype = { }, openCart: function (p2, callback) { + if (!this.checkLoginSession()) { + callback(); + return; + } if (!this.dataok()) { callback(); return;