blob: 1c6e13168cf1f35f7da74510ce43701ec29a47f9 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
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);
}
|