diff --git a/src/components/catalog/Cart.vue b/src/components/catalog/Cart.vue index f9d7276..c557e72 100644 --- a/src/components/catalog/Cart.vue +++ b/src/components/catalog/Cart.vue @@ -21,8 +21,26 @@ {{ item.name }} - - {{ item.quantity }} x {{ currency(item.price) }} + + + mdi-minus + + mdi-plus + + x {{ currency(item.price) }} @@ -71,6 +89,7 @@ export default { required: true } }, + emits: ['remove', 'checkout', 'update-quantity'], computed: { cartCount() { return this.cartItems.reduce((sum, item) => sum + item.quantity, 0); @@ -78,6 +97,45 @@ export default { cartTotal() { return this.cartItems.reduce((sum, item) => sum + (item.price * item.quantity), 0); } + }, + methods: { + updateQuantity(itemId, newQuantity) { + const qty = parseInt(newQuantity) || 1; + this.$emit('update-quantity', { itemId, quantity: qty }); + }, + increaseQuantity(itemId) { + const item = this.cartItems.find(i => i.id === itemId); + if (item) { + this.$emit('update-quantity', { itemId, quantity: item.quantity + 1 }); + } + }, + decreaseQuantity(itemId) { + const item = this.cartItems.find(i => i.id === itemId); + if (item && item.quantity > 1) { + this.$emit('update-quantity', { itemId, quantity: item.quantity - 1 }); + } else if (item) { + this.$emit('remove', itemId); + } + } } } + + diff --git a/src/pages/catalog.vue b/src/pages/catalog.vue index 3047d99..c2471ba 100644 --- a/src/pages/catalog.vue +++ b/src/pages/catalog.vue @@ -17,6 +17,7 @@ :currency="currency" @remove="removeFromCart" @checkout="goToCheckout" + @update-quantity="updateCartQuantity" /> @@ -98,6 +99,16 @@ export default { item.quantity = 0; } }, + updateCartQuantity({ itemId, quantity }) { + const cartItem = this.cartItems.find(i => i.id === itemId); + if (cartItem) { + cartItem.quantity = quantity; + } + const productItem = this.items.find(i => i.id === itemId); + if (productItem) { + productItem.quantity = quantity; + } + }, goToCheckout() { this.$router.push('/comprar'); },