From bc09ac8989d5d7cc5e89bca7036b6010815dbee9 Mon Sep 17 00:00:00 2001 From: Leo Goetz Date: Mon, 2 Feb 2026 11:47:42 +0100 Subject: feat: added components, proxy and finished project/course --- services/Order.js | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 services/Order.js (limited to 'services/Order.js') diff --git a/services/Order.js b/services/Order.js new file mode 100644 index 0000000..1c6e131 --- /dev/null +++ b/services/Order.js @@ -0,0 +1,20 @@ +import { getProductById } from "./Menu.js"; + +export async function addToCart(id) { + const product = await getProductById(id); + const results = app.store.cart.filter( + (prodInCart) => prodInCart.product.id == id, + ); + + if (results.length == 1) { + app.store.cart = app.store.cart.map((p) => + p.product.id == id ? { ...p, quantity: p.quantity + 1 } : p, + ); + } else { + app.store.cart = [...app.store.cart, { product, quantity: 1 }]; + } +} + +export function removeFromCart(id) { + app.store.cart = app.store.cart.filter((p) => p.product.id != id); +} -- cgit v1.3