Skip to content

Commit

Permalink
Fixed cart items issue
Browse files Browse the repository at this point in the history
  • Loading branch information
AdityaPatil22 committed Jul 2, 2024
1 parent 6623eb4 commit 61cb365
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 2 deletions.
1 change: 1 addition & 0 deletions src/components/redux_api/reducers/CartReducer.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ export const cartReducer = (state={cartItems:[]},action)=>{
const exist = state.cartItems.find(product=>product.id===item.id);

if(exist){
item.quantity += exist.quantity;
return {...state,cartItems:state.cartItems.map(data=>data.id===exist.id?item:data)};
}
else{
Expand Down
4 changes: 2 additions & 2 deletions src/pages/Cart/CartItem.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,15 @@ function CartItem({item}) {
const dispatch = useDispatch();

const addToItemCart =()=>{
dispatch(addToCart(item.id,item.quantity+1));
dispatch(addToCart(item.id,1));
}

const reduceFromItemCart =()=>{
if(item.quantity<=1){
dispatch(removeFromCart(item.id));
}
else{
dispatch(addToCart(item.id,item.quantity-1));
dispatch(addToCart(item.id,-1));
}
}

Expand Down

0 comments on commit 61cb365

Please sign in to comment.