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
Minor code improvements
support6cef3d85f3f5
diff --git a/src/API/Grand.Api/Controllers/OData/CustomerGroupController.cs b/src/API/Grand.Api/Controllers/OData/CustomerGroupController.csindex 1d25f55f1..b9094a388 100644--- a/src/API/Grand.Api/Controllers/OData/CustomerGroupController.cs+++ b/src/API/Grand.Api/Controllers/OData/CustomerGroupController.cs@@ -100,7 +100,7 @@ namespace Grand.Api.Controllers.ODatavar cr = customerGroup.FirstOrDefault();model.ApplyTo(cr);- if (!cr.IsSystem)+ if (cr is { IsSystem: false }){await _mediator.Send(new UpdateCustomerGroupCommand { Model = cr });return Ok();diff --git a/src/Business/Grand.Business.Messages/Services/MessageProviderService.cs b/src/Business/Grand.Business.Messages/Services/MessageProviderService.csindex f1b042c32..22035c901 100644--- a/src/Business/Grand.Business.Messages/Services/MessageProviderService.cs+++ b/src/Business/Grand.Business.Messages/Services/MessageProviderService.cs@@ -1852,7 +1852,7 @@ namespace Grand.Business.Messages.Serviceselse{var store = (await _storeService.GetAllStores()).FirstOrDefault();- var language = await EnsureLanguageIsActive(languageId, store.Id);+ var language = await EnsureLanguageIsActive(languageId, store?.Id);messageTemplate = await GetMessageTemplate("AuctionExpired.StoreOwnerNotification", "");if (messageTemplate == null)return 0;diff --git a/src/Core/Grand.Domain/Catalog/ProductExtensions.cs b/src/Core/Grand.Domain/Catalog/ProductExtensions.csindex 052326f4a..9e271a4fa 100644--- a/src/Core/Grand.Domain/Catalog/ProductExtensions.cs+++ b/src/Core/Grand.Domain/Catalog/ProductExtensions.cs@@ -367,7 +367,6 @@ namespace Grand.Domain.Catalog/// Generate all combinations/// </summary>/// <param name="product">Product</param>- /// <param name="ignoreNonCombinableAttributes">A value indicating whether we should ignore non-combinable attributes</param>/// <returns>Attribute combinations</returns>public static IList<IEnumerable<CustomAttribute>> GenerateAllCombinations(this Product product){diff --git a/src/Web/Grand.Web.Admin/Controllers/TaxController.cs b/src/Web/Grand.Web.Admin/Controllers/TaxController.csindex f1a4aa450..106d05191 100644--- a/src/Web/Grand.Web.Admin/Controllers/TaxController.cs+++ b/src/Web/Grand.Web.Admin/Controllers/TaxController.cs@@ -157,7 +157,7 @@ namespace Grand.Web.Admin.Controllersmodel.DefaultTaxAddress.AvailableCountries.Add(new SelectListItem { Text = c.Name, Value = c.Id, Selected = defaultAddress != null && c.Id == defaultAddress.CountryId });var states = defaultAddress != null && !string.IsNullOrEmpty(defaultAddress.CountryId) ? (await _countryService.GetCountryById(defaultAddress.CountryId))?.StateProvinces : new List<StateProvince>();- if (states.Count > 0)+ if (states?.Count > 0){foreach (var s in states)model.DefaultTaxAddress.AvailableStates.Add(new SelectListItem { Text = s.Name, Value = s.Id, Selected = s.Id == defaultAddress.StateProvinceId });diff --git a/src/Web/Grand.Web/Controllers/CommonController.cs b/src/Web/Grand.Web/Controllers/CommonController.csindex e0d08e166..365ad5bed 100644--- a/src/Web/Grand.Web/Controllers/CommonController.cs+++ b/src/Web/Grand.Web/Controllers/CommonController.cs@@ -93,7 +93,7 @@ namespace Grand.Web.Controllers}//add language code- return $"/{language.UniqueSeoCode}/{url.TrimStart('/')}";+ return $"/{language.UniqueSeoCode}/{url?.TrimStart('/')}";}#endregiondiff --git a/src/Web/Grand.Web/Controllers/ShoppingCartController.cs b/src/Web/Grand.Web/Controllers/ShoppingCartController.csindex 5104b11e0..74b1fa76d 100644--- a/src/Web/Grand.Web/Controllers/ShoppingCartController.cs+++ b/src/Web/Grand.Web/Controllers/ShoppingCartController.cs@@ -98,6 +98,7 @@ namespace Grand.Web.Controllers#endregion#region Shopping cart+[HttpGet][ProducesResponseType(typeof(MiniShoppingCartModel), StatusCodes.Status200OK)]public async Task<IActionResult> SidebarShoppingCart()@@ -182,6 +183,7 @@ namespace Grand.Web.ControllersdownloadGuid = Guid.Empty});}+var form = await HttpContext.Request.ReadFormAsync();var httpPostedFile = form.Files.FirstOrDefault();if (httpPostedFile == null)@@ -259,7 +261,7 @@ namespace Grand.Web.ControllersdownloadGuid = download.DownloadGuid});}-+[HttpGet]//[ProducesResponseType(typeof(ShoppingCartModel), StatusCodes.Status200OK)]public virtual async Task<IActionResult> Cart(bool checkoutAttributes)@@ -279,7 +281,7 @@ namespace Grand.Web.Controllers});return View(model);}-+[HttpGet][DenySystemAccount][ProducesResponseType(typeof(ShoppingCartModel), StatusCodes.Status200OK)]@@ -300,7 +302,7 @@ namespace Grand.Web.Controllersreturn Json(model);}-+[HttpGet][DenySystemAccount][ProducesResponseType(typeof(OrderTotalsModel), StatusCodes.Status200OK)]@@ -319,7 +321,7 @@ namespace Grand.Web.Controllers});return Json(model);}-+[AutoValidateAntiforgeryToken][DenySystemAccount]@@ -332,17 +334,20 @@ namespace Grand.Web.Controllerssuccess = false,warnings = string.Join(',', ModelState.Values.SelectMany(x => x.Errors.Select(x => x.ErrorMessage)))});-}-+var cart = (await _shoppingCartService.GetShoppingCart(_workContext.CurrentStore.Id, PrepareCartTypes())).FirstOrDefault(x => x.Id == model.ShoppingCartId);var warnings = new List<string>();- var currSciWarnings = await _shoppingCartService.UpdateShoppingCartItem(_workContext.CurrentCustomer,- cart.Id, cart.WarehouseId, cart.Attributes, cart.EnteredPrice,- cart.RentalStartDateUtc, cart.RentalEndDateUtc,- model.Quantity);- warnings.AddRange(currSciWarnings);++ if (cart != null)+ {+ var currSciWarnings = await _shoppingCartService.UpdateShoppingCartItem(_workContext.CurrentCustomer,+ cart.Id, cart.WarehouseId, cart.Attributes, cart.EnteredPrice,+ cart.RentalStartDateUtc, cart.RentalEndDateUtc,+ model.Quantity);+ warnings.AddRange(currSciWarnings);+ }var cartModel = await _mediator.Send(new GetShoppingCart {Cart = await _shoppingCartService.GetShoppingCart(_workContext.CurrentStore.Id, PrepareCartTypes()),@@ -361,7 +366,7 @@ namespace Grand.Web.Controllersmodel = cartModel});}-+[HttpGet][DenySystemAccount]public virtual async Task<IActionResult> ClearCart()@@ -482,7 +487,7 @@ namespace Grand.Web.Controllerssidebarshoppingcartmodel = miniShoppingCart});}-+[IgnoreApi][HttpGet]public virtual IActionResult ContinueShopping()@@ -495,7 +500,7 @@ namespace Grand.Web.Controllersreturn RedirectToRoute("HomePage");}-+[HttpPost][DenySystemAccount]public virtual async Task<IActionResult> StartCheckout(CheckoutAttributeSelectedModel model)@@ -582,7 +587,6 @@ namespace Grand.Web.Controllers[HttpPost]public virtual async Task<IActionResult> ApplyGiftVoucher(GiftVoucherCouponModel model){-var cart = await _shoppingCartService.GetShoppingCart(_workContext.CurrentStore.Id, PrepareCartTypes());var message = string.Empty;@@ -713,6 +717,7 @@ namespace Grand.Web.Controllersmodel});}+#endregion}}\ No newline at end of filediff --git a/src/Web/Grand.Web/Controllers/WishlistController.cs b/src/Web/Grand.Web/Controllers/WishlistController.csindex 3775ad4ef..ecb4f226d 100644--- a/src/Web/Grand.Web/Controllers/WishlistController.cs+++ b/src/Web/Grand.Web/Controllers/WishlistController.cs@@ -121,12 +121,15 @@ namespace Grand.Web.Controllersif (ModelState.IsValid){var cart = (await _shoppingCartService.GetShoppingCart(_workContext.CurrentStore.Id, ShoppingCartType.Wishlist)).FirstOrDefault(x => x.Id == model.ShoppingCartId);-- var currSciWarnings = await _shoppingCartService.UpdateShoppingCartItem(_workContext.CurrentCustomer,- cart.Id, cart.WarehouseId, cart.Attributes, cart.EnteredPrice,- cart.RentalStartDateUtc, cart.RentalEndDateUtc,- model.Quantity);- warnings.AddRange(currSciWarnings);+ if (cart != null)+ {+ var currSciWarnings = await _shoppingCartService.UpdateShoppingCartItem(+ _workContext.CurrentCustomer,+ cart.Id, cart.WarehouseId, cart.Attributes, cart.EnteredPrice,+ cart.RentalStartDateUtc, cart.RentalEndDateUtc,+ model.Quantity);+ warnings.AddRange(currSciWarnings);+ }}else{diff --git a/src/Web/Grand.Web/Features/Handlers/Catalog/GetCompareProductsHandler.cs b/src/Web/Grand.Web/Features/Handlers/Catalog/GetCompareProductsHandler.csindex cabd8a9a4..cffc0b7d7 100644--- a/src/Web/Grand.Web/Features/Handlers/Catalog/GetCompareProductsHandler.cs+++ b/src/Web/Grand.Web/Features/Handlers/Catalog/GetCompareProductsHandler.cs@@ -69,7 +69,7 @@ namespace Grand.Web.Features.Handlers.Catalogprotected virtual List<string> GetComparedProductIds(){//try to get cookie- if (!_httpContextAccessor.HttpContext.Request.Cookies.TryGetValue(CacheKey.PRODUCTS_COMPARE_COOKIE_NAME, out var productIdsCookie) || string.IsNullOrEmpty(productIdsCookie))+ if (!_httpContextAccessor.HttpContext!.Request.Cookies.TryGetValue(CacheKey.PRODUCTS_COMPARE_COOKIE_NAME, out var productIdsCookie) || string.IsNullOrEmpty(productIdsCookie))return new List<string>();//get array of string product identifiers from cookiediff --git a/src/Web/Grand.Web/Features/Handlers/Orders/GetMerchandiseReturnDetailsHandler.cs b/src/Web/Grand.Web/Features/Handlers/Orders/GetMerchandiseReturnDetailsHandler.csindex 65754451b..ac6d97f75 100644--- a/src/Web/Grand.Web/Features/Handlers/Orders/GetMerchandiseReturnDetailsHandler.cs+++ b/src/Web/Grand.Web/Features/Handlers/Orders/GetMerchandiseReturnDetailsHandler.cs@@ -63,6 +63,9 @@ namespace Grand.Web.Features.Handlers.Ordersforeach (var item in request.MerchandiseReturn.MerchandiseReturnItems){var orderItem = request.Order.OrderItems.FirstOrDefault(x => x.Id == item.OrderItemId);+ if (orderItem == null)+ continue;+var product = await _productService.GetProductByIdIncludeArch(orderItem.ProductId);var unitPrice = _priceFormatter.FormatPrice(request.Order.CustomerTaxDisplayTypeId == TaxDisplayType.IncludingTax ?diff --git a/src/Web/Grand.Web/Views/Product/Partials/Pictures.cshtml b/src/Web/Grand.Web/Views/Product/Partials/Pictures.cshtmlindex 603b82e94..a4916d3bd 100644--- a/src/Web/Grand.Web/Views/Product/Partials/Pictures.cshtml+++ b/src/Web/Grand.Web/Views/Product/Partials/Pictures.cshtml@@ -5,7 +5,7 @@@if (Model.PictureModels.Any()){var schemaPicture = Model.PictureModels.FirstOrDefault();- <img src="@schemaPicture.FullSizeImageUrl" class="d-none" itemprop="image">+ <img src="@schemaPicture?.FullSizeImageUrl" class="d-none" itemprop="image">}@if (Model.PictureModels.Count == 1) { @if (Model.DefaultPictureZoomEnabled) {<gallery-images></gallery-images>