sdras / sample-vue-shop

See readme for newer repo details! A sample shop that shows how to manage payments with Vue, Stripe, and Serverless Functions

Home Page:https://shoppity.azurewebsites.net/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

shop cart error

sleemy1997 opened this issue · 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 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 = []
    }