|
@@ -1,6 +1,7 @@
|
|
const state = {
|
|
const state = {
|
|
cart: [],
|
|
cart: [],
|
|
- total: 0
|
|
|
|
|
|
+ total: 0,
|
|
|
|
+ productToDiscount: null
|
|
}
|
|
}
|
|
|
|
|
|
const getters = {
|
|
const getters = {
|
|
@@ -12,6 +13,9 @@ const getters = {
|
|
},
|
|
},
|
|
cartIsEmpty(state) {
|
|
cartIsEmpty(state) {
|
|
return state.cart.length !== 0
|
|
return state.cart.length !== 0
|
|
|
|
+ },
|
|
|
|
+ productToDiscount(state) {
|
|
|
|
+ return state.productToDiscount
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
@@ -29,6 +33,9 @@ const mutations = {
|
|
let finded = state.cart.find(item => item.id == payload.product.id)
|
|
let finded = state.cart.find(item => item.id == payload.product.id)
|
|
finded.qty = finded.qty - 1
|
|
finded.qty = finded.qty - 1
|
|
},
|
|
},
|
|
|
|
+ discountFromCart(state, payload) {
|
|
|
|
+ state.productToDiscount = payload
|
|
|
|
+ },
|
|
removeFromCart(state, payload) {
|
|
removeFromCart(state, payload) {
|
|
let findedIndex = state.cart.findIndex(item => item.id == payload.product.id)
|
|
let findedIndex = state.cart.findIndex(item => item.id == payload.product.id)
|
|
state.cart.splice(findedIndex, 1)
|
|
state.cart.splice(findedIndex, 1)
|
|
@@ -69,6 +76,9 @@ const actions = {
|
|
|
|
|
|
commit('calculateTotal')
|
|
commit('calculateTotal')
|
|
},
|
|
},
|
|
|
|
+ discountFromCart({ commit }, payload) {
|
|
|
|
+ commit('discountFromCart', payload)
|
|
|
|
+ },
|
|
removeFromCart({ commit, dispatch }, payload) {
|
|
removeFromCart({ commit, dispatch }, payload) {
|
|
commit('removeFromCart', {
|
|
commit('removeFromCart', {
|
|
product: payload
|
|
product: payload
|