cartReducer-1
cartReducer-1
jpg";
import "bootstrap/dist/css/bootstrap.css";
const initState = {
items: [
{id: 1,src: Phone,name: "ONEPLUS",price: 30000,color: "Nebula Blue", RAM:
"8GB",Storage: "128GB"},
{id: 2,src: Phone,name: "SAMSUNG",price: 23000,color: "Glacier Blue",RAM:
"8GB",Storage: "128GB"},
{id: 3,src: Phone,name: "MI A7",price: 19000,color: "Frosted Silver",RAM:
"6GB",Storage: "64GB"},
{id: 4,src: Phone,name: "REAL ME",price: 20000,color: "Nebula Blue",RAM:
"12GB",Storage: "32GB"},
{id: 5,src: Phone,name: "MOTO",price: 23000,color: "Glacier Blue",RAM:
"4GB",Storage: "32GB"},
{id: 6,src: Phone,name: "VIVO",price: 19000,color: "Frosted Silver",RAM:
"6GB",Storage: "64GB"},
{id: 7,src: Phone,name: "OPPO",price: 20000,color: "Glacier Blue",RAM:
"8GB",Storage: "128GB"},
{id: 8,src: Phone,name: "REDMI",price: 20000,color: "Nebula Blue",RAM:
"4GB",Storage: "64GB"}
],
addedItems: [],
total: 0,
shippingPrice: 0,
myOrder: [],
view: [],
Amount: [],
price: 0
};
const cartReducer = (state = initState, action) => {
if (action.type === "on_Add_To_Cart") {
let items=state.items;
for(let i=0;i<items.length;i++) {
let a= state.items[i]
let addedItem=state.addedItems;
let newTotal=state.total;
let newQuantity = state.newQuatity;
if(a.id==action.id)
{
addedItem.push(a);
newTotal = newTotal+a.price;
newQuantity = newQuantity+1;
}
return {...state,
addedItems:addedItem,
total:newTotal}
}//code here to add a product in cart
//state.addedItems.push(...action.items);
//state.total = action.total
//return action.id;
}
if (action.type === "on_Delete") {
//code here to delete a product in cart
}
if (action.type === "on_Inc") {
//code goes here for increasing the quantity
}
if (action.type === "on_Decr") {
//code goes here for decreasing the quantity
}
if (action.type === "on_Op1") {
//code goes here on choosing first option(shipping within 7 days(+50))
console.log(state.shippingPrice)
state.shippingPrice=50
}