- corretto la gestione degli Sconti
- Duplicare un Catalogo
This commit is contained in:
@@ -55,14 +55,12 @@ async function aggiornaCarrello(mycartpar, userId, idapp) {
|
||||
|
||||
if (!mycart) mycart = await Cart.getCartByUserId(userId, idapp);
|
||||
|
||||
if (!mycart) {
|
||||
return null;
|
||||
}
|
||||
if (!mycart) return null;
|
||||
|
||||
mycart = await Cart.getCartCompletoByCartId(mycart._id, idapp);
|
||||
|
||||
let newCart = await CartClass.constructByCart(mycart);
|
||||
// order = await Product.updateProductInOrder(order);
|
||||
await newCart.updatecarttotals(true);
|
||||
await newCart.updateExtraOrder();
|
||||
if (newCart) return newCart.aggiornaCarrello();
|
||||
|
||||
return newCart;
|
||||
} catch (e) {
|
||||
@@ -88,7 +86,7 @@ router.post('/:userId', authenticate, async function (req, res, next) {
|
||||
|
||||
// const myorder = Order.getOrderByID(order._id);
|
||||
if (!addqty && !subqty && order) {
|
||||
order._id = await Order.createOrder(order);
|
||||
order._id = await Order.createOrder(order, mycart.codice_sconto);
|
||||
if (!order._id) {
|
||||
return res.send({ code: server_constants.RIS_CODE_ERR, cart: 0 });
|
||||
}
|
||||
@@ -210,6 +208,7 @@ router.put('/:userId', authenticate, async function (req, res, next) {
|
||||
totalQty: newCart.totalQty,
|
||||
totalPrice: newCart.totalPrice,
|
||||
totalPriceCalc: newCart.totalPriceCalc,
|
||||
totalPriceIntero: newCart.totalPriceIntero,
|
||||
userId: userId,
|
||||
});
|
||||
res.json(result);
|
||||
@@ -223,6 +222,7 @@ router.put('/:userId', authenticate, async function (req, res, next) {
|
||||
totalQty: newCart.totalQty,
|
||||
totalPrice: newCart.totalPrice,
|
||||
totalPriceCalc: newCart.totalPriceCalc,
|
||||
totalPriceIntero: newCart.totalPriceIntero,
|
||||
userId: userId,
|
||||
};
|
||||
try {
|
||||
@@ -260,12 +260,15 @@ router.post('/:userId/app_sc', authenticate, async function (req, res, next) {
|
||||
let mycart = null;
|
||||
let valido = false;
|
||||
let errmsg = '';
|
||||
let recscontisticaTrovata = null;
|
||||
|
||||
try {
|
||||
let mycart = await Cart.findOne({ _id: cart_id }).lean();
|
||||
let mycart = await Cart.getCartCompletoByCartId(cart_id, idapp);
|
||||
// let mycart = await Cart.findOne({ _id: cart_id }).lean();
|
||||
|
||||
if (codice_sconto === 'RIMUOVI') {
|
||||
mycart = await Cart.findOneAndUpdate({ _id: cart_id }, { $set: { codice_sconto: '' } }, { new: true }).lean();
|
||||
mycart = await aggiornaCarrello(mycart, userId, idapp);
|
||||
return res.send({ mycart, valido, msg: 'Codice Sconto rimosso', rimuovi: true });
|
||||
}
|
||||
|
||||
@@ -273,17 +276,16 @@ router.post('/:userId/app_sc', authenticate, async function (req, res, next) {
|
||||
await tools.attendiNSecondi(1);
|
||||
|
||||
if (codice_sconto) {
|
||||
const condSconto = { $regex: new RegExp(`^${codice_sconto}$`, 'i') };
|
||||
recscontisticheTrovate = await Scontistica.find({
|
||||
idapp: idapp,
|
||||
code: condSconto,
|
||||
applica: shared_consts.SCONTI_APPLICA.A_TUTTI,
|
||||
}).lean();
|
||||
|
||||
const recscontisticheTrovate = await CartClass.getRecSconto(idapp, codice_sconto, true);
|
||||
if (recscontisticheTrovate && recscontisticheTrovate.length > 0) {
|
||||
recscontisticaTrovata = recscontisticheTrovate[0];
|
||||
}
|
||||
|
||||
if (recscontisticaTrovata) {
|
||||
if (mycart.codice_sconto !== codice_sconto) {
|
||||
mycart.codice_sconto = codice_sconto;
|
||||
await Cart.updateOne({ _id: cart_id }, { $set: { codice_sconto: codice_sconto } });
|
||||
mycart.descr_sconto = recscontisticaTrovata.description;
|
||||
await Cart.updateOne({ _id: cart_id }, { $set: { codice_sconto, descr_sconto: mycart.descr_sconto } });
|
||||
}
|
||||
valido = true;
|
||||
|
||||
@@ -293,7 +295,7 @@ router.post('/:userId/app_sc', authenticate, async function (req, res, next) {
|
||||
}
|
||||
}
|
||||
|
||||
return res.send({ mycart, valido, errmsg, recsconto: recscontisticheTrovate });
|
||||
return res.send({ mycart, valido, errmsg, recsconto: recscontisticaTrovata });
|
||||
} catch (e) {
|
||||
console.error('Err Applica Sconto', e);
|
||||
return res.send({ valido: false, mycart: null, errmsg: e.message });
|
||||
@@ -321,11 +323,13 @@ async function createOrUpdateOrderFromCart({ idapp, cart, userId, status, note }
|
||||
totalQty: cart.totalQty,
|
||||
totalPrice: cart.totalPrice,
|
||||
totalPriceCalc: cart.totalPriceCalc,
|
||||
totalPriceIntero: cart.totalPriceIntero,
|
||||
note_ordine_gas: cart.note_ordine_gas,
|
||||
userId,
|
||||
status,
|
||||
note,
|
||||
codice_sconto: cart.codice_sconto,
|
||||
descr_sconto: cart.descr_sconto,
|
||||
numorder,
|
||||
numord_pers,
|
||||
created_at: new Date(),
|
||||
@@ -360,10 +364,12 @@ async function handleCheckout({ myorderCart, mycart, userId, idapp, req, options
|
||||
|
||||
//POST cart
|
||||
router.post('/:userId/createorderscart', authenticate, async function (req, res) {
|
||||
const { idapp, cart_id, status, note, options } = req.body;
|
||||
const userId = req.params.userId;
|
||||
|
||||
try {
|
||||
const { idapp, cart_id, status, note, options } = req.body;
|
||||
const userId = req.params.userId;
|
||||
|
||||
// console.log('createorderscart', cart_id);
|
||||
|
||||
const mycart = await getCartById(cart_id);
|
||||
if (!mycart) {
|
||||
return res.send({
|
||||
@@ -401,6 +407,8 @@ router.post('/:userId/createorderscart', authenticate, async function (req, res)
|
||||
}
|
||||
}
|
||||
|
||||
// console.log('SEND OK', statusOrderCart);
|
||||
|
||||
return res.send({
|
||||
code: server_constants.RIS_CODE_OK,
|
||||
status: statusOrderCart,
|
||||
|
||||
Reference in New Issue
Block a user