mirror of
https://github.com/ae-utbm/sith.git
synced 2025-07-12 04:49:25 +00:00
Split counter-click-index.ts
This commit is contained in:
25
counter/static/bundled/counter/basket.ts
Normal file
25
counter/static/bundled/counter/basket.ts
Normal file
@ -0,0 +1,25 @@
|
||||
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;
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user