Fix some errors after cart refactor

This commit is contained in:
Michał Gdula 2024-05-03 19:21:28 +01:00
parent 7066cc492b
commit 7f7fa3b3ab
2 changed files with 10 additions and 1 deletions

View file

@ -42,6 +42,13 @@ function createCartStore() {
) )
}); });
} }
cart.update((cart: Record<string, CartItem>) => {
if (cart[uuid].amount <= 0) {
delete cart[uuid];
}
return cart;
})
} }
function getEntries(): [string, CartItem][] { function getEntries(): [string, CartItem][] {

View file

@ -12,15 +12,17 @@
let items: [string, CartItem][]; let items: [string, CartItem][];
let totalPrice: number; let totalPrice: number;
let totalItems: number;
Cart.subscribe(() => { Cart.subscribe(() => {
items = Cart.getEntries(); items = Cart.getEntries();
totalPrice = Cart.getTotalPrice(); totalPrice = Cart.getTotalPrice();
totalItems = Cart.getUniqueLength();
}); });
</script> </script>
{#if items.entries} {#if totalItems}
<h1>Cart</h1> <h1>Cart</h1>
<button id="checkout-button">Checkout</button> <button id="checkout-button">Checkout</button>