aggiornamento visualizzazione Ordini e Carrello
This commit is contained in:
@@ -45,12 +45,16 @@ class Cart {
|
||||
}
|
||||
|
||||
async subqty(itemorder) {
|
||||
const myitem = this.items.find((rec) => rec.order._id.toString() === itemorder._id)
|
||||
if (!!myitem) {
|
||||
myitem.order.quantity--;
|
||||
await Order.findOneAndUpdate({ _id: myitem.order._id }, { $set: myitem.order }, { new: false });
|
||||
this.updatetotals();
|
||||
return myitem.order.quantity;
|
||||
try {
|
||||
const myitem = this.items.find((rec) => rec.order._id.toString() === itemorder._id)
|
||||
if (!!myitem && myitem.order.quantity > 0) {
|
||||
myitem.order.quantity--;
|
||||
await Order.findOneAndUpdate({ _id: myitem.order._id }, { $set: myitem.order }, { new: false });
|
||||
this.updatetotals();
|
||||
return myitem.order.quantity;
|
||||
}
|
||||
} catch (e) {
|
||||
console.error('Err: ', e);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -86,18 +90,22 @@ class Cart {
|
||||
}
|
||||
|
||||
updatetotals() {
|
||||
this.totalQty = 0;
|
||||
this.totalPrice = 0;
|
||||
for (const rec in this.items) {
|
||||
let order = this.items[rec].order;
|
||||
if (!order) {
|
||||
order = this.items[rec];
|
||||
try {
|
||||
this.totalQty = 0;
|
||||
this.totalPrice = 0;
|
||||
for (const rec in this.items) {
|
||||
let order = this.items[rec].order;
|
||||
if (!order) {
|
||||
order = this.items[rec];
|
||||
}
|
||||
this.totalQty += order.quantity;
|
||||
this.totalPrice += order.price * order.quantity;
|
||||
}
|
||||
this.totalQty += order.quantity;
|
||||
this.totalPrice += order.price * order.quantity;
|
||||
|
||||
this.totalPrice = parseFloat(this.totalPrice.toFixed(2))
|
||||
} catch (e) {
|
||||
console.error('Err: ', e);
|
||||
}
|
||||
|
||||
this.totalPrice = parseFloat(this.totalPrice.toFixed(2))
|
||||
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user