Commit 6ff1b7f2 authored by kusang96's avatar kusang96
Browse files

Merge remote-tracking branch 'origin/jiwon' into kimpen

parents 07a6689c beb80a05
...@@ -302,17 +302,17 @@ function Payment({ match, location }) { ...@@ -302,17 +302,17 @@ function Payment({ match, location }) {
<div className="my-1 pt-2 border-top font-weight-bold"> <div className="my-1 pt-2 border-top font-weight-bold">
결제금액<span className="float-right">{finalPrice + 2500}</span> 결제금액<span className="float-right">{finalPrice + 2500}</span>
</div> </div>
<div> </div>
<h5 className="font-weight-bold py-3 border-top border-bottom text-center" style={{ background: '#F7F3F3' }}>결제수단</h5> <div>
<div className="text-center m-3"> <h5 className="font-weight-bold py-3 border-top border-bottom text-center" style={{ background: '#F7F3F3' }}>결제수단</h5>
<Button className="align-top m-1" variant="success" onClick={handleClick} style={{ height: '42px' }}>무통장입금</Button> <div className="text-center m-3">
<Button className="align-top m-1 p-0" style={{ borderColor: "#ffeb00" }} type="button" onClick={kakaopay} alt="카카오페이"><img src="icon/payment_icon_yellow_small2.png" /></Button> <Button className="align-top m-1" variant="success" onClick={handleClick} style={{ height: '42px' }}>무통장입금</Button>
</div> <Button className="align-top m-1 p-0" style={{ borderColor: "#ffeb00" }} type="button" onClick={kakaopay} alt="카카오페이"><img src="icon/payment_icon_yellow_small2.png" /></Button>
{paymentWay}
</div>
<div className="text-center">
<Button type="button" onClick={paymentCompleted} className="px-5" style={{ background: "#91877F", borderColor: '#91877F' }} block>결제완료</Button>
</div> </div>
{paymentWay}
</div>
<div className="text-center">
<Button type="button" onClick={paymentCompleted} className="px-5" style={{ background: "#91877F", borderColor: '#91877F' }} block>결제완료</Button>
</div> </div>
</Container> </Container>
) )
......
...@@ -29,16 +29,15 @@ function Product({ match, location }) { ...@@ -29,16 +29,15 @@ function Product({ match, location }) {
if (size && color) { if (size && color) {
pushOptions() pushOptions()
} }
getRecommend()
}, [size, color]) }, [size, color])
async function recommend(){ async function getRecommend(){
try { try {
console.log("pro=",product.id) const response = await axios.get(`/api/order/recommend?products=${product.id}`)
const response = await axios.post('/api/order/recommend', { productId: product.id})
console.log("recommend res=",response.data)
setProductList(response.data) setProductList(response.data)
} catch (error) { } catch (error) {
catchErrors(error, setError) catchErrors(error,setError)
} }
} }
...@@ -155,6 +154,7 @@ function Product({ match, location }) { ...@@ -155,6 +154,7 @@ function Product({ match, location }) {
return ( return (
<div> <div>
{console.log(product)}
<style type="text/css"> <style type="text/css">
{` {`
.btn { .btn {
......
...@@ -20,6 +20,7 @@ const changeCart = async (req, res) => { ...@@ -20,6 +20,7 @@ const changeCart = async (req, res) => {
console.log(products) console.log(products)
try { try {
const cart = await Cart.findOne({ userId: userId }) const cart = await Cart.findOne({ userId: userId })
console.log(cart)
await Cart.updateOne( await Cart.updateOne(
{ _id: cart._id }, { _id: cart._id },
{ $set: { products: products } } { $set: { products: products } }
...@@ -38,7 +39,7 @@ const showCart = async (req, res) => { ...@@ -38,7 +39,7 @@ const showCart = async (req, res) => {
model: 'Product' model: 'Product'
}) })
res.status(200).json(cart.products) res.status(200).json(cart.products)
console.log("cart-products : ", cart.products); console.log("cart-products : ", cart);
} catch (error) { } catch (error) {
console.log("xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx") console.log("xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx")
console.log(error) console.log(error)
......
import mongoose from 'mongoose'; import mongoose from 'mongoose';
import Order from "../schemas/Order.js"; import Order from "../schemas/Order.js";
import User from "../schemas/User.js"; import User from "../schemas/User.js";
import Product from "../schemas/Product.js";
const addorder = async (req, res) => { const addorder = async (req, res) => {
const { userId, products, receiverInfo, total } = req.body const { userId, products, receiverInfo, total } = req.body
...@@ -51,26 +52,41 @@ const orderById = async (req, res, next, id) => { ...@@ -51,26 +52,41 @@ const orderById = async (req, res, next, id) => {
} }
const recommendPro = async (req, res) => { const recommendPro = async (req, res) => {
const { productId } = req.body const productId = req.query.products
console.log(productId)
try { try {
const recommend = await Order.aggregate([ const recommend = await Order.aggregate([
{ {
$match: { $match: {
'products.productId': { $ne : [ "$productId[0]", mongoose.Types.ObjectId(productId)] } 'products.productId': mongoose.Types.ObjectId(productId)
} }
}, },
{ "$unwind": "$products" }, { "$unwind": "$products" },
{ {
$group: { $group: {
productId: "$products.productId", _id: "$products.productId",
total: { $sum: 1 } count: { $sum: 1 }
} }
} }
]) ])
const sorting = recommend.filter({})
console.log('recommend=', recommend) console.log('recommend=', recommend)
res.send('dddkfdskfsa fsk') const filteredRecommend = recommend.filter((el) => String(el._id) !== String(productId))
console.log('filtering=', filteredRecommend)
filteredRecommend.sort(function (a, b) {
if (a.count > b.count) {
return -1;
}
if (a.count < b.count) {
return 1;
}
// a must be equal to b
return 0;
});
const array = filteredRecommend.map(async (el) => {
const aa = await Product.findById(el._id)
return aa
})
const bb = await Promise.all(array)
res.json(bb)
} catch (error) { } catch (error) {
console.log('error in order ', error) console.log('error in order ', error)
} }
......
...@@ -6,6 +6,9 @@ const router = express.Router() ...@@ -6,6 +6,9 @@ const router = express.Router()
router.route('/addorder') router.route('/addorder')
.post(orderCtrl.addorder) .post(orderCtrl.addorder)
router.route('/recommend')
.get(orderCtrl.recommendPro)
router.route('/showorder/:userId') router.route('/showorder/:userId')
.get(orderCtrl.showorder) .get(orderCtrl.showorder)
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment