vanilli-shop-client
Advanced tools
Comparing version 1.5.0 to 1.5.1
@@ -27,5 +27,5 @@ import BaseStore from "./base-store"; | ||
private loadCart; | ||
private validateQuickAddingToCart; | ||
private validateAddingToCart; | ||
private validateProductStock; | ||
private validateItemParameter; | ||
} |
@@ -99,3 +99,3 @@ "use strict"; | ||
CartStore.prototype.quickAddToCart = function (product) { | ||
var valid = this.validateQuickAddingToCart(product); | ||
var valid = this.validateProductStock(product, 1); | ||
if (valid) { | ||
@@ -211,16 +211,2 @@ var item = { | ||
}; | ||
CartStore.prototype.validateQuickAddingToCart = function (product) { | ||
var notificationStore = this.notificationStore; | ||
var translationStore = this.translationStore; | ||
var stock = product.stock; | ||
if (stock !== undefined && 1 > stock) { | ||
notificationStore.notifyError(translationStore.t("product.out-of-stock", "Toodet {0} on saadaval ainult {1}", [product.name, stock.toString()])); | ||
return false; | ||
} | ||
if (product.hasParameters) { | ||
notificationStore.notifyError(translationStore.t("product.has-parameters", "Toote täpsemate valikute tegemiseks palume minna detailvaatesse")); | ||
return false; | ||
} | ||
return true; | ||
}; | ||
CartStore.prototype.validateAddingToCart = function (product, qty) { | ||
@@ -240,5 +226,16 @@ var notificationStore = this.notificationStore; | ||
} | ||
return this.validateProductStock(product, qty); | ||
}; | ||
CartStore.prototype.validateProductStock = function (product, qty) { | ||
var notificationStore = this.notificationStore; | ||
var translationStore = this.translationStore; | ||
var stock = product.stock; | ||
if (stock !== undefined && qty > stock) { | ||
notificationStore.notifyError(translationStore.t("product.out-of-stock", "Toodet {0} on saadaval ainult {1}", [product.name, stock.toString()])); | ||
var productName = product.name; | ||
if (stock === 0) { | ||
notificationStore.notifyError(translationStore.t("product.out-of-stock", "Toodet {0} pole hetkel saadaval", [productName])); | ||
} | ||
else { | ||
notificationStore.notifyError(translationStore.t("product.not-enough-stock", "Toodet {0} on saadaval ainult {1}", [productName, stock.toString()])); | ||
} | ||
return false; | ||
@@ -245,0 +242,0 @@ } |
{ | ||
"name": "vanilli-shop-client", | ||
"version": "1.5.0", | ||
"version": "1.5.1", | ||
"description": "Client for Vanilli Shop API", | ||
@@ -5,0 +5,0 @@ "main": "dist/index.js", |
@@ -99,3 +99,3 @@ import BaseStore from "./base-store"; | ||
quickAddToCart(product: IProductDto) { | ||
const valid = this.validateQuickAddingToCart(product); | ||
const valid = this.validateProductStock(product, 1); | ||
@@ -237,20 +237,2 @@ if (valid) { | ||
private validateQuickAddingToCart(product: IProductDto): boolean { | ||
const notificationStore = this.notificationStore; | ||
const translationStore = this.translationStore; | ||
const stock = product.stock; | ||
if (stock !== undefined && 1 > stock) { | ||
notificationStore.notifyError(translationStore.t("product.out-of-stock", "Toodet {0} on saadaval ainult {1}", [product.name, stock.toString()])); | ||
return false; | ||
} | ||
if (product.hasParameters) { | ||
notificationStore.notifyError(translationStore.t("product.has-parameters", "Toote täpsemate valikute tegemiseks palume minna detailvaatesse")); | ||
return false; | ||
} | ||
return true; | ||
} | ||
private validateAddingToCart(product: IProductDetailsDto, qty: number): boolean { | ||
@@ -273,6 +255,19 @@ const notificationStore = this.notificationStore; | ||
return this.validateProductStock(product, qty); | ||
} | ||
private validateProductStock(product: IProductDetailsDto, qty: number): boolean { | ||
const notificationStore = this.notificationStore; | ||
const translationStore = this.translationStore; | ||
const stock = product.stock; | ||
if (stock !== undefined && qty > stock) { | ||
notificationStore.notifyError(translationStore.t("product.out-of-stock", "Toodet {0} on saadaval ainult {1}", [product.name, stock.toString()])); | ||
const productName = product.name; | ||
if (stock === 0) { | ||
notificationStore.notifyError(translationStore.t("product.out-of-stock", "Toodet {0} pole hetkel saadaval", [productName])); | ||
} else { | ||
notificationStore.notifyError(translationStore.t("product.not-enough-stock", "Toodet {0} on saadaval ainult {1}", [productName, stock.toString()])); | ||
} | ||
return false; | ||
@@ -279,0 +274,0 @@ } |
260073
5753