fix: limit order quantity to in-stock
This commit is contained in:
parent
6c4ea7ac7d
commit
602d6858cd
1 changed files with 9 additions and 5 deletions
|
|
@ -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)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue