this.data;
this.handleTooltips = true;
this.handleTaxes = false;
+ this.minQuantities = {};
+ this.idBySku = {};
this.initBaseURL();
this.init();
if (this.dataok()) {
this.updateCart();
}
- if (callback !== undefined) {
- callback();
- }
+ this.updateMinQuantities(function () {
+ if (callback !== undefined) {
+ callback();
+ }
+ });
},
init: function () {
addToCart: function (ref, quantity) {
var $this = this;
this.fluidbook.displayLoader();
- if (quantity === undefined) {
- quantity = 1;
- }
this.getProductIDBySKU(ref, function (product_id) {
if (product_id === null) {
$this.fluidbook.hideLoader();
$this.fluidbook.openInPopupIframe(url);
} else {
+ var minQuantity = $this.minQuantities[ref];
+ if (quantity === undefined || isNaN(quantity) || quantity < minQuantity) {
+ quantity = minQuantity
+ }
+
$.ajax({
url: $this.baseURL + 'checkout/cart/add',
cache: false,
});
return false;
+ },
+
+ getMinQuantity: function (sku, callback) {
+ if (this.minQuantities[sku] !== undefined) {
+ callback(this.minQuantities[sku]);
+ return;
+ }
+ var $this = this;
+ this.getProductIDBySKU(sku, function (product_id) {
+ if ($this.minQuantities[sku] === undefined) {
+ $this.minQuantities[sku] = 1;
+ }
+ callback($this.minQuantities[sku]);
+ });
+ },
+ updateMinQuantities: function (callback) {
+ var skus = [];
+ $.each(this.data.items, function (index, item) {
+ skus.push(item.product_sku);
+ });
+ this._updateMinQuantity(skus, callback);
+ },
+
+ _updateMinQuantity: function (list, callback) {
+ if (list.length === 0) {
+ callback();
+ return;
+ }
+ var sku = list.pop();
+ var $this = this;
+ this.getMinQuantity(sku, function () {
+ $this._updateMinQuantity(list, callback);
+ });
},
getProductIDBySKU: function (sku, callback) {
+ if (this.idBySku[sku] !== undefined) {
+ callback(this.idBySku[sku]);
+ return;
+ }
+ var $this = this;
$.ajax({
url: this.baseURL + 'fastorder/index/search',
cache: false,
product_id = null;
} else {
product_id = data[0].product_id;
+ var min = 1;
+ if (data[0].min !== undefined) {
+ min = data[0].min;
+ }
+ $this.minQuantities[sku] = min;
}
+ $this.idBySku[sku] = product_id;
callback(product_id);
}, error: function () {
+ $this.idBySku[sku] = null;
callback(null);
}
});
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>';
- content += '<td class="quantity"><input name="' + item.item_id + '" class="cartqty" type="number" min="0" max="10000" value="' + qty + '" step="1" /></td>';
+ var step = $this.minQuantities[item.product_sku];
+ 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="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>';