Implement ordering process

This commit is contained in:
2024-09-24 15:40:16 +02:00
parent 22d3e8d177
commit 03ff8b402f
19 changed files with 274 additions and 160 deletions

View File

@@ -1,11 +1,3 @@
import { BasketItemModel } from "@/data/models/basketItemModel";
import { CategoryModel } from "@/data/models/categoryModel";
import { ProductModel } from "@/data/models/productModel";
export function calcProductPrice(product: ProductModel, quantity: number = 1): number {
return calcPrice(product.price, product.discount, quantity)
}
/**
* Calculate a price based on parameters
*
@@ -17,28 +9,4 @@ export function calcProductPrice(product: ProductModel, quantity: number = 1): n
*/
export function calcPrice(price: number, discount: number = 0, quantity: number = 1): number {
return Math.round(quantity * price * ((100 - discount) / 100) * 100) / 100
}
/**
* Convert a ProductModel to a BasketModel
*
* @param product ProductModel to convert
* @param productCategory Category of the product
* @param quantity Number of units
*
* @returns BasketItemModel
*/
export function productToBasketItem(product: ProductModel, quantity: number): BasketItemModel {
let result = new BasketItemModel()
result.productId = product.id
result.quantity = quantity
result.price = product.price
result.brand = product.brand
result.discount = product.discount
result.name = product.name
result.categoryName = product.category.name
result.categoryIcon = product.category.icon
return result
}