Open-source eCommerce platform for C# and ASP.NET Core 10 with MongoDB. Build multi-store shops and multi-vendor marketplaces with B2B/B2C, REST API, plugins, Vue 3 and Docker.
C# aspnet-corecsharpdockerdotnetecommerceecommerce-platformmongodbmulti-storemulti-vendornosqlonline-shopshoppingcart
Extend model OrderTotalsModel
KrzysztofPajak3dfd74592e97
diff --git a/src/Web/Grand.Web/Features/Handlers/ShoppingCart/GetOrderTotalsHandler.cs b/src/Web/Grand.Web/Features/Handlers/ShoppingCart/GetOrderTotalsHandler.csindex 0717ced10..106b30014 100644--- a/src/Web/Grand.Web/Features/Handlers/ShoppingCart/GetOrderTotalsHandler.cs+++ b/src/Web/Grand.Web/Features/Handlers/ShoppingCart/GetOrderTotalsHandler.cs@@ -79,9 +79,12 @@ namespace Grand.Web.Features.Handlers.ShoppingCartvar subTotalIncludingTax = request.TaxDisplayType == TaxDisplayType.IncludingTax && !_taxSettings.ForceTaxExclusionFromOrderSubtotal;var shoppingCartSubTotal = await _orderTotalCalculationService.GetShoppingCartSubTotal(request.Cart, subTotalIncludingTax);model.SubTotal = _priceFormatter.FormatPrice(shoppingCartSubTotal.subTotalWithoutDiscount, request.Currency, request.Language, subTotalIncludingTax);+ model.SubTotalValue = shoppingCartSubTotal.subTotalWithoutDiscount;if (shoppingCartSubTotal.discountAmount > 0){model.SubTotalDiscount = _priceFormatter.FormatPrice(-shoppingCartSubTotal.discountAmount, request.Currency, request.Language, subTotalIncludingTax);+ model.SubTotalDiscountValue = -shoppingCartSubTotal.discountAmount;+ shoppingCartSubTotal.appliedDiscounts.ForEach(x => model.Discounts.Add(x.DiscountId));}}@@ -90,7 +93,7 @@ namespace Grand.Web.Features.Handlers.ShoppingCartmodel.RequiresShipping = request.Cart.RequiresShipping();if (model.RequiresShipping){- double? shoppingCartShippingBase = (await _orderTotalCalculationService.GetShoppingCartShippingTotal(request.Cart)).shoppingCartShippingTotal;+ var shoppingCartShippingBase = (await _orderTotalCalculationService.GetShoppingCartShippingTotal(request.Cart)).shoppingCartShippingTotal;if (shoppingCartShippingBase.HasValue){model.Shipping = _priceFormatter.FormatShippingPrice(shoppingCartShippingBase.Value);@@ -108,18 +111,19 @@ namespace Grand.Web.Features.Handlers.ShoppingCart{var paymentMethodSystemName = request.Customer.GetUserFieldFromEntity<string>(SystemCustomerFieldNames.SelectedPaymentMethod, request.Store.Id);- double paymentMethodAdditionalFee = await _paymentService.GetAdditionalHandlingFee(request.Cart, paymentMethodSystemName);- double paymentMethodAdditionalFeeWithTaxBase = (await _taxService.GetPaymentMethodAdditionalFee(paymentMethodAdditionalFee, request.Customer)).paymentPrice;+ var paymentMethodAdditionalFee = await _paymentService.GetAdditionalHandlingFee(request.Cart, paymentMethodSystemName);+ var paymentMethodAdditionalFeeWithTaxBase = (await _taxService.GetPaymentMethodAdditionalFee(paymentMethodAdditionalFee, request.Customer)).paymentPrice;if (paymentMethodAdditionalFeeWithTaxBase > 0){model.PaymentMethodAdditionalFee = _priceFormatter.FormatPaymentMethodAdditionalFee(paymentMethodAdditionalFeeWithTaxBase);+ model.PaymentMethodAdditionalFeeValue = paymentMethodAdditionalFeeWithTaxBase;}}private async Task PrepareTax(OrderTotalsModel model, GetOrderTotals request){- bool displayTax = true;- bool displayTaxRates = true;+ bool displayTax;+ bool displayTaxRates;if (_taxSettings.HideTaxInOrderSummary && request.TaxDisplayType == TaxDisplayType.IncludingTax){displayTax = false;@@ -143,8 +147,7 @@ namespace Grand.Web.Features.Handlers.ShoppingCartmodel.Tax = _priceFormatter.FormatPrice(taxtotal.taxtotal, false);foreach (var tr in taxRates){- model.TaxRates.Add(new OrderTotalsModel.TaxRate- {+ model.TaxRates.Add(new OrderTotalsModel.TaxRate {Rate = _priceFormatter.FormatTaxRate(tr.Key),Value = _priceFormatter.FormatPrice(tr.Value, false),});@@ -158,19 +161,22 @@ namespace Grand.Web.Features.Handlers.ShoppingCartprivate async Task PrepareTotal(OrderTotalsModel model, GetOrderTotals request){var carttotal = await _orderTotalCalculationService.GetShoppingCartTotal(request.Cart);- double? shoppingCartTotalBase = carttotal.shoppingCartTotal;- double orderTotalDiscountAmountBase = carttotal.discountAmount;+ var shoppingCartTotalBase = carttotal.shoppingCartTotal;+ var orderTotalDiscountAmountBase = carttotal.discountAmount;List<AppliedGiftVoucher> appliedGiftVouchers = carttotal.appliedGiftVouchers;- int redeemedLoyaltyPoints = carttotal.redeemedLoyaltyPoints;- double redeemedLoyaltyPointsAmount = carttotal.redeemedLoyaltyPointsAmount;+ var redeemedLoyaltyPoints = carttotal.redeemedLoyaltyPoints;+ var redeemedLoyaltyPointsAmount = carttotal.redeemedLoyaltyPointsAmount;if (shoppingCartTotalBase.HasValue){model.OrderTotal = _priceFormatter.FormatPrice(shoppingCartTotalBase.Value, false);+ model.OrderTotalValue = shoppingCartTotalBase.Value;}//discountif (orderTotalDiscountAmountBase > 0){model.OrderTotalDiscount = _priceFormatter.FormatPrice(-orderTotalDiscountAmountBase, false);+ model.OrderTotalDiscountValue = -orderTotalDiscountAmountBase;+ carttotal.appliedDiscounts.ForEach(x => model.Discounts.Add(x.DiscountId));}//gift vouchers@@ -194,7 +200,7 @@ namespace Grand.Web.Features.Handlers.ShoppingCart_loyaltyPointsSettings.DisplayHowMuchWillBeEarned &&shoppingCartTotalBase.HasValue){- double? shippingBaseInclTax = model.RequiresShipping+ var shippingBaseInclTax = model.RequiresShipping? (await _orderTotalCalculationService.GetShoppingCartShippingTotal(request.Cart, true)).shoppingCartShippingTotal: 0;var earnLoyaltyPoints = shoppingCartTotalBase.Value - shippingBaseInclTax.Value;@@ -205,14 +211,13 @@ namespace Grand.Web.Features.Handlers.ShoppingCartprivate void PrepareGiftVouchers(AppliedGiftVoucher appliedGiftVoucher, OrderTotalsModel model, GetOrderTotals request){- var gcModel = new OrderTotalsModel.GiftVoucher- {+ var gcModel = new OrderTotalsModel.GiftVoucher {Id = appliedGiftVoucher.GiftVoucher.Id,CouponCode = appliedGiftVoucher.GiftVoucher.Code,};gcModel.Amount = _priceFormatter.FormatPrice(-appliedGiftVoucher.AmountCanBeUsed, false);- double remainingAmountBase = appliedGiftVoucher.GiftVoucher.GetGiftVoucherRemainingAmount() - appliedGiftVoucher.AmountCanBeUsed;+ var remainingAmountBase = appliedGiftVoucher.GiftVoucher.GetGiftVoucherRemainingAmount() - appliedGiftVoucher.AmountCanBeUsed;gcModel.Remaining = _priceFormatter.FormatPrice(remainingAmountBase, false);model.GiftVouchers.Add(gcModel);diff --git a/src/Web/Grand.Web/Features/Handlers/ShoppingCart/GetShoppingCartHandler.cs b/src/Web/Grand.Web/Features/Handlers/ShoppingCart/GetShoppingCartHandler.csindex 411442493..07bae6ca9 100644--- a/src/Web/Grand.Web/Features/Handlers/ShoppingCart/GetShoppingCartHandler.cs+++ b/src/Web/Grand.Web/Features/Handlers/ShoppingCart/GetShoppingCartHandler.cs@@ -425,10 +425,7 @@ namespace Grand.Web.Features.Handlers.ShoppingCartif (discount != null && discount.MaximumDiscountedQuantity.HasValue)cartItemModel.DiscountedQty = discount.MaximumDiscountedQuantity.Value;- foreach (var disc in appliedDiscounts)- {- cartItemModel.Discounts.Add(disc.DiscountId);- }+ appliedDiscounts.ForEach(x => cartItemModel.Discounts.Add(x.DiscountId));}//sub totalvar subtotal = await _pricingService.GetSubTotal(sci, product, true);diff --git a/src/Web/Grand.Web/Models/ShoppingCart/OrderTotalsModel.cs b/src/Web/Grand.Web/Models/ShoppingCart/OrderTotalsModel.csindex 43bbb2af8..b14b9797f 100644--- a/src/Web/Grand.Web/Models/ShoppingCart/OrderTotalsModel.cs+++ b/src/Web/Grand.Web/Models/ShoppingCart/OrderTotalsModel.cs@@ -8,18 +8,22 @@ namespace Grand.Web.Models.ShoppingCart{TaxRates = new List<TaxRate>();GiftVouchers = new List<GiftVoucher>();+ Discounts = new HashSet<string>();}public bool IsEditable { get; set; }public string SubTotal { get; set; }+ public double SubTotalValue { get; set; }public string SubTotalDiscount { get; set; }+ public double SubTotalDiscountValue { get; set; }public string Shipping { get; set; }public bool RequiresShipping { get; set; }public string SelectedShippingMethod { get; set; }public string PaymentMethodAdditionalFee { get; set; }+ public double PaymentMethodAdditionalFeeValue { get; set; }public string Tax { get; set; }public IList<TaxRate> TaxRates { get; set; }@@ -30,12 +34,17 @@ namespace Grand.Web.Models.ShoppingCartpublic IList<GiftVoucher> GiftVouchers { get; set; }public string OrderTotalDiscount { get; set; }+ public double OrderTotalDiscountValue { get; set; }+public int RedeemedLoyaltyPoints { get; set; }public string RedeemedLoyaltyPointsAmount { get; set; }public int WillEarnLoyaltyPoints { get; set; }public string OrderTotal { get; set; }+ public double OrderTotalValue { get; set; }++ public HashSet<string> Discounts { get; set; }#region Nested classesdiff --git a/src/Web/Grand.Web/Models/ShoppingCart/ShoppingCartModel.cs b/src/Web/Grand.Web/Models/ShoppingCart/ShoppingCartModel.csindex d37a12a02..03874db7b 100644--- a/src/Web/Grand.Web/Models/ShoppingCart/ShoppingCartModel.cs+++ b/src/Web/Grand.Web/Models/ShoppingCart/ShoppingCartModel.cs@@ -41,7 +41,7 @@ namespace Grand.Web.Models.ShoppingCart{Picture = new PictureModel();AllowedQuantities = new List<SelectListItem>();- Discounts = new List<string>();+ Discounts = new HashSet<string>();Warnings = new List<string>();}public string Sku { get; set; }@@ -64,7 +64,7 @@ namespace Grand.Web.Models.ShoppingCartpublic double SubTotalValue { get; set; }public string Discount { get; set; }public int DiscountedQty { get; set; }- public List<string> Discounts { get; set; }+ public HashSet<string> Discounts { get; set; }public int Quantity { get; set; }public List<SelectListItem> AllowedQuantities { get; set; }public string AttributeInfo { get; set; }