Skip to content

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.

Improvements/code (#587)

Krzysztof Pajakdc374ff81eb6
diff --git a/src/Business/Grand.Business.Catalog/Events/Handlers/UpdateProductOnCartEventHandler.cs b/src/Business/Grand.Business.Catalog/Events/Handlers/UpdateProductOnCartEventHandler.cs
index 35c1d67bc..f671049b6 100644
--- a/src/Business/Grand.Business.Catalog/Events/Handlers/UpdateProductOnCartEventHandler.cs
+++ b/src/Business/Grand.Business.Catalog/Events/Handlers/UpdateProductOnCartEventHandler.cs
@@ -18,15 +18,15 @@ public class UpdateProductOnCartEventHandler : INotificationHandler<UpdateProduc
{
var customers = _customerRepository.Table
.Where(x => x.ShoppingCartItems.Any(y => y.ProductId == notification.Product.Id)).ToList();
- foreach (var cs in customers)
- foreach (var item in cs.ShoppingCartItems.Where(x => x.ProductId == notification.Product.Id))
+ foreach (var (cs, item) in from cs in customers
+ from item in cs.ShoppingCartItems.Where(x => x.ProductId == notification.Product.Id)
+ select (cs, item))
{
item.AdditionalShippingChargeProduct = notification.Product.AdditionalShippingCharge;
item.IsFreeShipping = notification.Product.IsFreeShipping;
item.IsGiftVoucher = notification.Product.IsGiftVoucher;
item.IsShipEnabled = notification.Product.IsShipEnabled;
item.IsTaxExempt = notification.Product.IsTaxExempt;
-
await _customerRepository.UpdateToSet(cs.Id, x => x.ShoppingCartItems, z => z.Id, item.Id, item);
}
}
diff --git a/src/Business/Grand.Business.Catalog/Services/Categories/CategoryService.cs b/src/Business/Grand.Business.Catalog/Services/Categories/CategoryService.cs
index 8b3eb3064..2c3eed6d4 100644
--- a/src/Business/Grand.Business.Catalog/Services/Categories/CategoryService.cs
+++ b/src/Business/Grand.Business.Catalog/Services/Categories/CategoryService.cs
@@ -402,6 +402,8 @@ public class CategoryService : ICategoryService
public virtual async Task InsertCategory(Category category)
{
ArgumentNullException.ThrowIfNull(category);
+ if (string.IsNullOrEmpty(category.ParentCategoryId))
+ category.ParentCategoryId = "";
await _categoryRepository.InsertAsync(category);
diff --git a/src/Business/Grand.Business.Checkout/Services/Orders/OrderReportService.cs b/src/Business/Grand.Business.Checkout/Services/Orders/OrderReportService.cs
index 32e41653d..4278f4bc9 100644
--- a/src/Business/Grand.Business.Checkout/Services/Orders/OrderReportService.cs
+++ b/src/Business/Grand.Business.Checkout/Services/Orders/OrderReportService.cs
@@ -60,9 +60,8 @@ public class OrderReportService : IOrderReportService
/// <param name="startTimeUtc">Start date</param>
/// <param name="endTimeUtc">End date</param>
/// <returns>Result</returns>
- public virtual async Task<IList<OrderByCountryReportLine>> GetCountryReport(string storeId, string vendorId,
- int? os,
- PaymentStatus? ps, ShippingStatus? ss, DateTime? startTimeUtc, DateTime? endTimeUtc)
+ public virtual async Task<IList<OrderByCountryReportLine>> GetCountryReport(string storeId = "", string vendorId = "",
+ int? os = null, PaymentStatus? ps = null, ShippingStatus? ss = null, DateTime? startTimeUtc = null, DateTime? endTimeUtc = null)
{
var query = from p in _orderRepository.Table
select p;
diff --git a/src/Business/Grand.Business.Checkout/Services/Orders/ShoppingCartService.cs b/src/Business/Grand.Business.Checkout/Services/Orders/ShoppingCartService.cs
index ea2cf5cae..df1047e02 100644
--- a/src/Business/Grand.Business.Checkout/Services/Orders/ShoppingCartService.cs
+++ b/src/Business/Grand.Business.Checkout/Services/Orders/ShoppingCartService.cs
@@ -8,7 +8,6 @@ using Grand.Domain.Catalog;
using Grand.Domain.Common;
using Grand.Domain.Customers;
using Grand.Domain.Orders;
-using Grand.Domain.Payments;
using Grand.Infrastructure;
using Grand.Infrastructure.Extensions;
using MediatR;
@@ -314,7 +313,7 @@ public class ShoppingCartService : IShoppingCartService
/// <returns>Warnings</returns>
public virtual async Task<IList<string>> UpdateShoppingCartItem(Customer customer,
string shoppingCartItemId, string warehouseId, IList<CustomAttribute> attributes,
- double? customerEnteredPrice,
+ double? customerEnteredPrice = null,
DateTime? rentalStartDate = null, DateTime? rentalEndDate = null,
int quantity = 1, bool resetCheckoutData = true, string reservationId = "", string sciId = "")
{
diff --git a/src/Business/Grand.Business.Core/Interfaces/Customers/ICustomerService.cs b/src/Business/Grand.Business.Core/Interfaces/Customers/ICustomerService.cs
index 0a07b9087..407308a40 100644
--- a/src/Business/Grand.Business.Core/Interfaces/Customers/ICustomerService.cs
+++ b/src/Business/Grand.Business.Core/Interfaces/Customers/ICustomerService.cs
@@ -128,7 +128,7 @@ public interface ICustomerService
/// Insert a guest customer
/// </summary>
/// <returns>Customer</returns>
- Task<Customer> InsertGuestCustomer(Customer customer = null);
+ Task<Customer> InsertGuestCustomer(Customer customer);
/// <summary>
/// Insert a customer
diff --git a/src/Core/Grand.Infrastructure/Caching/Constants/CommonCacheKey.cs b/src/Core/Grand.Infrastructure/Caching/Constants/CommonCacheKey.cs
index d0e319fee..7cdd207cd 100644
--- a/src/Core/Grand.Infrastructure/Caching/Constants/CommonCacheKey.cs
+++ b/src/Core/Grand.Infrastructure/Caching/Constants/CommonCacheKey.cs
@@ -136,7 +136,7 @@ public static partial class CacheKey
/// <summary>
/// Key pattern to clear cache
/// </summary>
- public static string URLEntity_PATTERN_KEY = "Grand.urlEntity.";
+ public const string URLEntity_PATTERN_KEY = "Grand.urlEntity.";
#endregion
diff --git a/src/Core/Grand.Infrastructure/GrandVersion.cs b/src/Core/Grand.Infrastructure/GrandVersion.cs
index e4895c17f..deef8dd2c 100644
--- a/src/Core/Grand.Infrastructure/GrandVersion.cs
+++ b/src/Core/Grand.Infrastructure/GrandVersion.cs
@@ -33,12 +33,12 @@ public static class GrandVersion
/// <summary>
/// Gets the git branch
/// </summary>
- public static string GitBranch = GetGitBranch();
+ public static readonly string GitBranch = GetGitBranch();
/// <summary>
/// Gets the git commit
/// </summary>
- public static string GitCommit = GetGitHash();
+ public static readonly string GitCommit = GetGitHash();
/// <summary>
/// Gets the patch version
diff --git a/src/Core/Grand.Infrastructure/Models/BaseModel.cs b/src/Core/Grand.Infrastructure/Models/BaseModel.cs
index c748ad93e..b21a10cdf 100644
--- a/src/Core/Grand.Infrastructure/Models/BaseModel.cs
+++ b/src/Core/Grand.Infrastructure/Models/BaseModel.cs
@@ -12,8 +12,7 @@ public class BaseModel
public BaseModel()
{
- UserFields = new List<UserField>();
- PostInitialize();
+ UserFields = [];
}
#endregion
@@ -29,10 +28,5 @@ public class BaseModel
public virtual void BindModel(ModelBindingContext bindingContext)
{
}
-
- protected virtual void PostInitialize()
- {
- }
-
#endregion
}
\ No newline at end of file
diff --git a/src/Core/Grand.SharedKernel/Extensions/CommonPath.cs b/src/Core/Grand.SharedKernel/Extensions/CommonPath.cs
index f50cfb3a2..7e45dd892 100644
--- a/src/Core/Grand.SharedKernel/Extensions/CommonPath.cs
+++ b/src/Core/Grand.SharedKernel/Extensions/CommonPath.cs
@@ -2,15 +2,15 @@
public static class CommonPath
{
- public static string AppData => "App_Data";
+ public const string AppData = "App_Data";
- public static string Plugins => "Plugins";
+ public const string Plugins = "Plugins";
- public static string TmpUploadPath = "TempUploads";
+ public const string TmpUploadPath = "TempUploads";
- public static string DirectoryParam = "Directory";
+ public const string DirectoryParam = "Directory";
- public static string SettingsFile = "Settings.cfg";
+ public const string SettingsFile = "Settings.cfg";
- public static string InstalledPluginsFile = "InstalledPlugins.cfg";
+ public const string InstalledPluginsFile = "InstalledPlugins.cfg";
}
\ No newline at end of file
diff --git a/src/Plugins/Widgets.FacebookPixel/FacebookPixelDefaults.cs b/src/Plugins/Widgets.FacebookPixel/FacebookPixelDefaults.cs
index 304659ade..7bc094c03 100644
--- a/src/Plugins/Widgets.FacebookPixel/FacebookPixelDefaults.cs
+++ b/src/Plugins/Widgets.FacebookPixel/FacebookPixelDefaults.cs
@@ -5,7 +5,7 @@ public static class FacebookPixelDefaults
public const string ProviderSystemName = "Widgets.FacebookPixel";
public const string FriendlyName = "Widgets.FacebookPixel.FriendlyName";
public const string ConfigurationUrl = "../WidgetsFacebookPixel/Configure";
- public static string ConsentCookieSystemName = "FacebookPixel";
+ public const string ConsentCookieSystemName = "FacebookPixel";
public static string Page => "head_html_tag";
public static string AddToCart => "popup_add_to_cart_content_before";
diff --git a/src/Plugins/Widgets.GoogleAnalytics/GoogleAnalyticDefaults.cs b/src/Plugins/Widgets.GoogleAnalytics/GoogleAnalyticDefaults.cs
index 2586aa0e1..fe337e1b2 100644
--- a/src/Plugins/Widgets.GoogleAnalytics/GoogleAnalyticDefaults.cs
+++ b/src/Plugins/Widgets.GoogleAnalytics/GoogleAnalyticDefaults.cs
@@ -5,5 +5,5 @@ public static class GoogleAnalyticDefaults
public const string ProviderSystemName = "Widgets.GoogleAnalytics";
public const string FriendlyName = "Widgets.GoogleAnalytics.FriendlyName";
public const string ConfigurationUrl = "../WidgetsGoogleAnalytics/Configure";
- public static string ConsentCookieSystemName = "GoogleAnalytics";
+ public const string ConsentCookieSystemName = "GoogleAnalytics";
}
\ No newline at end of file
diff --git a/src/Web/Grand.Web.Common/Page/PageHeadBuilder.cs b/src/Web/Grand.Web.Common/Page/PageHeadBuilder.cs
index 6d8ccf321..7259ef4b4 100644
--- a/src/Web/Grand.Web.Common/Page/PageHeadBuilder.cs
+++ b/src/Web/Grand.Web.Common/Page/PageHeadBuilder.cs
@@ -15,15 +15,14 @@ public class PageHeadBuilder : IPageHeadBuilder
/// <param name="seoSettings">SEO settings</param>
public PageHeadBuilder(SeoSettings seoSettings)
{
- _title = new List<string>();
- _metaDescription = new List<string>();
- _metaKeyword = new List<string>();
- _canonicalUrl = new List<string>();
- _headCustom = new List<string>();
- _pageCssClass = new List<string>();
-
- if (!string.IsNullOrEmpty(seoSettings.CustomHeadTags)) AppendHeadCustomParts(seoSettings.CustomHeadTags);
+ _title = [];
+ _metaDescription = [];
+ _metaKeyword = [];
+ _canonicalUrl = [];
+ _headCustom = [];
+ _pageCssClass = [];
_seoSettings = seoSettings;
+ ConfigureHeadParts();
}
#endregion
@@ -43,6 +42,14 @@ public class PageHeadBuilder : IPageHeadBuilder
#region Methods
+ private void ConfigureHeadParts()
+ {
+ if (!string.IsNullOrEmpty(_seoSettings.CustomHeadTags))
+ {
+ AppendHeadCustomParts(_seoSettings.CustomHeadTags);
+ }
+ }
+
public virtual void AddTitleParts(string part)
{
if (string.IsNullOrEmpty(part))