]> _ Git - fluidbook-html5.git/commitdiff
wip #3828 @1
authorVincent Vanwaelscappel <vincent@cubedesigners.com>
Fri, 18 Sep 2020 09:12:51 +0000 (11:12 +0200)
committerVincent Vanwaelscappel <vincent@cubedesigners.com>
Fri, 18 Sep 2020 09:12:51 +0000 (11:12 +0200)
js/libs/fluidbook/cart/fluidbook.cart.mopec.js

index 64d77cdcbbb3e3bcee999e9ec9c012b143e71974..fbb66a0c45840691b69790d7d30d2c186ea593ed 100644 (file)
@@ -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);
             }
         });
     },