vanilli-shop-client
Advanced tools
Comparing version 1.2.6 to 1.2.7
@@ -10,5 +10,5 @@ import Base, { IBaseProps } from "./base"; | ||
} | ||
export default class ProductDetailsBase extends Base<IProductDetailsBase> { | ||
export default class ProductDetailsBase<T extends IProductDetailsBase, S = {}> extends Base<T, S> { | ||
componentDidMount(): Promise<void>; | ||
} | ||
export {}; |
@@ -65,14 +65,15 @@ "use strict"; | ||
ProductDetailsBase.prototype.componentDidMount = function () { | ||
var _a, _b; | ||
return __awaiter(this, void 0, void 0, function () { | ||
var props, refType, productStore, product; | ||
return __generator(this, function (_a) { | ||
switch (_a.label) { | ||
return __generator(this, function (_c) { | ||
switch (_c.label) { | ||
case 0: | ||
props = this.props; | ||
refType = qs_1.default.parse(props.location.search, { ignoreQueryPrefix: true }).refType; | ||
refType = qs_1.default.parse((_a = props.location) === null || _a === void 0 ? void 0 : _a.search, { ignoreQueryPrefix: true }).refType; | ||
if (!refType) return [3 /*break*/, 3]; | ||
productStore = props.productStore; | ||
return [4 /*yield*/, productStore.getProductByRef(props.match.params.ref, refType)]; | ||
return [4 /*yield*/, productStore.getProductByRef((_b = props.match) === null || _b === void 0 ? void 0 : _b.params.ref, refType)]; | ||
case 1: | ||
_a.sent(); | ||
_c.sent(); | ||
product = productStore.product; | ||
@@ -82,4 +83,4 @@ if (!(product === null || product === void 0 ? void 0 : product.id)) return [3 /*break*/, 3]; | ||
case 2: | ||
_a.sent(); | ||
_a.label = 3; | ||
_c.sent(); | ||
_c.label = 3; | ||
case 3: return [2 /*return*/]; | ||
@@ -86,0 +87,0 @@ } |
@@ -27,2 +27,3 @@ import BaseStore from "./base-store"; | ||
private loadCart; | ||
private validateAddingToCart; | ||
} |
@@ -125,11 +125,4 @@ "use strict"; | ||
} | ||
var notificationStore = this.notificationStore; | ||
var translationStore = this.translationStore; | ||
if (qty > 0) { | ||
var stock = product.stock; | ||
var productName = product.name; | ||
if (stock && qty > stock) { | ||
this.notificationStore.notifyError(translationStore.t("product.out-of-stock", "Toodet {0} on saadaval ainult {1}", [productName, stock.toString()])); | ||
return; | ||
} | ||
var valid = this.validateAddingToCart(product, qty); | ||
if (valid) { | ||
var parameterStore = this.rootStore.parameterStore; | ||
@@ -140,3 +133,3 @@ var item = { | ||
productCode: product.code, | ||
productName: productName, | ||
productName: product.name, | ||
categoryId: product.categoryId, | ||
@@ -156,9 +149,6 @@ price: product.price, | ||
this.updateCart(); | ||
notificationStore.notifySuccess(translationStore.t("cart.added", "{0} lisati {1}tk ostukorvi", [item.productName || "", item.qty.toString()])); | ||
this.notificationStore.notifySuccess(this.translationStore.t("cart.added", "{0} lisati {1}tk ostukorvi", [item.productName || "", item.qty.toString()])); | ||
parameterStore.resetSelectedParameters(); | ||
this.resetSelectedQty(); | ||
} | ||
else { | ||
notificationStore.notifyError(translationStore.t("cart.min-qty", "Lisatav kogus peab olema vähemalt 1")); | ||
} | ||
}; | ||
@@ -227,2 +217,31 @@ CartStore.prototype.changeItemQty = function (qty, itemId) { | ||
}; | ||
CartStore.prototype.validateAddingToCart = function (product, qty) { | ||
var notificationStore = this.notificationStore; | ||
var translationStore = this.translationStore; | ||
var parameterStore = this.rootStore.parameterStore; | ||
var _loop_1 = function (parameter) { | ||
var parameterName = parameter.parameterName; | ||
var selectedParameterValue = parameterStore.selectedParameters.find(function (x) { return x.name == parameterName; }); | ||
if (!selectedParameterValue) { | ||
notificationStore.notifyError(translationStore.t("product.select-parameter-value", "Palun valige {0}", [parameterName.toLowerCase()])); | ||
return { value: false }; | ||
} | ||
}; | ||
for (var _i = 0, _a = parameterStore.parameters; _i < _a.length; _i++) { | ||
var parameter = _a[_i]; | ||
var state_1 = _loop_1(parameter); | ||
if (typeof state_1 === "object") | ||
return state_1.value; | ||
} | ||
if (qty < 1) { | ||
notificationStore.notifyError(translationStore.t("cart.min-qty", "Lisatav kogus peab olema vähemalt 1")); | ||
return false; | ||
} | ||
var stock = product.stock; | ||
if (stock && qty > stock) { | ||
notificationStore.notifyError(translationStore.t("product.out-of-stock", "Toodet {0} on saadaval ainult {1}", [product.name, stock.toString()])); | ||
return false; | ||
} | ||
return true; | ||
}; | ||
__decorate([ | ||
@@ -229,0 +248,0 @@ mobx_1.observable |
{ | ||
"name": "vanilli-shop-client", | ||
"version": "1.2.6", | ||
"version": "1.2.7", | ||
"description": "Client for Vanilli Shop API", | ||
@@ -5,0 +5,0 @@ "main": "dist/index.js", |
@@ -130,14 +130,5 @@ import BaseStore from "./base-store"; | ||
const notificationStore = this.notificationStore; | ||
const translationStore = this.translationStore; | ||
const valid = this.validateAddingToCart(product, qty); | ||
if (qty > 0) { | ||
const stock = product.stock; | ||
const productName = product.name; | ||
if (stock && qty > stock) { | ||
this.notificationStore.notifyError(translationStore.t("product.out-of-stock", "Toodet {0} on saadaval ainult {1}", [productName, stock.toString()])); | ||
return; | ||
} | ||
if (valid) { | ||
const parameterStore = this.rootStore.parameterStore; | ||
@@ -149,3 +140,3 @@ | ||
productCode: product.code, | ||
productName: productName, | ||
productName: product.name, | ||
categoryId: product.categoryId, | ||
@@ -168,7 +159,5 @@ price: product.price, | ||
this.updateCart(); | ||
notificationStore.notifySuccess(translationStore.t("cart.added", "{0} lisati {1}tk ostukorvi", [item.productName || "", item.qty.toString()])); | ||
this.notificationStore.notifySuccess(this.translationStore.t("cart.added", "{0} lisati {1}tk ostukorvi", [item.productName || "", item.qty.toString()])); | ||
parameterStore.resetSelectedParameters(); | ||
this.resetSelectedQty(); | ||
} else { | ||
notificationStore.notifyError(translationStore.t("cart.min-qty", "Lisatav kogus peab olema vähemalt 1")); | ||
} | ||
@@ -253,2 +242,32 @@ } | ||
} | ||
private validateAddingToCart(product: IProductDetailsDto, qty: number): boolean { | ||
const notificationStore = this.notificationStore; | ||
const translationStore = this.translationStore; | ||
const parameterStore = this.rootStore.parameterStore; | ||
for (const parameter of parameterStore.parameters) { | ||
const parameterName = parameter.parameterName; | ||
const selectedParameterValue = parameterStore.selectedParameters.find(x => x.name == parameterName); | ||
if (!selectedParameterValue) { | ||
notificationStore.notifyError(translationStore.t("product.select-parameter-value", "Palun valige {0}", [parameterName.toLowerCase()])); | ||
return false; | ||
} | ||
} | ||
if (qty < 1) { | ||
notificationStore.notifyError(translationStore.t("cart.min-qty", "Lisatav kogus peab olema vähemalt 1")); | ||
return false; | ||
} | ||
const stock = product.stock; | ||
if (stock && qty > stock) { | ||
notificationStore.notifyError(translationStore.t("product.out-of-stock", "Toodet {0} on saadaval ainult {1}", [product.name, stock.toString()])); | ||
return false; | ||
} | ||
return true; | ||
} | ||
} |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
219790
4885