mirror of
https://github.com/ae-utbm/sith.git
synced 2025-05-05 09:04:03 +00:00
26 lines
581 B
TypeScript
26 lines
581 B
TypeScript
import type { Product } from "#counter:counter/types";
|
|
|
|
export class BasketItem {
|
|
quantity: number;
|
|
product: Product;
|
|
quantityForTrayPrice: number;
|
|
errors: string[];
|
|
|
|
constructor(product: Product, quantity: number) {
|
|
this.quantity = quantity;
|
|
this.product = product;
|
|
this.errors = [];
|
|
}
|
|
|
|
getBonusQuantity(): number {
|
|
if (!this.product.hasTrayPrice) {
|
|
return 0;
|
|
}
|
|
return Math.floor(this.quantity / this.product.quantityForTrayPrice);
|
|
}
|
|
|
|
sum(): number {
|
|
return (this.quantity - this.getBonusQuantity()) * this.product.price;
|
|
}
|
|
}
|