]> _ Git - fluidbook-html5.git/commitdiff
wait #3828 @1.5
authorVincent Vanwaelscappel <vincent@cubedesigners.com>
Mon, 21 Sep 2020 15:45:15 +0000 (17:45 +0200)
committerVincent Vanwaelscappel <vincent@cubedesigners.com>
Mon, 21 Sep 2020 15:45:15 +0000 (17:45 +0200)
js/libs/fluidbook/cart/fluidbook.cart.mopec.js

index d384665c5682717992e73acdc2ea5b6b7d5af0cf..82e57f3e67dec9ecba9f9e5c4bf8cc60841d4986 100644 (file)
@@ -93,7 +93,7 @@ FluidbookCartMopec.prototype = {
 
         this.getProductIDBySKU(ref, function (product_id) {
             if (product_id === null) {
-                var url = this.fluidbook.settings.product_zoom_references[ref];
+                var url = this.fluidbook.settings.product_zoom_references[ref][0];
                 $this.fluidbook.hideLoader();
                 $this.fluidbook.openInPopupIframe(url);
             } else {
@@ -134,11 +134,45 @@ FluidbookCartMopec.prototype = {
             return;
         }
         var $this = this;
+        console.log('check qty for ' + sku);
         this.getProductIDBySKU(sku, function (product_id) {
             if ($this.minQuantities[sku] === undefined) {
-                $this.minQuantities[sku] = 1;
+                console.log('no qty for ' + sku);
+                var e = sku.split('.');
+                if (e.length > 1) {
+                    e.pop();
+                    var nsku = e.join('.') + '.';
+                    console.log('check qty for ' + nsku);
+                    $this.getProductIDBySKU(nsku, function (product_id) {
+                        if ($this.minQuantities[nsku] === undefined) {
+                            console.log('no qty for ' + nsku);
+                            var ee = nsku.split('.');
+                            if (ee.length > 1) {
+                                ee.pop();
+                                ee.pop();
+                                var nnsku = ee.join('.') + '.';
+                                console.log('check qty for ' + nnsku);
+                                $this.getProductIDBySKU(nnsku, function (product_id) {
+                                    console.log('no qty for ' + nnsku);
+                                    if ($this.minQuantities[nnsku] === undefined) {
+                                        $this.minQuantities[nnsku] = 1;
+                                    }
+                                    $this.minQuantities[nsku] = $this.minQuantities[nnsku];
+                                    $this.minQuantities[sku] = $this.minQuantities[nnsku];
+                                    callback($this.minQuantities[nnsku]);
+                                });
+                                return;
+                            }
+                        } else {
+                            $this.minQuantities[sku] = $this.minQuantities[nsku];
+                        }
+                        callback($this.minQuantities[nsku]);
+                    });
+                    return;
+                }
+            } else {
+                callback($this.minQuantities[sku]);
             }
-            callback($this.minQuantities[sku]);
         });
     },
 
@@ -185,6 +219,7 @@ FluidbookCartMopec.prototype = {
                     if (data[0].min !== undefined) {
                         min = data[0].min;
                     }
+                    console.log('set min qty for ' + sku + ' : ' + min)
                     $this.minQuantities[sku] = min;
                 }
                 $this.idBySku[sku] = product_id;
@@ -271,6 +306,11 @@ FluidbookCartMopec.prototype = {
             var unit = $this.parseFloat(item.product_price_value);
             var ht = unit * qty;
 
+            var options = {};
+            $.each(item.options, function (k, opt) {
+                options[opt.option_id] = opt.option_value;
+            });
+
             content += '<tr>';
             content += '<td class="name">' + item.product_name + '<div class="m">' + $this.fluidbook.l10n.__('unit price') + ': ' + $this.formatPrice(unit);
             content += '<br />' + $this.fluidbook.l10n.__('price') + ': ' + $this.formatPrice(ht) + '</div></td>';
@@ -278,7 +318,7 @@ FluidbookCartMopec.prototype = {
             if (step === undefined) {
                 step = 1;
             }
-            content += '<td class="quantity"><input name="' + item.item_id + '" class="cartqty" type="number" step="' + step + '" min="0" max="10000" value="' + qty + '" /></td>';
+            content += '<td class="quantity"><input data-options=\'' + JSON.stringify(options) + '\' name="' + item.item_id + '" class="cartqty" type="number" step="' + step + '" min="0" max="10000" value="' + qty + '" /></td>';
             content += '<td class="price_unit">' + $this.formatPrice(unit) + '</td>';
             content += '<td class="price_excluding_taxes">' + $this.formatPrice(ht) + '</td>';
             content += '<td class="delete"><a href="#" data-cart-delete="' + item.item_id + '">' + getSpriteIcon('interface-close') + '</a></td>';
@@ -308,6 +348,7 @@ FluidbookCartMopec.prototype = {
         var $this = this;
         var input = $(el).find('input.cartqty');
         var item_id = $(input).attr('name');
+        var options = $(input).data('options');
         var newVal = $this.parseInt($(input).val());
 
         if (newVal === 0) {
@@ -315,10 +356,11 @@ FluidbookCartMopec.prototype = {
             });
         } else {
             this.fluidbook.displayLoader();
+
             $.ajax({
                 url: $this.baseURL + 'checkout/cart/updateItemOptions/id/' + item_id,
                 method: "post",
-                data: {item: item_id, qty: newVal, form_key: this.getFormKey()},
+                data: {item: item_id, qty: newVal, super_attribute: options, form_key: this.getFormKey()},
                 xhrFields: {withCredentials: true},
                 success: function () {
                     $this.updateCartData(function () {