Skip to content

Instantly share code, notes, and snippets.

@gearmobile
Last active June 22, 2017 18:28
Show Gist options
  • Save gearmobile/cebd3af63f66d0ed2b2b00d8f2e388c2 to your computer and use it in GitHub Desktop.
Save gearmobile/cebd3af63f66d0ed2b2b00d8f2e388c2 to your computer and use it in GitHub Desktop.
getters
getDiscountSum (state, getters) {
let total = getters.getResult // connect getters getResult
for (let i = 0; i < state.discount.length; i += 1) {
if (state.discount[i].name === state.discountStatus) {
const discount = total * state.discount[i].value / 100
return discount
}
}
},
getPromoSum (state, getters) {
let total = getters.getResult // connect getter getResult
if (state.promocode.status) {
const promo = total - total * state.promocode.percent / 100
return promo
}
},
getResult (state) {
let total = state.order.reduce((sum, c) => sum + c.quantity * c.price, 0)
return total
},
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment