@@ -209,7 +209,7 @@ class CouponService {
|
|||||||
cartShipmentItem.totalCouponDiscount = discount;
|
cartShipmentItem.totalCouponDiscount = discount;
|
||||||
cartShipmentItem.totalPaymentPrice = cartShipmentItem.totalPaymentPrice - discount;
|
cartShipmentItem.totalPaymentPrice = cartShipmentItem.totalPaymentPrice - discount;
|
||||||
userCart.coupon_discount = discount;
|
userCart.coupon_discount = discount;
|
||||||
userCart.total_discount += discount;
|
|
||||||
coupon.usageCount += 1;
|
coupon.usageCount += 1;
|
||||||
|
|
||||||
await validCartShipmentItem.save({ session });
|
await validCartShipmentItem.save({ session });
|
||||||
|
|||||||
@@ -310,9 +310,14 @@ class CartRepository extends BaseRepository<ICart> {
|
|||||||
},
|
},
|
||||||
total_discount: {
|
total_discount: {
|
||||||
$sum: {
|
$sum: {
|
||||||
$subtract: [
|
$add: [
|
||||||
{ $multiply: ["$items.quantity", "$variantDetails.price.retailPrice"] },
|
{
|
||||||
{ $multiply: ["$items.quantity", "$variantDetails.price.selling_price"] },
|
$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) {
|
async getCartS(userId: string) {
|
||||||
const doc = (await this.cartRepo.getCartWithAggregate(userId))[0] as ICart;
|
const doc = (await this.cartRepo.getCartWithAggregate(userId))[0] as ICart;
|
||||||
const cart = CartDTO.transformCart(doc);
|
const cart = CartDTO.transformCart(doc);
|
||||||
|
|
||||||
let cartShipmentItems;
|
let cartShipmentItems;
|
||||||
|
|
||||||
if (doc?._id) {
|
if (doc?._id) {
|
||||||
cartShipmentItems = await this.cartShipItemRepo.getCartShipmentItems(doc._id.toString());
|
cartShipmentItems = await this.cartShipItemRepo.getCartShipmentItems(doc._id.toString());
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user