summaryrefslogtreecommitdiff
path: root/services/Order.js
diff options
context:
space:
mode:
authorLeo Goetz <dev@leogtz.de>2026-02-02 11:47:42 +0100
committerLeo Goetz <dev@leogtz.de>2026-02-02 11:47:42 +0100
commitbc09ac8989d5d7cc5e89bca7036b6010815dbee9 (patch)
treed5cc8a1f4e99910870589539e5fe86809795e314 /services/Order.js
parentd5a420a8135537c9fc36f9dd81ec7c9fc0500e66 (diff)
feat: added components, proxy and finished project/courseHEADmaster
Diffstat (limited to 'services/Order.js')
-rw-r--r--services/Order.js20
1 files changed, 20 insertions, 0 deletions
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);
+}