maryluis 4 лет назад
Родитель
Сommit
bf70b32dc4
1 измененных файлов с 3 добавлено и 2 удалено
  1. 3 2
      shop/src/reducers/cartReducer.js

+ 3 - 2
shop/src/reducers/cartReducer.js

@@ -13,6 +13,7 @@ function cartReducer(state, { type, count, id, image,  name, description,  price
     }
     }
     if (type === "CART_ADD") {
+        //debugger
         state = {
             ...state,
             
@@ -22,7 +23,7 @@ function cartReducer(state, { type, count, id, image,  name, description,  price
                     description: description,
                     image: image,
                     name, name,
-                   count: (count + 1 )|| 0},
+                    count: ((state[id] ? state[id].count : 0) + 1  )},
         };
     }
 
@@ -39,7 +40,7 @@ function cartReducer(state, { type, count, id, image,  name, description,  price
 
 
 
-const actionCartAdd = (name, price, id, description, image, count = 1) => ({
+const actionCartAdd = (name, price, id, description, image, count = 0) => ({
     type: "CART_ADD",
     id,
     count,