feat: allow for manual quantity input
This commit is contained in:
parent
415ca6da74
commit
d4efa84d2e
4 changed files with 52 additions and 18 deletions
|
|
@ -26,6 +26,7 @@
|
||||||
:products="stallproducts"
|
:products="stallproducts"
|
||||||
@add-to-cart="addToCart"
|
@add-to-cart="addToCart"
|
||||||
@remove-from-cart="removeFromCart"
|
@remove-from-cart="removeFromCart"
|
||||||
|
@update-qty="updateQty"
|
||||||
@reset-cart="resetCart"
|
@reset-cart="resetCart"
|
||||||
@open-checkout="openCheckout"
|
@open-checkout="openCheckout"
|
||||||
></shopping-cart>
|
></shopping-cart>
|
||||||
|
|
|
||||||
|
|
@ -92,6 +92,15 @@ async function customerStall(path) {
|
||||||
getAmountFormated(amount, unit = 'USD') {
|
getAmountFormated(amount, unit = 'USD') {
|
||||||
return LNbits.utils.formatCurrency(amount, unit)
|
return LNbits.utils.formatCurrency(amount, unit)
|
||||||
},
|
},
|
||||||
|
updateQty(id, qty) {
|
||||||
|
let prod = this.cart.products
|
||||||
|
let product = prod.get(id)
|
||||||
|
prod.set(id, {
|
||||||
|
...product,
|
||||||
|
quantity: qty
|
||||||
|
})
|
||||||
|
this.updateCart()
|
||||||
|
},
|
||||||
addToCart(item) {
|
addToCart(item) {
|
||||||
let prod = this.cart.products
|
let prod = this.cart.products
|
||||||
if (prod.has(item.id)) {
|
if (prod.has(item.id)) {
|
||||||
|
|
@ -122,7 +131,7 @@ async function customerStall(path) {
|
||||||
icon: 'thumb_up'
|
icon: 'thumb_up'
|
||||||
})
|
})
|
||||||
this.cart.products = prod
|
this.cart.products = prod
|
||||||
this.updateCart(+item.price)
|
this.updateCart()
|
||||||
},
|
},
|
||||||
removeFromCart(item, del = false) {
|
removeFromCart(item, del = false) {
|
||||||
let prod = this.cart.products
|
let prod = this.cart.products
|
||||||
|
|
@ -136,16 +145,15 @@ async function customerStall(path) {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
this.cart.products = prod
|
this.cart.products = prod
|
||||||
this.updateCart(+item.price, true)
|
this.updateCart()
|
||||||
},
|
},
|
||||||
updateCart(price, del = false) {
|
updateCart() {
|
||||||
if (del) {
|
this.cart.total = 0
|
||||||
this.cart.total -= price
|
this.cart.products.forEach(p => {
|
||||||
this.cart.size--
|
this.cart.total += p.quantity * p.price
|
||||||
} else {
|
})
|
||||||
this.cart.total += price
|
|
||||||
this.cart.size++
|
this.cart.size = this.cart.products.size
|
||||||
}
|
|
||||||
this.cartMenu = Array.from(this.cart.products, item => {
|
this.cartMenu = Array.from(this.cart.products, item => {
|
||||||
return {id: item[0], ...item[1]}
|
return {id: item[0], ...item[1]}
|
||||||
})
|
})
|
||||||
|
|
@ -365,9 +373,8 @@ async function customerStall(path) {
|
||||||
this.qrCodeDialog.data.message = json.message
|
this.qrCodeDialog.data.message = json.message
|
||||||
return cb()
|
return cb()
|
||||||
}
|
}
|
||||||
let payment_request = json.payment_options.find(
|
let payment_request = json.payment_options.find(o => o.type == 'ln')
|
||||||
o => o.type == 'ln'
|
.link
|
||||||
).link
|
|
||||||
if (!payment_request) return
|
if (!payment_request) return
|
||||||
this.loading = false
|
this.loading = false
|
||||||
this.qrCodeDialog.data.payment_request = payment_request
|
this.qrCodeDialog.data.payment_request = payment_request
|
||||||
|
|
|
||||||
|
|
@ -5,11 +5,19 @@
|
||||||
<q-menu v-if="cart.size">
|
<q-menu v-if="cart.size">
|
||||||
<q-list style="min-width: 100px">
|
<q-list style="min-width: 100px">
|
||||||
<q-item :id="p.id" :key="p.id" v-for="p in cartMenu">
|
<q-item :id="p.id" :key="p.id" v-for="p in cartMenu">
|
||||||
<q-btn color="red" size="xs" icon="remove" @click="remove(p.id)" />
|
<q-item-section style="flex-flow: row">
|
||||||
<q-item-section>
|
<q-btn color="red" size="xs" icon="remove" @click="remove(p.id)" />
|
||||||
<span class="text-center q-ma-xs">{{p.quantity}} x </span>
|
<q-input
|
||||||
|
v-model.number="p.quantity"
|
||||||
|
@change="addQty(p.id, p.quantity)"
|
||||||
|
type="number"
|
||||||
|
dense
|
||||||
|
standout
|
||||||
|
:max="products.find(pr => pr.id == p.id).quantity"
|
||||||
|
></q-input>
|
||||||
|
<!-- <span class="text-center q-ma-xs">{{p.quantity}} x </span> -->
|
||||||
|
<q-btn color="green" size="xs" icon="add" @click="add(p.id)" />
|
||||||
</q-item-section>
|
</q-item-section>
|
||||||
<q-btn color="green" size="xs" icon="add" @click="add(p.id)" />
|
|
||||||
<q-item-section avatar v-if="p.image">
|
<q-item-section avatar v-if="p.image">
|
||||||
<q-avatar color="primary">
|
<q-avatar color="primary">
|
||||||
<img :src="p.image" />
|
<img :src="p.image" />
|
||||||
|
|
@ -29,7 +37,7 @@
|
||||||
color="red"
|
color="red"
|
||||||
size="xs"
|
size="xs"
|
||||||
icon="close"
|
icon="close"
|
||||||
@click="$emit('remove-from-cart', p)"
|
@click="removeProduct(p.id)"
|
||||||
/>
|
/>
|
||||||
</span>
|
</span>
|
||||||
</q-item-section>
|
</q-item-section>
|
||||||
|
|
|
||||||
|
|
@ -10,6 +10,7 @@ async function shoppingCart(path) {
|
||||||
'cart-menu',
|
'cart-menu',
|
||||||
'add-to-cart',
|
'add-to-cart',
|
||||||
'remove-from-cart',
|
'remove-from-cart',
|
||||||
|
'update-qty',
|
||||||
'reset-cart',
|
'reset-cart',
|
||||||
'products'
|
'products'
|
||||||
],
|
],
|
||||||
|
|
@ -36,6 +37,23 @@ async function shoppingCart(path) {
|
||||||
this.products.find(p => p.id == id),
|
this.products.find(p => p.id == id),
|
||||||
true
|
true
|
||||||
)
|
)
|
||||||
|
},
|
||||||
|
addQty(id, qty) {
|
||||||
|
if (qty == 0) {
|
||||||
|
return this.removeProduct(id)
|
||||||
|
}
|
||||||
|
let product = this.products.find(p => p.id == id)
|
||||||
|
if (product.quantity < qty) {
|
||||||
|
this.$q.notify({
|
||||||
|
type: 'warning',
|
||||||
|
message: `${product.name} only has ${product.quantity} units!`,
|
||||||
|
icon: 'production_quantity_limits'
|
||||||
|
})
|
||||||
|
let objIdx = this.cartMenu.findIndex(pr => pr.id == id)
|
||||||
|
this.cartMenu[objIdx].quantity = this.cart.products.get(id).quantity
|
||||||
|
return
|
||||||
|
}
|
||||||
|
this.$emit('update-qty', id, qty)
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
created() {}
|
created() {}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue