summaryrefslogtreecommitdiff
path: root/iridescence/src/store/index.js
diff options
context:
space:
mode:
authorAdam T. Carpenter <atc@53hor.net>2020-12-03 19:25:12 -0500
committerAdam T. Carpenter <atc@53hor.net>2020-12-03 19:25:12 -0500
commitd8d44376d193d925582a0a12373e1403df49cf63 (patch)
tree3c7d2422ad000efb606d7a0995c089f4db56b237 /iridescence/src/store/index.js
parent8280cf98c9a33613c7440442b73636e39dd297bc (diff)
downloadtheglassyladies-d8d44376d193d925582a0a12373e1403df49cf63.tar.xz
theglassyladies-d8d44376d193d925582a0a12373e1403df49cf63.zip
basic cart subtotaling, sidebar with total and checkout controls, better
navbar cart buttons
Diffstat (limited to 'iridescence/src/store/index.js')
-rw-r--r--iridescence/src/store/index.js49
1 files changed, 36 insertions, 13 deletions
diff --git a/iridescence/src/store/index.js b/iridescence/src/store/index.js
index 48cae11..e2d970d 100644
--- a/iridescence/src/store/index.js
+++ b/iridescence/src/store/index.js
@@ -24,6 +24,13 @@ export default new Vuex.Store({
.includes(state.searchTerm.toLowerCase());
})
.sort(state.compare);
+ },
+ cartTotal(state) {
+ let cents = state.products
+ .filter(p => state.cart[p.id])
+ .map(p => p.cents * state.cart[p.id])
+ .reduce((acc, cur) => acc + cur, 0);
+ return "$ " + (cents / 100).toFixed(2);
}
},
mutations: {
@@ -34,22 +41,38 @@ export default new Vuex.Store({
state.productDetailId = id;
},
cartItem(state, { id, by }) {
+ let newCount = 1;
if (state.cart[id]) {
- let newCount = (state.cart[id] += by);
- if (newCount <= 0) {
- // remove from cart entirely
- delete state.cart[id];
- return;
- }
- state.cart = {
- ...state.cart,
- [id]: newCount
- };
+ newCount = state.cart[id] += by;
+ //if (newCount <= 0) {
+ // // remove from cart entirely
+ // delete state.cart[id];
+ // return;
+ //}
+ //state.cart = {
+ // ...state.cart,
+ // [id]: newCount
+ }
+
+ let cart = {
+ ...state.cart
+ };
+
+ if (newCount) {
+ cart[id] = newCount;
} else {
- state.cart = {
- ...state.cart,
- [id]: 1
+ // remove entirely
+ delete cart[id];
+ }
+ state.cart = cart;
+ },
+ removeItemFromCart(state, id) {
+ if (state.cart[id]) {
+ let cart = {
+ ...state.cart
};
+ delete cart[id];
+ state.cart = cart;
}
},
compare(state, compare) {