possibilità di modificare un ordine, e anche i totali
This commit is contained in:
@@ -101,7 +101,7 @@ router.post('/:userId', authenticate, async function (req, res, next) {
|
||||
return res.send({ code: server_constants.RIS_CODE_ERR, cart: null, myord: null, msgerr: 'Non è possibile acquistare nello stesso ordine, su negozi differenti!' });
|
||||
}
|
||||
} else {
|
||||
await newCart.updatetotals();
|
||||
await newCart.updatecarttotals(true);
|
||||
const arrord = await Order.getTotalOrderById(order._id);
|
||||
myord = arrord ? arrord[0] : null;
|
||||
}
|
||||
@@ -270,6 +270,7 @@ router.post('/:userId/createorderscart', authenticate, async function (req, res,
|
||||
items: mycart.items,
|
||||
totalQty: mycart.totalQty,
|
||||
totalPrice: mycart.totalPrice,
|
||||
totalPriceCalc: mycart.totalPriceCalc,
|
||||
userId,
|
||||
status,
|
||||
note,
|
||||
@@ -324,14 +325,6 @@ router.post('/:userId/createorderscart', authenticate, async function (req, res,
|
||||
})
|
||||
}
|
||||
})
|
||||
} else if (status < shared_consts.OrderStatus.CHECKOUT_SENT) {
|
||||
// Aggiorna il carrello !
|
||||
|
||||
/*const cartpao = await Cart.getCartByUserId(userId, idapp);
|
||||
let newCart = CartClass.constructByCart(cartpao);
|
||||
if (newCart)
|
||||
await newCart.updatetotals();
|
||||
newCart;*/
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -66,21 +66,31 @@ router.post('/updateord', authenticate, async (req, res) => {
|
||||
|
||||
|
||||
router.post('/update', authenticate, async (req, res) => {
|
||||
let orderscart = null;
|
||||
const idOrdersCart = req.body.idOrdersCart;
|
||||
const paramstoupdate = req.body.paramstoupdate;
|
||||
|
||||
try {
|
||||
// Aggiorno Orderscart con i parametri passati
|
||||
await OrdersCart.updateOrdersCartByParams(idOrdersCart, paramstoupdate);
|
||||
orderscart = await OrdersCart.updateOrdersCartByParams(idOrdersCart, paramstoupdate);
|
||||
|
||||
// Aggiorno il Totale degli Ordini (OrdersCart)
|
||||
await OrdersCart.updateOrdersCartTotals(idOrdersCart, true)
|
||||
.then((orderscart) => {
|
||||
return res.send({ code: server_constants.RIS_CODE_OK, orderscart });
|
||||
}).catch(err => {
|
||||
console.log('ERR:', err);
|
||||
res.status(400).send();
|
||||
});
|
||||
let updatetotals = true;
|
||||
if (paramstoupdate && paramstoupdate.hasOwnProperty('totalPrice')) {
|
||||
updatetotals = false;
|
||||
}
|
||||
if (updatetotals) {
|
||||
|
||||
// Aggiorno il Totale degli Ordini (OrdersCart)
|
||||
await OrdersCart.updateOrdersCartTotals(idOrdersCart, true)
|
||||
.then((orderscart) => {
|
||||
return res.send({ code: server_constants.RIS_CODE_OK, orderscart });
|
||||
}).catch(err => {
|
||||
console.log('ERR:', err);
|
||||
res.status(400).send();
|
||||
});
|
||||
} else {
|
||||
return res.send({ code: server_constants.RIS_CODE_OK, orderscart });
|
||||
}
|
||||
} catch (e) {
|
||||
console.error('Err', e);
|
||||
}
|
||||
|
||||
@@ -1330,6 +1330,22 @@ async function eseguiDbOp(idapp, mydata, locale, req, res) {
|
||||
} catch (e) {
|
||||
console.error('Err:', e);
|
||||
}
|
||||
} else if (mydata.dbop === 'CopyPriceToCalc') {
|
||||
|
||||
try {
|
||||
const arrrec = await OrdersCart.find({}).lean();
|
||||
for (const rec of arrrec) {
|
||||
await OrdersCart.findByIdAndUpdate(rec._id, { $set: { totalPriceCalc: rec.totalPrice } })
|
||||
}
|
||||
|
||||
const arrrec2 = await Order.find({}).lean();
|
||||
for (const rec of arrrec2) {
|
||||
await Order.findByIdAndUpdate(rec._id, { $set: { TotalPriceProductCalc: rec.TotalPriceProduct } })
|
||||
}
|
||||
|
||||
} catch (e) {
|
||||
console.error('Err:', e);
|
||||
}
|
||||
|
||||
} else if (mydata.dbop === 'dropAllCarts') {
|
||||
|
||||
|
||||
Reference in New Issue
Block a user