fix : cart total_discount

This commit is contained in:
morteza-mortezai
2025-10-28 17:27:06 +03:30
parent 3e8f6a3ea5
commit 76c0e6a83e
3 changed files with 10 additions and 5 deletions
+1 -1
View File
@@ -209,7 +209,7 @@ class CouponService {
cartShipmentItem.totalCouponDiscount = discount;
cartShipmentItem.totalPaymentPrice = cartShipmentItem.totalPaymentPrice - discount;
userCart.coupon_discount = discount;
userCart.total_discount += discount;
coupon.usageCount += 1;
await validCartShipmentItem.save({ session });
+8 -3
View File
@@ -310,9 +310,14 @@ class CartRepository extends BaseRepository<ICart> {
},
total_discount: {
$sum: {
$subtract: [
{ $multiply: ["$items.quantity", "$variantDetails.price.retailPrice"] },
{ $multiply: ["$items.quantity", "$variantDetails.price.selling_price"] },
$add: [
{
$subtract: [
{ $multiply: ["$items.quantity", "$variantDetails.price.retailPrice"] },
{ $multiply: ["$items.quantity", "$variantDetails.price.selling_price"] },
],
},
{ $divide: ["$coupon_discount", { $literal: 1 }] }, // safely adds coupon_discount
],
},
},
+1 -1
View File
@@ -25,8 +25,8 @@ class CartService {
async getCartS(userId: string) {
const doc = (await this.cartRepo.getCartWithAggregate(userId))[0] as ICart;
const cart = CartDTO.transformCart(doc);
let cartShipmentItems;
if (doc?._id) {
cartShipmentItems = await this.cartShipItemRepo.getCartShipmentItems(doc._id.toString());
}