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.

Changes with LastVisitedPage property from Customer

support3df57d98e30e
diff --git a/src/Core/Grand.Domain/Customers/Customer.cs b/src/Core/Grand.Domain/Customers/Customer.cs
index 7dba6def2..8379d352c 100644
--- a/src/Core/Grand.Domain/Customers/Customer.cs
+++ b/src/Core/Grand.Domain/Customers/Customer.cs
@@ -143,6 +143,11 @@ public class Customer : BaseEntity
/// </summary>
public string LastIpAddress { get; set; }
+ /// <summary>
+ /// Gets or sets the last visited page
+ /// </summary>
+ public string LastVisitedPage { get; set; }
+
/// <summary>
/// Gets or sets the date and time of last login
/// </summary>
diff --git a/src/Core/Grand.Domain/Customers/SystemCustomerFieldNames.cs b/src/Core/Grand.Domain/Customers/SystemCustomerFieldNames.cs
index 7cc94734c..cd8decfc6 100644
--- a/src/Core/Grand.Domain/Customers/SystemCustomerFieldNames.cs
+++ b/src/Core/Grand.Domain/Customers/SystemCustomerFieldNames.cs
@@ -26,7 +26,6 @@ public static class SystemCustomerFieldNames
public static string PasswordRecoveryToken => "PasswordRecoveryToken";
public static string PasswordRecoveryTokenDateGenerated => "PasswordRecoveryTokenDateGenerated";
public static string AccountActivationToken => "AccountActivationToken";
- public static string LastVisitedPage => "LastVisitedPage";
public static string ImpersonatedCustomerId => "ImpersonatedCustomerId";
public static string AdminAreaStoreScopeConfiguration => "AdminAreaStoreScopeConfiguration";
public static string TwoFactorEnabled => "TwoFactorEnabled";
diff --git a/src/Web/Grand.Web.Admin/Controllers/OnlineCustomerController.cs b/src/Web/Grand.Web.Admin/Controllers/OnlineCustomerController.cs
index 95cf49aac..ef775c3e1 100644
--- a/src/Web/Grand.Web.Admin/Controllers/OnlineCustomerController.cs
+++ b/src/Web/Grand.Web.Admin/Controllers/OnlineCustomerController.cs
@@ -65,16 +65,11 @@ public class OnlineCustomerController : BaseAdminController
{
var item = new OnlineCustomerModel {
Id = x.Id,
- CustomerInfo = !string.IsNullOrEmpty(x.Email)
- ? x.Email
- : _translationService.GetResource("Admin.Customers.Guest"),
+ CustomerInfo = !string.IsNullOrEmpty(x.Email) ? x.Email : _translationService.GetResource("Admin.Customers.Guest"),
LastIpAddress = x.LastIpAddress,
Location = _geoLookupService.CountryName(x.LastIpAddress),
LastActivityDate = _dateTimeService.ConvertToUserTime(x.LastActivityDateUtc, DateTimeKind.Utc),
- LastVisitedPage = _customerSettings.StoreLastVisitedPage
- ? x.GetUserFieldFromEntity<string>(SystemCustomerFieldNames.LastVisitedPage)
- : _translationService.GetResource(
- "Admin.Dashboards.OnlineCustomers.Fields.LastVisitedPage.Disabled")
+ LastVisitedPage = _customerSettings.StoreLastVisitedPage ? x.LastVisitedPage : _translationService.GetResource("Admin.Dashboards.OnlineCustomers.Fields.LastVisitedPage.Disabled")
};
items.Add(item);
}
diff --git a/src/Web/Grand.Web.Admin/Services/CustomerViewModelService.cs b/src/Web/Grand.Web.Admin/Services/CustomerViewModelService.cs
index 327054583..91c31cb81 100644
--- a/src/Web/Grand.Web.Admin/Services/CustomerViewModelService.cs
+++ b/src/Web/Grand.Web.Admin/Services/CustomerViewModelService.cs
@@ -225,7 +225,7 @@ public class CustomerViewModelService : ICustomerViewModelService
model.LastPurchaseDate =
_dateTimeService.ConvertToUserTime(customer.LastPurchaseDateUtc.Value, DateTimeKind.Utc);
model.LastIpAddress = customer.LastIpAddress;
- model.LastVisitedPage = customer.GetUserFieldFromEntity<string>(SystemCustomerFieldNames.LastVisitedPage);
+ model.LastVisitedPage = customer.LastVisitedPage;
model.CustomerGroups = customer.Groups.ToArray();
//newsletter subscriptions
diff --git a/src/Web/Grand.Web.Common/Filters/CustomerActivityAttribute.cs b/src/Web/Grand.Web.Common/Filters/CustomerActivityAttribute.cs
index 95e26e9b4..9e682858e 100644
--- a/src/Web/Grand.Web.Common/Filters/CustomerActivityAttribute.cs
+++ b/src/Web/Grand.Web.Common/Filters/CustomerActivityAttribute.cs
@@ -1,8 +1,5 @@
-using Grand.Business.Core.Extensions;
-using Grand.Business.Core.Interfaces.Common.Directory;
-using Grand.Business.Core.Interfaces.Customers;
+using Grand.Business.Core.Interfaces.Customers;
using Grand.Data;
-using Grand.Domain.Common;
using Grand.Domain.Customers;
using Grand.Infrastructure;
using Microsoft.AspNetCore.Http;
@@ -36,12 +33,10 @@ public class CustomerActivityAttribute : TypeFilterAttribute
public CustomerActivityFilter(
ICustomerService customerService,
IWorkContext workContext,
- IUserFieldService userFieldService,
CustomerSettings customerSettings)
{
_customerService = customerService;
_workContext = workContext;
- _userFieldService = userFieldService;
_customerSettings = customerSettings;
}
@@ -92,14 +87,12 @@ public class CustomerActivityAttribute : TypeFilterAttribute
if (string.IsNullOrEmpty(pageUrl))
return;
- //get previous last page
- var previousPageUrl =
- _workContext.CurrentCustomer.GetUserFieldFromEntity<string>(SystemCustomerFieldNames.LastVisitedPage);
-
//save new one if don't match
- if (!pageUrl.Equals(previousPageUrl, StringComparison.OrdinalIgnoreCase))
- await _userFieldService.SaveField(_workContext.CurrentCustomer,
- SystemCustomerFieldNames.LastVisitedPage, pageUrl);
+ if (!pageUrl.Equals(_workContext.CurrentCustomer.LastVisitedPage, StringComparison.OrdinalIgnoreCase))
+ {
+ _workContext.CurrentCustomer.LastVisitedPage = pageUrl;
+ await _customerService.UpdateCustomerField(_workContext.CurrentCustomer, x => x.LastVisitedPage, pageUrl);
+ }
}
#endregion
@@ -108,7 +101,6 @@ public class CustomerActivityAttribute : TypeFilterAttribute
private readonly ICustomerService _customerService;
private readonly IWorkContext _workContext;
- private readonly IUserFieldService _userFieldService;
private readonly CustomerSettings _customerSettings;
#endregion