sample-vue-shop icon indicating copy to clipboard operation
sample-vue-shop copied to clipboard

shop cart error

Open sleemy1997 opened this issue 5 years ago • 1 comments

first of all nice work. after successful payment cart is cleared up but if you add new item than last bought item is in cart as well, every time you add new item in cart all last bought items stay there

sleemy1997 avatar Jul 30 '18 10:07 sleemy1997

@sleemy1997 you can fix it by reworking the store a bit to use an array for the cart data structure vs an object.

Not sure where all she is referencing an object that will need to be replaced. But I have something like this in my store and it's working good. This has been a great resource, I'd be happy to rework the data structure and the components if @sdras would like.

    addItem(state, payload) {
      state.cartTotal+= payload.qty
      state.cart.push(payload)
    },

    removeCartItem(state, payload) {
      state.cartTotal-= payload.qty
      const cartItemPostion = state.cart.indexOf(payload)
      state.cart.splice(cartItemPostion, 1)
    },

    clearCartCount(state) {
      state.cartTotal = 0
    },

    clearCartContents(state) {
      state.cart = []
    }

pburdette avatar Aug 03 '18 15:08 pburdette