in src/Modules/SimplCommerce.Module.ShoppingCart/Services/CartService.cs [113:170]
public async Task<CartVm> GetActiveCartDetails(long customerId, long createdById)
{
var cart = await GetActiveCart(customerId, createdById);
if (cart == null)
{
return null;
}
var cartVm = new CartVm(_currencyService)
{
Id = cart.Id,
CouponCode = cart.CouponCode,
IsProductPriceIncludeTax = cart.IsProductPriceIncludeTax,
TaxAmount = cart.TaxAmount,
ShippingAmount = cart.ShippingAmount,
OrderNote = cart.OrderNote,
LockedOnCheckout = cart.LockedOnCheckout
};
cartVm.Items = _cartItemRepository
.Query()
.Include(x => x.Product).ThenInclude(p => p.ThumbnailImage)
.Include(x => x.Product).ThenInclude(p => p.OptionCombinations).ThenInclude(o => o.Option)
.Where(x => x.CartId == cart.Id).ToList()
.Select(x => new CartItemVm(_currencyService)
{
Id = x.Id,
ProductId = x.ProductId,
ProductName = x.Product.Name,
ProductPrice = x.Product.Price,
ProductStockQuantity = x.Product.StockQuantity,
ProductStockTrackingIsEnabled = x.Product.StockTrackingIsEnabled,
IsProductAvailabeToOrder = x.Product.IsAllowToOrder && x.Product.IsPublished && !x.Product.IsDeleted,
ProductImage = _mediaService.GetThumbnailUrl(x.Product.ThumbnailImage),
Quantity = x.Quantity,
VariationOptions = CartItemVm.GetVariationOption(x.Product)
}).ToList();
cartVm.SubTotal = cartVm.Items.Sum(x => x.Quantity * x.ProductPrice);
if (!string.IsNullOrWhiteSpace(cartVm.CouponCode))
{
var cartInfoForCoupon = new CartInfoForCoupon
{
Items = cartVm.Items.Select(x => new CartItemForCoupon { ProductId = x.ProductId, Quantity = x.Quantity }).ToList()
};
var couponValidationResult = await _couponService.Validate(customerId, cartVm.CouponCode, cartInfoForCoupon);
if (couponValidationResult.Succeeded)
{
cartVm.Discount = couponValidationResult.DiscountAmount;
}
else
{
cartVm.CouponValidationErrorMessage = couponValidationResult.ErrorMessage;
}
}
return cartVm;
}