fix: limit order quantity to in-stock

This commit is contained in:
Vlad Stan 2023-07-07 10:26:17 +03:00
parent 6c4ea7ac7d
commit 602d6858cd

View file

@ -581,12 +581,13 @@ const market = async () => {
} }
stallCart.merchant = this.merchants.find(m => m.publicKey === item.pubkey) stallCart.merchant = this.merchants.find(m => m.publicKey === item.pubkey)
const product = stallCart.products.find(p => p.id === item.id) let product = stallCart.products.find(p => p.id === item.id)
if (product) { if (!product) {
product.orderedQuantity = item.orderedQuantity || (product.orderedQuantity + 1) product = { ...item, orderedQuantity: 1 }
} else { stallCart.products.push(product)
stallCart.products.push({ ...item, orderedQuantity: 1 })
} }
product.orderedQuantity = Math.min(product.quantity, item.orderedQuantity || (product.orderedQuantity + 1))
this.$q.localStorage.set('nostrmarket.shoppingCarts', this.shoppingCarts) this.$q.localStorage.set('nostrmarket.shoppingCarts', this.shoppingCarts)
console.log('### this.shoppingCarts', this.shoppingCarts) console.log('### this.shoppingCarts', this.shoppingCarts)
@ -596,6 +597,9 @@ const market = async () => {
const stallCart = this.shoppingCarts.find(c => c.id === item.stallId) const stallCart = this.shoppingCarts.find(c => c.id === item.stallId)
if (stallCart) { if (stallCart) {
stallCart.products = stallCart.products.filter(p => p.id !== item.productId) stallCart.products = stallCart.products.filter(p => p.id !== item.productId)
if (!stallCart.products.length){
this.shoppingCarts = this.shoppingCarts.filter(s => s.id !== item.stallId)
}
this.$q.localStorage.set('nostrmarket.shoppingCarts', this.shoppingCarts) this.$q.localStorage.set('nostrmarket.shoppingCarts', this.shoppingCarts)
} }
} }