sdras / ecommerce-netlify

🛍 A JAMstack Ecommerce Site built with Nuxt and Netlify Functions

Home Page:https://ecommerce-netlify.netlify.app/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Cart count issue

Murodjon000 opened this issue · comments

Hi Sarah. While I was playing with your deployed site. I came across a little bug with the cart item count. If you add the item to your cart and if it is one try to decrease it then it disappears but when you add another item and in the cart page you will see the removed item which has a count of 0 but not disappearing. Here is the image screenshot https://res.cloudinary.com/dflkwvvnz/image/upload/v1626101578/scrnli_7_12_2021_7-52-44_PM_cikgtc.png
And I tried to fix it. Changing one line of code worked.

removeOneFromCart: (state, payload) => {
    const index = state.cart.findIndex((el) => el.id === payload.id)
    if (state.cart[index].count) {
      state.cart[index].count--
    }
    if (state.cart[index].count === 0) {
      state.cart.splice(index, 1)
    }
  },