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 }) {
<div className="my-1 pt-2 border-top font-weight-bold">
결제금액<span className="float-right">{finalPrice + 2500}</span>
</div>
<div>
<h5 className="font-weight-bold py-3 border-top border-bottom text-center" style={{ background: '#F7F3F3' }}>결제수단</h5>
<div className="text-center m-3">
<Button className="align-top m-1" variant="success" onClick={handleClick} style={{ height: '42px' }}>무통장입금</Button>
<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>
</div>
{paymentWay}
</div>
<div className="text-center">
<Button type="button" onClick={paymentCompleted} className="px-5" style={{ background: "#91877F", borderColor: '#91877F' }} block>결제완료</Button>
</div>
<div>
<h5 className="font-weight-bold py-3 border-top border-bottom text-center" style={{ background: '#F7F3F3' }}>결제수단</h5>
<div className="text-center m-3">
<Button className="align-top m-1" variant="success" onClick={handleClick} style={{ height: '42px' }}>무통장입금</Button>
<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>
</div>
{paymentWay}
</div>
<div className="text-center">
<Button type="button" onClick={paymentCompleted} className="px-5" style={{ background: "#91877F", borderColor: '#91877F' }} block>결제완료</Button>
</div>
</Container>
)
......
......@@ -29,16 +29,15 @@ function Product({ match, location }) {
if (size && color) {
pushOptions()
}
getRecommend()
}, [size, color])
async function recommend(){
async function getRecommend(){
try {
console.log("pro=",product.id)
const response = await axios.post('/api/order/recommend', { productId: product.id})
console.log("recommend res=",response.data)
const response = await axios.get(`/api/order/recommend?products=${product.id}`)
setProductList(response.data)
} catch (error) {
catchErrors(error, setError)
catchErrors(error,setError)
}
}
......@@ -155,6 +154,7 @@ function Product({ match, location }) {
return (
<div>
{console.log(product)}
<style type="text/css">
{`
.btn {
......
......@@ -20,6 +20,7 @@ const changeCart = async (req, res) => {
console.log(products)
try {
const cart = await Cart.findOne({ userId: userId })
console.log(cart)
await Cart.updateOne(
{ _id: cart._id },
{ $set: { products: products } }
......@@ -38,7 +39,7 @@ const showCart = async (req, res) => {
model: 'Product'
})
res.status(200).json(cart.products)
console.log("cart-products : ", cart.products);
console.log("cart-products : ", cart);
} catch (error) {
console.log("xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx")
console.log(error)
......
import mongoose from 'mongoose';
import Order from "../schemas/Order.js";
import User from "../schemas/User.js";
import Product from "../schemas/Product.js";
const addorder = async (req, res) => {
const { userId, products, receiverInfo, total } = req.body
......@@ -51,26 +52,41 @@ const orderById = async (req, res, next, id) => {
}
const recommendPro = async (req, res) => {
const { productId } = req.body
console.log(productId)
const productId = req.query.products
try {
const recommend = await Order.aggregate([
{
$match: {
'products.productId': { $ne : [ "$productId[0]", mongoose.Types.ObjectId(productId)] }
'products.productId': mongoose.Types.ObjectId(productId)
}
},
{ "$unwind": "$products" },
{
$group: {
productId: "$products.productId",
total: { $sum: 1 }
_id: "$products.productId",
count: { $sum: 1 }
}
}
])
const sorting = recommend.filter({})
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) {
console.log('error in order ', error)
}
......
......@@ -6,6 +6,9 @@ const router = express.Router()
router.route('/addorder')
.post(orderCtrl.addorder)
router.route('/recommend')
.get(orderCtrl.recommendPro)
router.route('/showorder/:userId')
.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