]> _ Git - fluidbook-html5.git/commitdiff
wait #3891 @2
authorVincent Vanwaelscappel <vincent@cubedesigners.com>
Mon, 21 Sep 2020 10:16:35 +0000 (12:16 +0200)
committerVincent Vanwaelscappel <vincent@cubedesigners.com>
Mon, 21 Sep 2020 10:16:35 +0000 (12:16 +0200)
js/libs/fluidbook/cart/fluidbook.cart.mopec.js

index f65bf77e85029da1cdcfde61decee082477f3ca0..ce0a0436b06a44df70c3a91115bb6dd85a1c7233 100644 (file)
@@ -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;