shopping cart add and remove products quantity
This commit is contained in:
parent
a28cae039c
commit
83f25f7972
5 changed files with 45 additions and 9 deletions
|
|
@ -23,6 +23,8 @@
|
||||||
<shopping-cart
|
<shopping-cart
|
||||||
:cart="cart"
|
:cart="cart"
|
||||||
:cart-menu="cartMenu"
|
:cart-menu="cartMenu"
|
||||||
|
:products="stallproducts"
|
||||||
|
@add-to-cart="addToCart"
|
||||||
@remove-from-cart="removeFromCart"
|
@remove-from-cart="removeFromCart"
|
||||||
@reset-cart="resetCart"
|
@reset-cart="resetCart"
|
||||||
@open-checkout="openCheckout"
|
@open-checkout="openCheckout"
|
||||||
|
|
|
||||||
|
|
@ -10,6 +10,7 @@ async function customerStall(path) {
|
||||||
'login-dialog',
|
'login-dialog',
|
||||||
'stall',
|
'stall',
|
||||||
'products',
|
'products',
|
||||||
|
'stallproducts',
|
||||||
'product-detail',
|
'product-detail',
|
||||||
'change-page',
|
'change-page',
|
||||||
'relays',
|
'relays',
|
||||||
|
|
@ -124,7 +125,17 @@ async function customerStall(path) {
|
||||||
this.updateCart(+item.price)
|
this.updateCart(+item.price)
|
||||||
},
|
},
|
||||||
removeFromCart(item) {
|
removeFromCart(item) {
|
||||||
this.cart.products.delete(item.id)
|
let prod = this.cart.products
|
||||||
|
let qty = prod.get(item.id).quantity
|
||||||
|
if (qty == 1) {
|
||||||
|
prod.delete(item.id)
|
||||||
|
} else {
|
||||||
|
prod.set(item.id, {
|
||||||
|
...prod.get(item.id),
|
||||||
|
quantity: qty - 1
|
||||||
|
})
|
||||||
|
}
|
||||||
|
this.cart.products = prod
|
||||||
this.updateCart(+item.price, true)
|
this.updateCart(+item.price, true)
|
||||||
},
|
},
|
||||||
updateCart(price, del = false) {
|
updateCart(price, del = false) {
|
||||||
|
|
|
||||||
|
|
@ -4,17 +4,19 @@
|
||||||
</q-badge>
|
</q-badge>
|
||||||
<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 :key="p.id" v-for="p in cartMenu">
|
<q-item :id="p.id" :key="p.id" v-for="p in cartMenu">
|
||||||
<q-item-section side>
|
<q-btn color="red" size="xs" icon="remove" @click="remove(p.id)" />
|
||||||
<span>{{p.quantity}} x </span>
|
<q-item-section>
|
||||||
|
<span class="text-center q-ma-xs">{{p.quantity}} x </span>
|
||||||
</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 size="sm" :src="p.image" />
|
<img :src="p.image" />
|
||||||
</q-avatar>
|
</q-avatar>
|
||||||
</q-item-section>
|
</q-item-section>
|
||||||
|
|
||||||
<q-item-section>
|
<q-item-section top class="q-mx-sm">
|
||||||
<q-item-label>{{ p.name }}</q-item-label>
|
<q-item-label>{{ p.name }}</q-item-label>
|
||||||
</q-item-section>
|
</q-item-section>
|
||||||
|
|
||||||
|
|
@ -42,7 +44,7 @@
|
||||||
@click="$emit('open-checkout')"
|
@click="$emit('open-checkout')"
|
||||||
></q-btn>
|
></q-btn>
|
||||||
<q-btn
|
<q-btn
|
||||||
class="q-ml-lg"
|
class="q-ml-auto"
|
||||||
flat
|
flat
|
||||||
color="primary"
|
color="primary"
|
||||||
label="Reset"
|
label="Reset"
|
||||||
|
|
|
||||||
|
|
@ -5,12 +5,32 @@ async function shoppingCart(path) {
|
||||||
name: 'shopping-cart',
|
name: 'shopping-cart',
|
||||||
template,
|
template,
|
||||||
|
|
||||||
props: ['cart', 'cart-menu', 'remove-from-cart', 'reset-cart'],
|
props: [
|
||||||
|
'cart',
|
||||||
|
'cart-menu',
|
||||||
|
'add-to-cart',
|
||||||
|
'remove-from-cart',
|
||||||
|
'reset-cart',
|
||||||
|
'products'
|
||||||
|
],
|
||||||
data: function () {
|
data: function () {
|
||||||
return {}
|
return {}
|
||||||
},
|
},
|
||||||
computed: {},
|
computed: {},
|
||||||
methods: {},
|
methods: {
|
||||||
|
add(id) {
|
||||||
|
this.$emit(
|
||||||
|
'add-to-cart',
|
||||||
|
this.products.find(p => p.id == id)
|
||||||
|
)
|
||||||
|
},
|
||||||
|
remove(id) {
|
||||||
|
this.$emit(
|
||||||
|
'remove-from-cart',
|
||||||
|
this.products.find(p => p.id == id)
|
||||||
|
)
|
||||||
|
}
|
||||||
|
},
|
||||||
created() {}
|
created() {}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -186,6 +186,7 @@
|
||||||
v-if="!isLoading && activeStall"
|
v-if="!isLoading && activeStall"
|
||||||
:stall="stalls.find(stall => stall.id == activeStall)"
|
:stall="stalls.find(stall => stall.id == activeStall)"
|
||||||
:products="filterProducts"
|
:products="filterProducts"
|
||||||
|
:stallproducts="products.filter(p => p.stall_id == activeStall)"
|
||||||
:product-detail="activeProduct"
|
:product-detail="activeProduct"
|
||||||
:relays="relays"
|
:relays="relays"
|
||||||
:account="account"
|
:account="account"
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue