vanilli-shop-client
Advanced tools
Comparing version 1.3.2 to 1.3.3
import { IBaseDto, IPropertyDto } from "./base"; | ||
import { IParameter } from "./parameter"; | ||
export interface IProductBaseDto extends IBaseDto { | ||
@@ -31,4 +30,2 @@ ref: string; | ||
export declare class ProductDetails { | ||
static getCurrentPrice(product: IProductBaseDto, parameters?: IParameter[]): number; | ||
static getPrice(defaultPrice: number, parameters?: IParameter[]): number; | ||
static getProperty(properties: IPropertyDto[] | undefined, key: string): string | undefined; | ||
@@ -35,0 +32,0 @@ } |
@@ -33,23 +33,2 @@ "use strict"; | ||
} | ||
ProductDetails.getCurrentPrice = function (product, parameters) { | ||
var discountPrice = product.discountPrice; | ||
if (discountPrice) { | ||
return discountPrice; | ||
} | ||
return this.getPrice(product.currentPrice, parameters); | ||
}; | ||
ProductDetails.getPrice = function (defaultPrice, parameters) { | ||
if (!parameters) { | ||
return defaultPrice; | ||
} | ||
var maxPrice = 0; | ||
for (var _i = 0, parameters_1 = parameters; _i < parameters_1.length; _i++) { | ||
var parameter = parameters_1[_i]; | ||
var price = parameter.price; | ||
if (price && price > maxPrice) { | ||
maxPrice = price; | ||
} | ||
} | ||
return maxPrice > 0 ? maxPrice : defaultPrice; | ||
}; | ||
ProductDetails.getProperty = function (properties, key) { | ||
@@ -56,0 +35,0 @@ var property = properties === null || properties === void 0 ? void 0 : properties.find(function (x) { return x.key === key; }); |
@@ -11,2 +11,3 @@ import BaseStore from "./base-store"; | ||
private setParameterValue; | ||
private calculateProductPrice; | ||
} |
@@ -135,3 +135,17 @@ "use strict"; | ||
} | ||
this.calculateProductPrice(); | ||
}; | ||
ParameterStore.prototype.calculateProductPrice = function () { | ||
var maxPrice = 0; | ||
for (var _i = 0, _a = this.selectedParameters; _i < _a.length; _i++) { | ||
var parameter = _a[_i]; | ||
var price = parameter.price; | ||
if (price && price > maxPrice) { | ||
maxPrice = price; | ||
} | ||
} | ||
if (maxPrice > 0) { | ||
this.rootStore.productStore.setProductPrice(maxPrice); | ||
} | ||
}; | ||
__decorate([ | ||
@@ -138,0 +152,0 @@ mobx_1.observable |
@@ -16,2 +16,3 @@ import BaseStore from "./base-store"; | ||
resetSearch(): void; | ||
setProductPrice(price: number): void; | ||
private setProducts; | ||
@@ -18,0 +19,0 @@ private toggleProductList; |
@@ -206,2 +206,10 @@ "use strict"; | ||
}; | ||
ProductStore.prototype.setProductPrice = function (price) { | ||
if (this.product) { | ||
this.product.price = price; | ||
if (!this.product.discountPrice) { | ||
this.product.currentPrice = price; | ||
} | ||
} | ||
}; | ||
ProductStore.prototype.setProducts = function (productList) { | ||
@@ -256,2 +264,5 @@ this.productList = productList; | ||
mobx_1.action | ||
], ProductStore.prototype, "setProductPrice", null); | ||
__decorate([ | ||
mobx_1.action | ||
], ProductStore.prototype, "setProducts", null); | ||
@@ -258,0 +269,0 @@ __decorate([ |
{ | ||
"name": "vanilli-shop-client", | ||
"version": "1.3.2", | ||
"version": "1.3.3", | ||
"description": "Client for Vanilli Shop API", | ||
@@ -5,0 +5,0 @@ "main": "dist/index.js", |
import {IBaseDto, IPropertyDto} from "./base"; | ||
import {IParameter} from "./parameter"; | ||
@@ -55,30 +54,2 @@ export interface IProductBaseDto extends IBaseDto { | ||
export class ProductDetails { | ||
static getCurrentPrice(product: IProductBaseDto, parameters?: IParameter[]): number { | ||
const discountPrice = product.discountPrice; | ||
if (discountPrice) { | ||
return discountPrice; | ||
} | ||
return this.getPrice(product.currentPrice, parameters); | ||
} | ||
static getPrice(defaultPrice: number, parameters?: IParameter[]): number { | ||
if (!parameters) { | ||
return defaultPrice; | ||
} | ||
let maxPrice = 0; | ||
for (const parameter of parameters) { | ||
const price = parameter.price; | ||
if (price && price > maxPrice) { | ||
maxPrice = price; | ||
} | ||
} | ||
return maxPrice > 0 ? maxPrice : defaultPrice; | ||
} | ||
static getProperty(properties: IPropertyDto[] | undefined, key: string): string | undefined { | ||
@@ -85,0 +56,0 @@ const property = properties?.find(x => x.key === key); |
@@ -68,3 +68,21 @@ import BaseStore from "./base-store"; | ||
} | ||
this.calculateProductPrice(); | ||
} | ||
private calculateProductPrice() { | ||
let maxPrice = 0 | ||
for (const parameter of this.selectedParameters) { | ||
const price = parameter.price; | ||
if (price && price > maxPrice) { | ||
maxPrice = price; | ||
} | ||
} | ||
if (maxPrice > 0) { | ||
this.rootStore.productStore.setProductPrice(maxPrice); | ||
} | ||
} | ||
} |
@@ -120,2 +120,13 @@ import BaseStore from "./base-store"; | ||
@action | ||
setProductPrice(price: number) { | ||
if (this.product) { | ||
this.product.price = price; | ||
if (!this.product.discountPrice) { | ||
this.product.currentPrice = price; | ||
} | ||
} | ||
} | ||
@action | ||
private setProducts(productList: IListDto<IProductDto>) { | ||
@@ -122,0 +133,0 @@ this.productList = productList; |
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
4954
222621