From 3d1a330fa26708057ad2bd98ca6e3a71ecfc7e5d Mon Sep 17 00:00:00 2001 From: Surya Paolo Date: Tue, 16 Jan 2024 23:00:10 +0100 Subject: [PATCH] =?UTF-8?q?Poter=20inserire=20un=20Ordine=20anche=20per=20?= =?UTF-8?q?un=20altra=20persona...=20(Modalit=C3=A0=20Cassa)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/server/models/cart.js | 4 ++++ src/server/modules/Cart.js | 11 +++++++---- src/server/router/cart_router.js | 2 ++ 3 files changed, 13 insertions(+), 4 deletions(-) diff --git a/src/server/models/cart.js b/src/server/models/cart.js index 3d5cfdb..b4cf9eb 100755 --- a/src/server/models/cart.js +++ b/src/server/models/cart.js @@ -17,6 +17,7 @@ const CartSchema = new Schema({ userId: { type: Schema.Types.ObjectId, ref: 'User' }, totalQty: { type: Number, default: 0 }, totalPrice: { type: Number, default: 0 }, + totalPriceCalc: { type: Number, default: 0 }, department: { type: String, ref: 'Department', }, @@ -88,6 +89,7 @@ module.exports.updateCartByUserId = function (userId, newCart, callback) { items: newCart.items, totalQty: newCart.totalQty, totalPrice: newCart.totalPrice, + totalPriceCalc: newCart.totalPriceCalc, userId: userId, }, }, @@ -106,6 +108,7 @@ module.exports.updateCartByCartId = async function (cartId, newCart) { const items = newCart.items; const totalQty = newCart.totalQty; const totalPrice = newCart.totalPrice; + const totalPriceCalc = newCart.totalPriceCalc; const note = newCart.note; const modify_at = new Date(); @@ -114,6 +117,7 @@ module.exports.updateCartByCartId = async function (cartId, newCart) { $set: { items, totalPrice, + totalPriceCalc, totalQty, note, modify_at: new Date(), diff --git a/src/server/modules/Cart.js b/src/server/modules/Cart.js index b959cb0..0f8d69d 100755 --- a/src/server/modules/Cart.js +++ b/src/server/modules/Cart.js @@ -245,17 +245,20 @@ class Cart { } else { mypricecalc = (order.price * order.quantity) + (order.price * order.quantitypreordered); - order.TotalPriceProductCalc += mypricecalc; - if (updatecalcprice) { - order.TotalPriceProduct += mypricecalc; - } } + // Aggiorna Totali + order.TotalPriceProductCalc += mypricecalc; + if (updatecalcprice) { + order.TotalPriceProduct += mypricecalc; + } + // Qui lo calcolo sempre, anche se lo cambio manualmente this.totalPriceCalc += mypricecalc; this.totalPrice += order.TotalPriceProduct; } this.totalPrice = parseFloat(this.totalPrice.toFixed(2)) + this.totalPriceCalc = parseFloat(this.totalPriceCalc.toFixed(2)) } catch (e) { console.error('Err: ', e); diff --git a/src/server/router/cart_router.js b/src/server/router/cart_router.js index 3461f58..1ec1c94 100755 --- a/src/server/router/cart_router.js +++ b/src/server/router/cart_router.js @@ -201,6 +201,7 @@ router.put('/:userId', authenticate, async function (req, res, next) { items: newCart.items, totalQty: newCart.totalQty, totalPrice: newCart.totalPrice, + totalPriceCalc: newCart.totalPriceCalc, userId: userId }, function (err, result) { @@ -213,6 +214,7 @@ router.put('/:userId', authenticate, async function (req, res, next) { items: newCart.items, totalQty: newCart.totalQty, totalPrice: newCart.totalPrice, + totalPriceCalc: newCart.totalPriceCalc, userId: userId } await Cart.createCart(newCartobj, function (err, resultCart) {