diff --git a/client/src/components/Product_card/index.js b/client/src/components/Product_card/index.js
index 61539196..910d7170 100644
--- a/client/src/components/Product_card/index.js
+++ b/client/src/components/Product_card/index.js
@@ -1,68 +1,71 @@
-
import React, { Component } from 'react'
import './style.css'
-import axios from 'axios';
+import axios from 'axios'
import { Link } from 'react-router-dom'
-
class ProductCard extends React.Component {
state = {
-
products: [],
- loading:true,
+ loading: true,
+ path1:"/shop"
}
-
+
componentDidMount() {
- if(this.props.match.params.id)
- {
- axios.get(`/shop/${this.props.match.params.id}`)
- .then( ({data}) => {
- this.setState({products:data,loading:false})
- })}
- else{
- axios.get("/shop")
- .then( ({data}) => {
- this.setState({products:data,loading:false})
-
+ this.setState({path1:this.props.path})
+ if (this.props.match.params.id) {
+ axios.get(`/shop/${this.props.match.params.id}`).then(({ data }) => {
+ this.setState({ products: data, loading: false })
+ })
+ } else {
+ axios.get('/shop').then(({ data }) => {
+ this.setState({ products: data, loading: false })
})
}
}
-
- searchedProducts = (products)=>{
-this.setState({products:products,loading:false})
+
+ searchedProducts = products => {
+ this.setState({ products: products, loading: false })
}
- render () {
- const {products,loading,searchedProducts} = this.state
- const myProducts = this.props.resultAfterSerch ? this.props.resultAfterSerch:products
+ render() {
+ const { products, loading, searchedProducts } = this.state
+ const myProducts = this.props.resultAfterSerch
+ ? this.props.resultAfterSerch
+ : products
return (
<>
- {!loading ? myProducts.length>0 ?(
-
-myProducts.map(e=>(
-
-
-
-
![product-img]({e.img})
-
{e.name}
-
₪ {e.price}
-
-
-
-
- ))) : (There is no products
- ):(
-
-
- )}
- >
+ {!loading ? (
+ myProducts.length > 0 ? (
+ myProducts.map(e => (
+
+
+
+
+
![product-img]({e.img})
+
{e.name}
+
₪ {e.price}
+
+
+
+
+ ))
+ ) : (
+ There is no products
+ )
+ ) : (
+
+ )}
+ >
)
}
}
export default ProductCard
-
diff --git a/client/src/components/Product_page/Add_quantity_cart/index.js b/client/src/components/Product_page/Add_quantity_cart/index.js
index 1a6128e3..b45e1aa2 100644
--- a/client/src/components/Product_page/Add_quantity_cart/index.js
+++ b/client/src/components/Product_page/Add_quantity_cart/index.js
@@ -1,6 +1,7 @@
import React, { Component } from 'react'
-import axios from 'axios'
import './style.css'
+import axios from 'axios'
+import swal from 'sweetalert'
class AddQuantityCart extends Component {
state = {
@@ -16,9 +17,22 @@ class AddQuantityCart extends Component {
axios
.post('/add-to-cart', productInfo)
.then(response => {
- console.log(response, 'done, added to cart')
+ swal({
+ title: 'added to cart',
+ icon: 'success',
+ button: 'Continue shoping'
+ }).then(res => {
+ window.location.href = `${this.props.prePath}`
+ })
})
.catch(error => {
+ swal({
+ title: 'err add to cart',
+ icon: 'error',
+ button: 'return to shoping'
+ }).then(res => {
+ window.location.href = `${this.props.prePath}`
+ })
console.log(error, 'components/Product_page/Add_quantity_cart')
})
}
diff --git a/client/src/components/Product_page/index.js b/client/src/components/Product_page/index.js
index 4b6c1b02..33abb93f 100644
--- a/client/src/components/Product_page/index.js
+++ b/client/src/components/Product_page/index.js
@@ -5,17 +5,25 @@ import ProductInfo from '../Product_page/product_info'
import AddQuantityCart from '../Product_page/Add_quantity_cart'
class ProductPage extends Component {
- state = {price:0}
+ state = { price: 0 }
- setPrice=(newPrice)=>{
- this.setState({price:newPrice})
+ setPrice = newPrice => {
+ this.setState({ price: newPrice })
}
- render () {
+ render() {
return (
<>
-
-
+
+
>
)
}
diff --git a/client/src/components/Shop/index.js b/client/src/components/Shop/index.js
index 4c861886..eb5ee233 100644
--- a/client/src/components/Shop/index.js
+++ b/client/src/components/Shop/index.js
@@ -38,7 +38,7 @@ class Shop extends Component {
trigger={this.state.afterSearchTrigger}
serchArray={this.searchSetArray}
/>
-
+
)
}
diff --git a/src/controller/add_to_cart.js b/src/controller/add_to_cart.js
index 5cdb256c..ed03ecb3 100644
--- a/src/controller/add_to_cart.js
+++ b/src/controller/add_to_cart.js
@@ -1,11 +1,14 @@
const addToCart = require('../database/queries/add_to_cart')
-exports.post = (req, res) => {
+exports.post = (req, res, next) => {
const { productID, quantity, price } = req.body
const userID = 1 // user id static we will get user id from cookies
addToCart(userID, productID, quantity, price)
.then(result => {
res.send(JSON.stringify({ product: result }))
})
- .catch(err => console.log(err, 'add_to_cart.js'))
+ .catch(err => {
+ console.log(err, 'controller/add_to_cart.js')
+ next(err)
+ })
}