0% found this document useful (0 votes)
6 views2 pages

cartReducer-1

Description DescriptionDescriptionDescriptionDescriptionDescriptionDescription
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views2 pages

cartReducer-1

Description DescriptionDescriptionDescriptionDescriptionDescriptionDescription
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 2

import Phone from "../../images/smartphone.

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
}

if (action.type === "on_Op2") {


//code goes here on choosing second option(shipping within 2 days(+100))
state.shippingPrice=100
}
if (action.type === "Place_Order") {
//code goes here for place order
}
if (action.type === "Cancel_Order") {
//code goes here for cancel order
}
if (action.type === "View") {
//code goes here for Viewing the product
} else {
return state;
}
};
export default cartReducer;
x

You might also like