react-shopping-cart
eCommerce
JavaScript
Build ECommerce Shopping Cart by React & Redux 2020 Edition
Demo:
https://reactredux-shoppingcart.herokuapp.com/
Get 90% Discount On This Course At Udemy
What you’ll learn
- Design Shopping Cart Using HTML and CSS
- Implement React Components For Product List, Filter, Cart
- Managing Component State using Redux, React-Redux and – Redux-Thunk
- Creating Animations Using React-Reveal and Add Routes using React-Routers
- Build Backend using Node, Express, MongoDB and Mongoose
- Publish Project on the Heroku and MongoDB Atlas
Are there any course requirements or prerequisites?
- Basic HTML and CSS
- Basic JavaScript
Who this course is for:
- Javascript developers
- Web Developers
- Freelancers
- Programming Students
Table Of Content
-
Introduction
-
Introduction
- Fully-Functional Shopping Cart
- Instant Feedback
- Animated and Intuitive Design
- List Products
- Sort Products By Price High or Low
- Filter Products by Size
- Open Modal By Click on Product
- Add Product To Cart using Animation
- Handle Multiple Click By Adding More Items
- Remove Product
- Show Checkout Form
- Create Order with user friendly id
- Admin Section to see list of products
- Using postman to add or remove products and orders
<li> Tools and Technologies <ol dir="auto"> <li> JavaScript (arrow functions, array functions, spread Operators, …) </li> <li> React (react-touter-dom, react-reveal, react-modal) </li> <li> Redux (react-redux, redux-thunk) </li> <li> Node (express, body-parser, Environment Variables, nodemon) </li> <li> MongoDB ( mongoose, shortid) </li> <li> VS Code (ES6 Snippets, ES7 React Extension, ESLint Extension,CSS Peek) </li> <li> Chrome ( React Developer Tools, Redux Developer Tools) </li> <li> Git (create repo, commit, remote, create and push branch) </li> <li> Github (create repo, connect to local repo, pull request and merge) </li> <li> Postman ( send get, post, put and delete requests to apis) </li> <li> Deployment ( Heroku, MongoDB Atlas Cloud) </li> </ol> </li> <li> Create React App <ol dir="auto"> <li> Open VS Code and open terminal </li> <li> cd Desktop </li> <li> npx create-react-app react-shopping-cart </li> <li> Remove unused files </li> <li> Convert App.js Class Component </li> <li> Add header, main and footer </li> <li> Update index.css to add grid </li> </ol> </li> <li> Project Development Workflow <ol dir="auto"> <li> Create Google Spreadsheet </li> <li> Add columns Feature, Description, State, and Duration </li> <li> Enter Products Component, Show list of products, Open, 2 </li> <li> Add Time ? Hours, Rate 30 USD/Hours, Cost ? USD </li> <li> Add All Features </li> <li> Create Github account </li> <li> Create new repository </li> <li> Add it as remote repository in VS Code </li> <li> Commit changes </li> <li> Push changes on github </li> <li> Start => create new feature Feature 1 in google spreadsheet </li> <li> Create a new branch feature-1 for test the workflow </li> <li> Add “// branch feature 1” in App.js Line 1 </li> <li> Commit with message “feature 1” </li> <li> Click publish changes </li> <li> Open repository page on github </li> <li> Create pull request </li> <li> Merge pull request </li> <li> In VS Code switch to master and Sync changes </li> <li> End => Loop from step 11 for next feature </li> </ol> </li> </ol>
-
Introduction
-
React
-
Products Component
- Create data.json {products:[{_id, title, …}]
- Update App.js to import data.json
- div.content {flex, wrap}
- div.main {flex: 3 60rem}
- div.sidebar {flex: 1 20rem;}
- Create components/Products.js component
- Add it to div.main in App.js and set products props
- ul.products {flex,center, center,warp, p:0,m:0, style:none}
- this.props.products.map(p => li.key={p._id} {flex, p:1, m:1, none,h:47}
- div.product { flex, column, space-between, h:100%}
- a href=”#” > img {max-width, max-height:37} + p {p.title}
- div.product-price > div.product.price + button.button.primary Add to cart
- product-price {flex, space-between, center}
- div {p.price} flex: 1; align: center; size: 2rem
- button.button.primary Add To Cart
<li> Filter Component <ol dir="auto"> <li> Create components/Filter.js </li> <li> Add it above Products component in App.js </li> <li> Update Filter.js render </li> <li> div.filter {flex, wrap, p,m:1rem, border-bottom: .1rem} </li> <li> filter-result {this.props.filteredProducts.length} </li> <li> filter-sort {flex:1} </li> <li> label Order select value=this.props.sort </li> <li> onChange= this.props.sortProducts(e.t.value) </li> <li> option lowestprice Lowest, … </li> <li> filter-size {flex:1} </li> <li> label Filter select value=this.props.size </li> <li> onChange= this.props.filterProducts(e.t.value) </li> <li> option “” ALL, XS, S, M, L, XL, XXL </li> <li> App.js </li> <li> Add Filter Component </li> </ol> </li> <li> Cart Component <ol dir="auto"> <li> Set Active Task Management Spreadsheet </li> <li> Create branch cart-component </li> <li> Product.js </li> <li> Handle “Add To Cart” to this.props.addToCart(product) </li> <li> App.js </li> <li> Add cartItems to state as [] </li> <li> Create addToCart(product) </li> <li> Slice, Check product existance, add to cartitems </li> <li> Cart.js </li> <li> Define cartItems from this.props </li> <li> Check cartItems.length and show message </li> <li> List cartItems {cartItems.length > 0 && (} </li> <li> index.css </li> <li> Style cart, cart-header, cart-items (img, li), </li> <li> Publish changes </li> <li> Pull request, merge, change to master </li> <li> Task Management Spreadsheet set it done </li> </ol> </li> <li> Checkout Form <ol dir="auto"> <li> Set Active Task Management Spreadsheet </li> <li> Create branch checkout-form </li> <li> Cart.js </li> <li> Make cart items persistent </li> <li> Use LocalStorage on App constructor to load cart items (JSON.parse) </li> <li> Use LocalStorage on addToCart to save cart items (JSON.stringify) </li> <li> Handle Click on Proceed </li> <li> Update showCheckout state to true on click </li> <li> Conditional rendering Checkout Form </li> <li> Get Email, Name and Address required input </li> <li> Define handleInput function </li> <li> Add Checkout Button </li> <li> Handle onSubmit Form Event by this.createOrder </li> <li> Create order object and pass to parent to handle it </li> <li> Commit and Publish changes </li> <li> Pull request, merge, change to master </li> <li> Task Management Spreadsheet set it done </li> </ol> </li> <li> Add Modal and Animation <ol dir="auto"> <li> Set Active Task Management Spreadsheet </li> <li> Create branch animation-modal </li> <li> Show Animation </li> <li> Install react-reveal </li> <li> Create fade effect from bottom for products </li> <li> Create fade left for add to cart </li> <li> Create fade right for show checkout form </li> <li> Open Modal by click on product image </li> <li> Install react-modal </li> <li> Products.js </li> <li> Import Modal </li> <li> Set state for product to null </li> <li> Define openModal and closeModal </li> <li> Show Modal if product exist </li> <li> Create Modal </li> <li> Create zoom effect for modal </li> <li> index.css </li> <li> Style Product Details </li> <li> Commit and Publish changes </li> <li> Pull request, merge, change to master </li> <li> Task Management Spreadsheet set it done </li> </ol> </li> </ol>
-
Products Component
-
Node.JS
-
Create Products Backend
- Install nodemon globally
- Add server.js
- Install express body-parser mongoose shortid
- Install MongoDB
- app = express()
- app.use(bodyParser.json())
- mongoose.connect()
- create Product model
- app.post(“/api.products”)
- Postman send post request
- route.get(“/api/products”)
- route.delete(“/api/products/:id”)
-
Create Products Backend
-
Redux
-
Add Redux
- what is redux (diagram)
- update task on spreadsheet
- create branch add-redux-products
- npm install redux react-redux redux-thunk
- create types
- types.js
- define FETCH_PRODUCTS
- actions/productActions.js
- declare fetchProducts
- create reducers
- reducers/productReducers.js
- define case FETCH_PRODUCTS
- create store
- store.js
- import redux
- set initial state
- define initialState
- create store
- import productReducers
- combine reducers
- Use store
- App.js
- import store
- wrap all in Provider
- connect products
- components/Products.js
- connect to store
- import fetchProducts
- fetch products on did mount
- package.json
- set proxy to http://127.0.0.1:5000
- npm run server
- check products list
- commit and publish
- send pull request and merge
- update spreadsheet
<li> Add Redux To Filter <ol dir="auto"> <li> Updte task and branch </li> <li> types.js </li> <li> create FILTER_PRODUCTS_BY_SIZE </li> <li> create ORDER_PRODUCTS_BY_PRICE </li> <li> actions/productActions.js </li> <li> create filterProducts </li> <li> move app.js filterProducts logic here </li> <li> create sortProducts </li> <li> move app.js filterProducts logic here </li> <li> reducers/productReducers.js </li> <li> case FILTER_PRODUCTS_BY_SIZE </li> <li> case ORDER_PRODUCTS_BY_PRICE </li> <li> Filter.js </li> <li> connect props: size, sort, items and filteredItems </li> <li> connect actions: filterProducts and sortProducts </li> <li> show loading if no filteredProducts </li> <li> App.js </li> <li> remove Filter props </li> <li> check result </li> <li> update task and branch </li> </ol> </li> <li> Add Redux To Cart <ol dir="auto"> <li> Updte task and branch </li> <li> types.js </li> <li> create ADD_TO_CART </li> <li> create REMOVE_FROM_CART </li> <li> actions/cartActions.js </li> <li> create addToCart </li> <li> create removeFromCart </li> <li> reducers/cartReducers.js </li> <li> case ADD_TO_CART </li> <li> case REMOVE_FROM_CART </li> <li> Cart.js </li> <li> connect props: cartItems </li> <li> connect actions: removeFromCart </li> <li> Product.js </li> <li> add action addToCart </li> <li> App.js </li> <li> remove Cart props </li> <li> store.js </li> <li> set initial cartItems to localStorage </li> <li> check result </li> <li> update task and branch </li> </ol> </li> </ol>
-
Add Redux
-
Advanced Topics
-
Create Order
- Backend
- server.js
- create order modal
- get /api/orders
- post /api/orders
- delete /api/orders/:id
- Frontend
- create types
- types.js
- CLEAR_ORDER, CLEAR_CART, CREATE_ORDER
- create actions
- actions/orderActions.js
- createOrder(order)
- clearOrder()
- create reducers
- reducers/orderReducers.js
- case CREATE_ORDER
- case CLEAR_ORDER
- Update Cart Component
- components/Cart.js
- connect order, createOrder, clearOrder
- form onSubmit={this.createOrder}
- createOrder() this.props.createOrder(order)
- closeModal() this.props.clearOrder()
- render()
- const { cartItems, order } = this.props;
- {order && (}
<li> Manage Orders <ol dir="auto"> <li> Add new page </li> <li> Install react-router-dom </li> <li> App.js </li> <li> Import BrowserRouter, Route, Link </li> <li> render() </li> <li> BrowserRouter </li> <li> Route path=”/admin” component={AdminScreen} </li> <li> Route path=”/” exact={true} component={HomeScreen} </li> <li> HomeScreen.js </li> <li> </li> <li> AdminScreen.js </li> <li> </li> <li> components/Orders.js </li> <li> render() Orders </li> <li> Backend </li> <li> server.js </li> <li> app.get(“/api/orders”) </li> <li> app.delete(“/api/orders/:id”) </li> <li> Frontend </li> <li> types.js </li> <li> FETCH_ORDERS </li> <li> actions/orderActions.js </li> <li> fetchOrders() </li> <li> reducers/orderReducers.js </li> <li> case FETCH_ORDERS {orders: action.payload} </li> <li> components/Orders.js </li> <li> connect orders, fetchOrders </li> <li> componentDidMount() fetchOrders </li> <li> render() </li> <li> !orders Loading… </li> <li> table orders </li> <li> index.css </li> <li> style orders </li> </ol> </li> </ol>
-
Create Order
-
Deploy Website
- Create MongoDB Cloud Database
- Login to https://www.mongodb.com/cloud
- Add database user
- Left sidebar> Select Security > Database Access
- Select Add New User button
- Enter user name and password and click Add User
- Add IP whitelist
- Left sidebar > Select Security > Network Access
- Select Add IP Address
- Enter 0.0.0.0/0 in Whitelist Entry and click Confirm
- Get connection string
- Left sidebar > Select Altas > Cluster
- Click Connect
- Click Connect to your application
- Click Copy button
- Step 2: Deploy On Heroku
- Create git repository in amazona folder using git init
- Create Heroku Account at heroku.com
- Heroku
- Create Heroku account on heroku.com
- Install Heroku cli https://devcenter.heroku.com/articles/heroku-cli
- Open Terminal
- heroku login
- heroku apps:create react-shopping-cart-best
- Edit package.json
- “engines”: { “node”: “12.4.0”, “npm”: “6.9.0”}
- Create Procfile
- web: node server.js
- Set MongoDB connection string in Heroku
- Open Heroku apps https://dashboard.heroku.com/apps/
- Select your apps, open Setting Tab and click Reveal Config Vars
- Add key MONGODB_URL
- Enter copied connection string from the previous step
- Update database name and username and password
- Add key NODE_MODULES_CACHE and value false
- app.use(“/”, express.static(__dirname + “/build”));
- app.get(“/”, (req, res) => res.sendFile(__dirname + “/build/index.html”));
- git add . && git commit -m “publish”
- git push heroku