fix : cart total_discount
This commit is contained in:
@@ -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 });
|
||||
|
||||
@@ -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
|
||||
],
|
||||
},
|
||||
},
|
||||
|
||||
@@ -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());
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user