Versione 1.2.71:
- sistemato il carrello su GruppoMacro e su PiuCheBuono. - Corretto visualizzazione della scontistica. - Se un prodotto viene cancellato ora lo cancella anche sul carrello.
This commit is contained in:
@@ -227,36 +227,56 @@ class Cart {
|
||||
async updateOrderTotals(order, updateCalcPrice) {
|
||||
order.TotalPriceProductCalc = 0;
|
||||
|
||||
// PROVO A METTERE SEMPRE CHE MI RICALCOLA IL PREZZO !
|
||||
// updateCalcPrice = true;
|
||||
try {
|
||||
// PROVO A METTERE SEMPRE CHE MI RICALCOLA IL PREZZO !
|
||||
// updateCalcPrice = true;
|
||||
|
||||
if (updateCalcPrice) {
|
||||
order.TotalPriceProduct = 0;
|
||||
if (updateCalcPrice) {
|
||||
order.TotalPriceProduct = 0;
|
||||
}
|
||||
|
||||
const qty = order.quantity + order.quantitypreordered;
|
||||
this.totalQty += qty;
|
||||
|
||||
const recscontisticheTrovate = await Cart.getRecSconto(this.idapp, this.codice_sconto, true);
|
||||
|
||||
const scontiDaUsare = recscontisticheTrovate?.length ? recscontisticheTrovate : order.scontisticas || [];
|
||||
const priceCalc = this.calcolaPrezzoScontato(order, qty, scontiDaUsare);
|
||||
const priceintero = this.calcolaPrezzoScontato(order, qty, []);
|
||||
|
||||
order.TotalPriceProductCalc += priceCalc;
|
||||
|
||||
if (updateCalcPrice) {
|
||||
order.TotalPriceProduct += priceCalc;
|
||||
order.TotalPriceProductstr = parseFloat(order.TotalPriceProduct.toFixed(2));
|
||||
}
|
||||
|
||||
this.totalPrice += order.TotalPriceProduct;
|
||||
this.totalPriceCalc += priceCalc;
|
||||
this.totalPriceIntero += priceintero;
|
||||
|
||||
// se idGasOrdine === '' allora toglilo
|
||||
if (order.idGasordine === '') {
|
||||
delete order.idGasordine;
|
||||
}
|
||||
if (order.idStorehouse === '') {
|
||||
delete order.idStorehouse;
|
||||
}
|
||||
if (order.idProvider === '') {
|
||||
delete order.idProvider;
|
||||
}
|
||||
if (order.idProducer === '') {
|
||||
delete order.idProducer;
|
||||
}
|
||||
|
||||
// if (updateCalcPrice) {
|
||||
// Aggiorna anche l'ordine associato
|
||||
await Order.findOneAndUpdate({ _id: order._id }, { $set: order }, { new: false });
|
||||
} catch (e) {
|
||||
console.error('Err updateOrderTotals', e);
|
||||
}
|
||||
|
||||
const qty = order.quantity + order.quantitypreordered;
|
||||
this.totalQty += qty;
|
||||
|
||||
const recscontisticheTrovate = await Cart.getRecSconto(this.idapp, this.codice_sconto, true);
|
||||
|
||||
const scontiDaUsare = recscontisticheTrovate?.length ? recscontisticheTrovate : order.scontisticas || [];
|
||||
const priceCalc = this.calcolaPrezzoScontato(order, qty, scontiDaUsare);
|
||||
const priceintero = this.calcolaPrezzoScontato(order, qty, []);
|
||||
|
||||
order.TotalPriceProductCalc += priceCalc;
|
||||
|
||||
if (updateCalcPrice) {
|
||||
order.TotalPriceProduct += priceCalc;
|
||||
order.TotalPriceProductstr = parseFloat(order.TotalPriceProduct.toFixed(2));
|
||||
}
|
||||
|
||||
this.totalPrice += order.TotalPriceProduct;
|
||||
this.totalPriceCalc += priceCalc;
|
||||
this.totalPriceIntero += priceintero;
|
||||
|
||||
// if (updateCalcPrice) {
|
||||
// Aggiorna anche l'ordine associato
|
||||
await Order.findOneAndUpdate({ _id: order._id }, { $set: order }, { new: false });
|
||||
// await Order.findOneAndUpdate({ _id: order._id }, { $set: order }, { new: false });
|
||||
// }
|
||||
}
|
||||
|
||||
@@ -356,6 +376,26 @@ class Cart {
|
||||
console.error("Errore durante l'aggiornamento del carrello:", e);
|
||||
}
|
||||
}
|
||||
|
||||
static async aggiornaCarrelloByCart(mycartpar, userId, idapp) {
|
||||
try {
|
||||
let mycart = mycartpar;
|
||||
|
||||
if (!mycart) mycart = await cartModel.getCartByUserId(userId, idapp);
|
||||
|
||||
if (!mycart) return null;
|
||||
|
||||
mycart = await cartModel.getCartCompletoByCartId(mycart._id, idapp);
|
||||
|
||||
let newCart = await Cart.constructByCart(mycart);
|
||||
if (newCart) return newCart.aggiornaCarrello();
|
||||
|
||||
return newCart;
|
||||
} catch (e) {
|
||||
console.error('Err AggiornaCarrello', e);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = Cart;
|
||||
|
||||
Reference in New Issue
Block a user