-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
54 additions
and
50 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
export interface InitialFormData { | ||
/* Used to refill the form when the backend raises an error */ | ||
id?: keyof Record<string, Product>; | ||
quantity?: number; | ||
errors?: string[]; | ||
} | ||
|
||
export interface CounterConfig { | ||
customerBalance: number; | ||
customerId: number; | ||
products: Record<string, Product>; | ||
formInitial: InitialFormData[]; | ||
cancelUrl: string; | ||
} | ||
|
||
export interface Product { | ||
id: string; | ||
code: string; | ||
name: string; | ||
price: number; | ||
hasTrayPrice: boolean; | ||
quantityForTrayPrice: number; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters