}
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;
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);
}
});
},