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 (#574)

Krzysztof Pajakd69faea8a012
diff --git a/src/Business/Grand.Business.Authentication/Services/ExternalAuthenticationService.cs b/src/Business/Grand.Business.Authentication/Services/ExternalAuthenticationService.cs
index ecb0fa610..c7043a835 100644
--- a/src/Business/Grand.Business.Authentication/Services/ExternalAuthenticationService.cs
+++ b/src/Business/Grand.Business.Authentication/Services/ExternalAuthenticationService.cs
@@ -31,7 +31,7 @@ public class ExternalAuthenticationService : IExternalAuthenticationService
IGroupService groupService,
IMediator mediator,
IRepository<ExternalAuthentication> externalAuthenticationRecordRepository,
- IWorkContextAccessor workContextAccessor,
+ IContextAccessor contextAccessor,
IEnumerable<IExternalAuthenticationProvider> externalAuthenticationProviders,
CustomerSettings customerSettings,
ExternalAuthenticationSettings externalAuthenticationSettings)
@@ -44,7 +44,7 @@ public class ExternalAuthenticationService : IExternalAuthenticationService
_groupService = groupService;
_mediator = mediator;
_externalAuthenticationRecordRepository = externalAuthenticationRecordRepository;
- _workContextAccessor = workContextAccessor;
+ _contextAccessor = contextAccessor;
_externalAuthenticationProviders = externalAuthenticationProviders;
}
@@ -58,7 +58,7 @@ public class ExternalAuthenticationService : IExternalAuthenticationService
private readonly IGroupService _groupService;
private readonly IMediator _mediator;
private readonly IRepository<ExternalAuthentication> _externalAuthenticationRecordRepository;
- private readonly IWorkContextAccessor _workContextAccessor;
+ private readonly IContextAccessor _contextAccessor;
private readonly IEnumerable<IExternalAuthenticationProvider> _externalAuthenticationProviders;
private readonly CustomerSettings _customerSettings;
private readonly ExternalAuthenticationSettings _externalAuthenticationSettings;
@@ -130,24 +130,24 @@ public class ExternalAuthenticationService : IExternalAuthenticationService
or UserRegistrationType.EmailValidation;
//create registration request
- var registrationRequest = new RegistrationRequest(_workContextAccessor.WorkContext.CurrentCustomer,
+ var registrationRequest = new RegistrationRequest(_contextAccessor.WorkContext.CurrentCustomer,
parameters.Email, parameters.Email,
CommonHelper.GenerateRandomDigitCode(20),
PasswordFormat.Hashed,
- _workContextAccessor.WorkContext.CurrentStore.Id,
+ _contextAccessor.StoreContext.CurrentStore.Id,
approved);
//whether registration request has been completed successfully
await _customerManagerService.RegisterCustomer(registrationRequest);
//allow to save other customer values by consuming this event
- await _mediator.Publish(new RegisteredByExternalMethod(_workContextAccessor.WorkContext.CurrentCustomer, parameters));
+ await _mediator.Publish(new RegisteredByExternalMethod(_contextAccessor.WorkContext.CurrentCustomer, parameters));
//raise customer registered event
- await _mediator.Publish(new CustomerRegisteredEvent(_workContextAccessor.WorkContext.CurrentCustomer));
+ await _mediator.Publish(new CustomerRegisteredEvent(_contextAccessor.WorkContext.CurrentCustomer));
//associate external account with registered user
- await AssociateCustomer(_workContextAccessor.WorkContext.CurrentCustomer, parameters);
+ await AssociateCustomer(_contextAccessor.WorkContext.CurrentCustomer, parameters);
//authenticate
if (!approved)
@@ -155,7 +155,7 @@ public class ExternalAuthenticationService : IExternalAuthenticationService
? new RedirectToRouteResult("RegisterResult",
new { resultId = (int)UserRegistrationType.AdminApproval })
: Error(["Error on registration"]);
- await _authenticationService.SignIn(_workContextAccessor.WorkContext.CurrentCustomer, false);
+ await _authenticationService.SignIn(_contextAccessor.WorkContext.CurrentCustomer, false);
return new RedirectToRouteResult("RegisterResult", new { resultId = (int)UserRegistrationType.Standard });
}
@@ -206,8 +206,8 @@ public class ExternalAuthenticationService : IExternalAuthenticationService
return LoadAllAuthenticationProviders()
.Where(provider =>
provider.IsMethodActive(_externalAuthenticationSettings) &&
- provider.IsAuthenticateGroup(_workContextAccessor.WorkContext.CurrentCustomer) &&
- provider.IsAuthenticateStore(_workContextAccessor.WorkContext.CurrentStore)
+ provider.IsAuthenticateGroup(_contextAccessor.WorkContext.CurrentCustomer) &&
+ provider.IsAuthenticateStore(_contextAccessor.StoreContext.CurrentStore)
).ToList();
}
@@ -242,8 +242,8 @@ public class ExternalAuthenticationService : IExternalAuthenticationService
return authenticationMethod != null &&
authenticationMethod.IsMethodActive(_externalAuthenticationSettings) &&
- authenticationMethod.IsAuthenticateGroup(_workContextAccessor.WorkContext.CurrentCustomer) &&
- authenticationMethod.IsAuthenticateStore(_workContextAccessor.WorkContext.CurrentStore);
+ authenticationMethod.IsAuthenticateGroup(_contextAccessor.WorkContext.CurrentCustomer) &&
+ authenticationMethod.IsAuthenticateStore(_contextAccessor.StoreContext.CurrentStore);
}
#endregion
@@ -264,8 +264,8 @@ public class ExternalAuthenticationService : IExternalAuthenticationService
return Error(["External authentication method cannot be loaded"]);
//get current logged-in user
- var currentLoggedInUser = await _groupService.IsRegistered(_workContextAccessor.WorkContext.CurrentCustomer)
- ? _workContextAccessor.WorkContext.CurrentCustomer
+ var currentLoggedInUser = await _groupService.IsRegistered(_contextAccessor.WorkContext.CurrentCustomer)
+ ? _contextAccessor.WorkContext.CurrentCustomer
: null;
//authenticate associated user if already exists
diff --git a/src/Business/Grand.Business.Authentication/Services/TwoFactorAuthenticationService.cs b/src/Business/Grand.Business.Authentication/Services/TwoFactorAuthenticationService.cs
index 1b2f7177a..d883a68b9 100644
--- a/src/Business/Grand.Business.Authentication/Services/TwoFactorAuthenticationService.cs
+++ b/src/Business/Grand.Business.Authentication/Services/TwoFactorAuthenticationService.cs
@@ -14,14 +14,14 @@ public class TwoFactorAuthenticationService : ITwoFactorAuthenticationService
private readonly IEnumerable<ISMSVerificationService> _smsVerificationService;
private readonly TwoFactorAuthenticator _twoFactorAuthentication;
private readonly ICustomerService _customerService;
- private readonly IWorkContextAccessor _workContextAccessor;
+ private readonly IContextAccessor _contextAccessor;
public TwoFactorAuthenticationService(
- IWorkContextAccessor workContextAccessor,
+ IContextAccessor contextAccessor,
ICustomerService customerService,
IEnumerable<ISMSVerificationService> smsVerificationService)
{
- _workContextAccessor = workContextAccessor;
+ _contextAccessor = contextAccessor;
_customerService = customerService;
_smsVerificationService = smsVerificationService;
_twoFactorAuthentication = new TwoFactorAuthenticator();
@@ -62,7 +62,7 @@ public class TwoFactorAuthenticationService : ITwoFactorAuthenticationService
switch (twoFactorAuthenticationType)
{
case TwoFactorAuthenticationType.AppVerification:
- var setupInfo = _twoFactorAuthentication.GenerateSetupCode(_workContextAccessor.WorkContext.CurrentStore.CompanyName,
+ var setupInfo = _twoFactorAuthentication.GenerateSetupCode(_contextAccessor.StoreContext.CurrentStore.CompanyName,
customer.Email, secretKey, false);
model.CustomValues.Add("QrCodeImageUrl", setupInfo.QrCodeSetupImageUrl);
model.CustomValues.Add("ManualEntryQrCode", setupInfo.ManualEntryKey);
diff --git a/src/Business/Grand.Business.Catalog/Services/Brands/BrandService.cs b/src/Business/Grand.Business.Catalog/Services/Brands/BrandService.cs
index 00bfb3cea..d63bdc2c0 100644
--- a/src/Business/Grand.Business.Catalog/Services/Brands/BrandService.cs
+++ b/src/Business/Grand.Business.Catalog/Services/Brands/BrandService.cs
@@ -24,12 +24,12 @@ public class BrandService : IBrandService
/// </summary>
public BrandService(ICacheBase cacheBase,
IRepository<Brand> brandRepository,
- IWorkContextAccessor workContextAccessor,
+ IContextAccessor contextAccessor,
IMediator mediator, AccessControlConfig accessControlConfig)
{
_cacheBase = cacheBase;
_brandRepository = brandRepository;
- _workContextAccessor = workContextAccessor;
+ _contextAccessor = contextAccessor;
_mediator = mediator;
_accessControlConfig = accessControlConfig;
}
@@ -39,7 +39,7 @@ public class BrandService : IBrandService
#region Fields
private readonly IRepository<Brand> _brandRepository;
- private readonly IWorkContextAccessor _workContextAccessor;
+ private readonly IContextAccessor _contextAccessor;
private readonly IMediator _mediator;
private readonly ICacheBase _cacheBase;
private readonly AccessControlConfig _accessControlConfig;
@@ -77,7 +77,7 @@ public class BrandService : IBrandService
if (!showHidden && !_accessControlConfig.IgnoreAcl)
{
//Limited to customer groups rules
- var allowedCustomerGroupsIds = _workContextAccessor.WorkContext.CurrentCustomer.GetCustomerGroupIds();
+ var allowedCustomerGroupsIds = _contextAccessor.WorkContext.CurrentCustomer.GetCustomerGroupIds();
query = from p in query
where !p.LimitedToGroups || allowedCustomerGroupsIds.Any(x => p.CustomerGroups.Contains(x))
select p;
diff --git a/src/Business/Grand.Business.Catalog/Services/Categories/CategoryService.cs b/src/Business/Grand.Business.Catalog/Services/Categories/CategoryService.cs
index 3ca6ab0d3..8b3eb3064 100644
--- a/src/Business/Grand.Business.Catalog/Services/Categories/CategoryService.cs
+++ b/src/Business/Grand.Business.Catalog/Services/Categories/CategoryService.cs
@@ -5,6 +5,7 @@ using Grand.Data;
using Grand.Domain;
using Grand.Domain.Catalog;
using Grand.Domain.Customers;
+using Grand.Domain.Stores;
using Grand.Infrastructure;
using Grand.Infrastructure.Caching;
using Grand.Infrastructure.Caching.Constants;
@@ -32,14 +33,14 @@ public class CategoryService : ICategoryService
/// <param name="accessControlConfig"></param>
public CategoryService(ICacheBase cacheBase,
IRepository<Category> categoryRepository,
- IWorkContextAccessor workContextAccessor,
+ IContextAccessor contextAccessor,
IMediator mediator,
IAclService aclService,
AccessControlConfig accessControlConfig)
{
_cacheBase = cacheBase;
_categoryRepository = categoryRepository;
- _workContextAccessor = workContextAccessor;
+ _contextAccessor = contextAccessor;
_mediator = mediator;
_aclService = aclService;
_accessControlConfig = accessControlConfig;
@@ -50,12 +51,15 @@ public class CategoryService : ICategoryService
#region Fields
private readonly IRepository<Category> _categoryRepository;
- private readonly IWorkContextAccessor _workContextAccessor;
+ private readonly IContextAccessor _contextAccessor;
private readonly IMediator _mediator;
private readonly ICacheBase _cacheBase;
private readonly IAclService _aclService;
private readonly AccessControlConfig _accessControlConfig;
+ private Customer CurrentCustomer => _contextAccessor.WorkContext.CurrentCustomer;
+ private Store CurrentStore => _contextAccessor.StoreContext.CurrentStore;
+
#endregion
#region Methods
@@ -91,7 +95,7 @@ public class CategoryService : ICategoryService
if (!showHidden && !_accessControlConfig.IgnoreAcl)
{
//Limited to customer group (access control list)
- var allowedCustomerGroupsIds = _workContextAccessor.WorkContext.CurrentCustomer.GetCustomerGroupIds();
+ var allowedCustomerGroupsIds = CurrentCustomer.GetCustomerGroupIds();
query = from p in query
where !p.LimitedToGroups || allowedCustomerGroupsIds.Any(x => p.CustomerGroups.Contains(x))
select p;
@@ -124,12 +128,12 @@ public class CategoryService : ICategoryService
switch (_accessControlConfig.IgnoreAcl)
{
case true when
- string.IsNullOrEmpty(_workContextAccessor.WorkContext.CurrentStore.Id) || _accessControlConfig.IgnoreStoreLimitations:
+ string.IsNullOrEmpty(CurrentStore.Id) || _accessControlConfig.IgnoreStoreLimitations:
return await Task.FromResult(query.ToList());
case false:
{
//Limited to customer group (access control list)
- var allowedCustomerGroupsIds = _workContextAccessor.WorkContext.CurrentCustomer.GetCustomerGroupIds();
+ var allowedCustomerGroupsIds = CurrentCustomer.GetCustomerGroupIds();
query = from p in query
where !p.LimitedToGroups || allowedCustomerGroupsIds.Any(x => p.CustomerGroups.Contains(x))
select p;
@@ -137,10 +141,10 @@ public class CategoryService : ICategoryService
}
}
- if (!string.IsNullOrEmpty(_workContextAccessor.WorkContext.CurrentStore.Id) && !_accessControlConfig.IgnoreStoreLimitations)
+ if (!string.IsNullOrEmpty(CurrentStore.Id) && !_accessControlConfig.IgnoreStoreLimitations)
//Limited to stores rule
query = from p in query
- where !p.LimitedToStores || p.Stores.Contains(_workContextAccessor.WorkContext.CurrentStore.Id)
+ where !p.LimitedToStores || p.Stores.Contains(CurrentStore.Id)
select p;
return await Task.FromResult(query.ToList());
}
@@ -155,10 +159,8 @@ public class CategoryService : ICategoryService
public virtual async Task<IList<Category>> GetAllCategoriesByParentCategoryId(string parentCategoryId = "",
bool showHidden = false, bool includeAllLevels = false)
{
- var storeId = _workContextAccessor.WorkContext.CurrentStore.Id;
- var customer = _workContextAccessor.WorkContext.CurrentCustomer;
var key = string.Format(CacheKey.CATEGORIES_BY_PARENT_CATEGORY_ID_KEY, parentCategoryId, showHidden,
- customer.Id, storeId, includeAllLevels);
+ CurrentCustomer.Id, CurrentStore.Id, includeAllLevels);
return await _cacheBase.GetAsync(key, async () =>
{
var query = _categoryRepository.Table.Where(c => c.ParentCategoryId == parentCategoryId);
@@ -170,7 +172,7 @@ public class CategoryService : ICategoryService
if (!_accessControlConfig.IgnoreAcl)
{
//Limited to customer groups rules
- var allowedCustomerGroupsIds = _workContextAccessor.WorkContext.CurrentCustomer.GetCustomerGroupIds();
+ var allowedCustomerGroupsIds = CurrentCustomer.GetCustomerGroupIds();
query = from p in query
where !p.LimitedToGroups || allowedCustomerGroupsIds.Any(x => p.CustomerGroups.Contains(x))
select p;
@@ -179,7 +181,7 @@ public class CategoryService : ICategoryService
if (!_accessControlConfig.IgnoreStoreLimitations)
//Limited to stores rules
query = from p in query
- where !p.LimitedToStores || p.Stores.Contains(storeId)
+ where !p.LimitedToStores || p.Stores.Contains(CurrentStore.Id)
select p;
}
@@ -207,8 +209,8 @@ public class CategoryService : ICategoryService
var categories = await Task.FromResult(query.ToList());
if (!showHidden)
categories = categories
- .Where(c => _aclService.Authorize(c, _workContextAccessor.WorkContext.CurrentCustomer) &&
- _aclService.Authorize(c, _workContextAccessor.WorkContext.CurrentStore.Id))
+ .Where(c => _aclService.Authorize(c, CurrentCustomer) &&
+ _aclService.Authorize(c, CurrentStore.Id))
.ToList();
return categories;
@@ -228,8 +230,8 @@ public class CategoryService : ICategoryService
var categories = await Task.FromResult(query.ToList());
if (!showHidden)
categories = categories
- .Where(c => _aclService.Authorize(c, _workContextAccessor.WorkContext.CurrentCustomer) &&
- _aclService.Authorize(c, _workContextAccessor.WorkContext.CurrentStore.Id))
+ .Where(c => _aclService.Authorize(c, CurrentCustomer) &&
+ _aclService.Authorize(c, CurrentStore.Id))
.ToList();
return categories;
}
@@ -245,8 +247,8 @@ public class CategoryService : ICategoryService
.OrderBy(x => x.SearchBoxDisplayOrder);
var categories = (await Task.FromResult(query.ToList()))
- .Where(c => _aclService.Authorize(c, _workContextAccessor.WorkContext.CurrentCustomer) &&
- _aclService.Authorize(c, _workContextAccessor.WorkContext.CurrentStore.Id))
+ .Where(c => _aclService.Authorize(c, CurrentCustomer) &&
+ _aclService.Authorize(c, CurrentStore.Id))
.ToList();
return categories;
@@ -268,8 +270,8 @@ public class CategoryService : ICategoryService
while (category != null && //not null
(showHidden || category.Published) && //published
(showHidden ||
- _aclService.Authorize(category, _workContextAccessor.WorkContext.CurrentCustomer)) && //limited to customer groups
- (showHidden || _aclService.Authorize(category, _workContextAccessor.WorkContext.CurrentStore.Id)) && //limited to store
+ _aclService.Authorize(category, CurrentCustomer)) && //limited to customer groups
+ (showHidden || _aclService.Authorize(category, CurrentStore.Id)) && //limited to store
!alreadyProcessedCategoryIds.Contains(category.Id))
{
result.Add(category);
@@ -301,8 +303,8 @@ public class CategoryService : ICategoryService
while (category != null && //not null
(showHidden || category.Published) && //published
(showHidden ||
- _aclService.Authorize(category, _workContextAccessor.WorkContext.CurrentCustomer)) && //limited to customer groups
- (showHidden || _aclService.Authorize(category, _workContextAccessor.WorkContext.CurrentStore.Id)) && //limited to store
+ _aclService.Authorize(category, CurrentCustomer)) && //limited to customer groups
+ (showHidden || _aclService.Authorize(category, CurrentStore.Id)) && //limited to store
!alreadyProcessedCategoryIds.Contains(category.Id)) //avoid circular references
{
result.Add(category);
diff --git a/src/Business/Grand.Business.Catalog/Services/Categories/ProductCategoryService.cs b/src/Business/Grand.Business.Catalog/Services/Categories/ProductCategoryService.cs
index e037f1350..94c183607 100644
--- a/src/Business/Grand.Business.Catalog/Services/Categories/ProductCategoryService.cs
+++ b/src/Business/Grand.Business.Catalog/Services/Categories/ProductCategoryService.cs
@@ -19,17 +19,17 @@ public class ProductCategoryService : IProductCategoryService
private readonly ICacheBase _cacheBase;
private readonly IMediator _mediator;
private readonly IRepository<Product> _productRepository;
- private readonly IWorkContextAccessor _workContextAccessor;
+ private readonly IContextAccessor _contextAccessor;
public ProductCategoryService(
IRepository<Product> productRepository,
ICacheBase cacheBase,
- IWorkContextAccessor workContextAccessor,
+ IContextAccessor contextAccessor,
IMediator mediator, AccessControlConfig accessControlConfig)
{
_productRepository = productRepository;
_cacheBase = cacheBase;
- _workContextAccessor = workContextAccessor;
+ _contextAccessor = contextAccessor;
_mediator = mediator;
_accessControlConfig = accessControlConfig;
}
@@ -49,7 +49,7 @@ public class ProductCategoryService : IProductCategoryService
return new PagedList<ProductsCategory>(new List<ProductsCategory>(), pageIndex, pageSize);
var key = string.Format(CacheKey.PRODUCTCATEGORIES_ALLBYCATEGORYID_KEY, showHidden, categoryId, pageIndex,
- pageSize, _workContextAccessor.WorkContext.CurrentCustomer.Id, _workContextAccessor.WorkContext.CurrentStore.Id);
+ pageSize, _contextAccessor.WorkContext.CurrentCustomer.Id, _contextAccessor.StoreContext.CurrentStore.Id);
return await _cacheBase.GetAsync(key, () =>
{
var query = _productRepository.Table.Where(x => x.ProductCategories.Any(y => y.CategoryId == categoryId));
@@ -59,7 +59,7 @@ public class ProductCategoryService : IProductCategoryService
if (!_accessControlConfig.IgnoreAcl)
{
//Limited to customer groups
- var allowedCustomerGroupsIds = _workContextAccessor.WorkContext.CurrentCustomer.GetCustomerGroupIds();
+ var allowedCustomerGroupsIds = _contextAccessor.WorkContext.CurrentCustomer.GetCustomerGroupIds();
query = from p in query
where !p.LimitedToGroups || allowedCustomerGroupsIds.Any(x => p.CustomerGroups.Contains(x))
select p;
@@ -68,7 +68,7 @@ public class ProductCategoryService : IProductCategoryService
if (!_accessControlConfig.IgnoreStoreLimitations)
{
//Limited to stores
- var currentStoreId = _workContextAccessor.WorkContext.CurrentStore.Id;
+ var currentStoreId = _contextAccessor.StoreContext.CurrentStore.Id;
query = from p in query
where !p.LimitedToStores || p.Stores.Contains(currentStoreId)
select p;
diff --git a/src/Business/Grand.Business.Catalog/Services/Collections/CollectionService.cs b/src/Business/Grand.Business.Catalog/Services/Collections/CollectionService.cs
index f1c97314a..a16a8c05c 100644
--- a/src/Business/Grand.Business.Catalog/Services/Collections/CollectionService.cs
+++ b/src/Business/Grand.Business.Catalog/Services/Collections/CollectionService.cs
@@ -25,13 +25,13 @@ public class CollectionService : ICollectionService
/// </summary>
public CollectionService(ICacheBase cacheBase,
IRepository<Collection> collectionRepository,
- IWorkContextAccessor workContextAccessor,
+ IContextAccessor contextAccessor,
IMediator mediator,
IAclService aclService, AccessControlConfig accessControlConfig)
{
_cacheBase = cacheBase;
_collectionRepository = collectionRepository;
- _workContextAccessor = workContextAccessor;
+ _contextAccessor = contextAccessor;
_mediator = mediator;
_aclService = aclService;
_accessControlConfig = accessControlConfig;
@@ -42,7 +42,7 @@ public class CollectionService : ICollectionService
#region Fields
private readonly IRepository<Collection> _collectionRepository;
- private readonly IWorkContextAccessor _workContextAccessor;
+ private readonly IContextAccessor _contextAccessor;
private readonly IMediator _mediator;
private readonly ICacheBase _cacheBase;
private readonly IAclService _aclService;
@@ -81,7 +81,7 @@ public class CollectionService : ICollectionService
if (!showHidden && !_accessControlConfig.IgnoreAcl)
{
//Limited to customer groups rules
- var allowedCustomerGroupsIds = _workContextAccessor.WorkContext.CurrentCustomer.GetCustomerGroupIds();
+ var allowedCustomerGroupsIds = _contextAccessor.WorkContext.CurrentCustomer.GetCustomerGroupIds();
query = from p in query
where !p.LimitedToGroups || allowedCustomerGroupsIds.Any(x => p.CustomerGroups.Contains(x))
select p;
@@ -112,8 +112,8 @@ public class CollectionService : ICollectionService
var collections = await Task.FromResult(query.ToList());
if (!showHidden)
collections = collections
- .Where(c => _aclService.Authorize(c, _workContextAccessor.WorkContext.CurrentCustomer) &&
- _aclService.Authorize(c, _workContextAccessor.WorkContext.CurrentStore.Id))
+ .Where(c => _aclService.Authorize(c, _contextAccessor.WorkContext.CurrentCustomer) &&
+ _aclService.Authorize(c, _contextAccessor.StoreContext.CurrentStore.Id))
.ToList();
return collections;
}
diff --git a/src/Business/Grand.Business.Catalog/Services/Collections/ProductCollectionService.cs b/src/Business/Grand.Business.Catalog/Services/Collections/ProductCollectionService.cs
index bd8603628..fc4f79e41 100644
--- a/src/Business/Grand.Business.Catalog/Services/Collections/ProductCollectionService.cs
+++ b/src/Business/Grand.Business.Catalog/Services/Collections/ProductCollectionService.cs
@@ -19,12 +19,12 @@ public class ProductCollectionService : IProductCollectionService
public ProductCollectionService(ICacheBase cacheBase,
IRepository<Product> productRepository,
- IWorkContextAccessor workContextAccessor,
+ IContextAccessor contextAccessor,
IMediator mediator, AccessControlConfig accessControlConfig)
{
_cacheBase = cacheBase;
_productRepository = productRepository;
- _workContextAccessor = workContextAccessor;
+ _contextAccessor = contextAccessor;
_mediator = mediator;
_accessControlConfig = accessControlConfig;
}
@@ -45,7 +45,7 @@ public class ProductCollectionService : IProductCollectionService
int pageIndex = 0, int pageSize = int.MaxValue, bool showHidden = false)
{
var key = string.Format(CacheKey.PRODUCTCOLLECTIONS_ALLBYCOLLECTIONID_KEY, showHidden, collectionId, pageIndex,
- pageSize, _workContextAccessor.WorkContext.CurrentCustomer.Id, storeId);
+ pageSize, _contextAccessor.WorkContext.CurrentCustomer.Id, storeId);
return await _cacheBase.GetAsync(key, () =>
{
var query = _productRepository.Table.Where(x =>
@@ -56,7 +56,7 @@ public class ProductCollectionService : IProductCollectionService
if (!_accessControlConfig.IgnoreAcl)
{
//ACL (access control list)
- var allowedCustomerGroupsIds = _workContextAccessor.WorkContext.CurrentCustomer.GetCustomerGroupIds();
+ var allowedCustomerGroupsIds = _contextAccessor.WorkContext.CurrentCustomer.GetCustomerGroupIds();
query = from p in query
where !p.LimitedToGroups || allowedCustomerGroupsIds.Any(x => p.CustomerGroups.Contains(x))
select p;
@@ -149,7 +149,7 @@ public class ProductCollectionService : IProductCollectionService
#region Fields
private readonly IRepository<Product> _productRepository;
- private readonly IWorkContextAccessor _workContextAccessor;
+ private readonly IContextAccessor _contextAccessor;
private readonly IMediator _mediator;
private readonly ICacheBase _cacheBase;
private readonly AccessControlConfig _accessControlConfig;
diff --git a/src/Business/Grand.Business.Catalog/Services/Prices/PriceFormatter.cs b/src/Business/Grand.Business.Catalog/Services/Prices/PriceFormatter.cs
index 14cc54ac0..0bd8c531b 100644
--- a/src/Business/Grand.Business.Catalog/Services/Prices/PriceFormatter.cs
+++ b/src/Business/Grand.Business.Catalog/Services/Prices/PriceFormatter.cs
@@ -12,15 +12,15 @@ public class PriceFormatter : IPriceFormatter
{
#region Fields
- private readonly IWorkContextAccessor _workContextAccessor;
+ private readonly IContextAccessor _contextAccessor;
#endregion
#region Constructors
- public PriceFormatter(IWorkContextAccessor workContextAccessor)
+ public PriceFormatter(IContextAccessor contextAccessor)
{
- _workContextAccessor = workContextAccessor;
+ _contextAccessor = contextAccessor;
}
#endregion
@@ -73,7 +73,7 @@ public class PriceFormatter : IPriceFormatter
/// <returns>Price</returns>
public virtual string FormatPrice(double price)
{
- return FormatPrice(price, _workContextAccessor.WorkContext.WorkingCurrency);
+ return FormatPrice(price, _contextAccessor.WorkContext.WorkingCurrency);
}
/// <summary>
diff --git a/src/Business/Grand.Business.Catalog/Services/Prices/PricingService.cs b/src/Business/Grand.Business.Catalog/Services/Prices/PricingService.cs
index 85fd416b6..53f44ff3f 100644
--- a/src/Business/Grand.Business.Catalog/Services/Prices/PricingService.cs
+++ b/src/Business/Grand.Business.Catalog/Services/Prices/PricingService.cs
@@ -28,7 +28,7 @@ public class PricingService : IPricingService
{
#region Ctor
- public PricingService(IWorkContextAccessor workContextAccessor,
+ public PricingService(IContextAccessor contextAccessor,
IDiscountService discountService,
ICategoryService categoryService,
IBrandService brandService,
@@ -40,7 +40,7 @@ public class PricingService : IPricingService
ShoppingCartSettings shoppingCartSettings,
CatalogSettings catalogSettings)
{
- _workContextAccessor = workContextAccessor;
+ _contextAccessor = contextAccessor;
_discountService = discountService;
_categoryService = categoryService;
_brandService = brandService;
@@ -70,7 +70,7 @@ public class PricingService : IPricingService
#region Fields
- private readonly IWorkContextAccessor _workContextAccessor;
+ private readonly IContextAccessor _contextAccessor;
private readonly IDiscountService _discountService;
private readonly ICategoryService _categoryService;
private readonly IBrandService _brandService;
@@ -529,9 +529,9 @@ public class PricingService : IPricingService
ArgumentNullException.ThrowIfNull(shoppingCartItem);
return await GetUnitPrice(product,
- _workContextAccessor.WorkContext.CurrentCustomer,
- _workContextAccessor.WorkContext.CurrentStore,
- _workContextAccessor.WorkContext.WorkingCurrency,
+ _contextAccessor.WorkContext.CurrentCustomer,
+ _contextAccessor.StoreContext.CurrentStore,
+ _contextAccessor.WorkContext.WorkingCurrency,
shoppingCartItem.ShoppingCartTypeId,
shoppingCartItem.Quantity,
shoppingCartItem.Attributes,
@@ -772,7 +772,7 @@ public class PricingService : IPricingService
if (adjustment > 0)
adjustment =
await _currencyService.ConvertFromPrimaryStoreCurrency(adjustment,
- _workContextAccessor.WorkContext.WorkingCurrency);
+ _contextAccessor.WorkContext.WorkingCurrency);
}
break;
case AttributeValueType.AssociatedToProduct:
@@ -781,9 +781,9 @@ public class PricingService : IPricingService
var associatedProduct = await _productService.GetProductById(value.AssociatedProductId);
if (associatedProduct != null)
adjustment = (await GetFinalPrice(associatedProduct,
- _workContextAccessor.WorkContext.CurrentCustomer,
- _workContextAccessor.WorkContext.CurrentStore,
- _workContextAccessor.WorkContext.WorkingCurrency,
+ _contextAccessor.WorkContext.CurrentCustomer,
+ _contextAccessor.StoreContext.CurrentStore,
+ _contextAccessor.WorkContext.WorkingCurrency,
value.PriceAdjustment)).finalPrice * value.Quantity;
}
break;
diff --git a/src/Business/Grand.Business.Catalog/Services/Products/ProductAttributeFormatter.cs b/src/Business/Grand.Business.Catalog/Services/Products/ProductAttributeFormatter.cs
index 94b18de55..90799591a 100644
--- a/src/Business/Grand.Business.Catalog/Services/Products/ProductAttributeFormatter.cs
+++ b/src/Business/Grand.Business.Catalog/Services/Products/ProductAttributeFormatter.cs
@@ -22,16 +22,16 @@ public class ProductAttributeFormatter : IProductAttributeFormatter
private readonly IProductAttributeService _productAttributeService;
private readonly IProductService _productService;
private readonly ITaxService _taxService;
- private readonly IWorkContextAccessor _workContextAccessor;
+ private readonly IContextAccessor _contextAccessor;
- public ProductAttributeFormatter(IWorkContextAccessor workContextAccessor,
+ public ProductAttributeFormatter(IContextAccessor contextAccessor,
IProductAttributeService productAttributeService,
ITaxService taxService,
IPriceFormatter priceFormatter,
IPricingService priceCalculationService,
IProductService productService)
{
- _workContextAccessor = workContextAccessor;
+ _contextAccessor = contextAccessor;
_productAttributeService = productAttributeService;
_taxService = taxService;
_priceFormatter = priceFormatter;
@@ -47,7 +47,7 @@ public class ProductAttributeFormatter : IProductAttributeFormatter
/// <returns>Attributes</returns>
public virtual Task<string> FormatAttributes(Product product, IList<CustomAttribute> customAttributes)
{
- var customer = _workContextAccessor.WorkContext.CurrentCustomer;
+ var customer = _contextAccessor.WorkContext.CurrentCustomer;
return FormatAttributes(product, customAttributes, customer);
}
@@ -75,8 +75,8 @@ public class ProductAttributeFormatter : IProductAttributeFormatter
if (customAttributes == null || !customAttributes.Any())
return result.ToString();
- var langId = _workContextAccessor.WorkContext.WorkingLanguage != null
- ? _workContextAccessor.WorkContext.WorkingLanguage.Id
+ var langId = _contextAccessor.WorkContext.WorkingLanguage != null
+ ? _contextAccessor.WorkContext.WorkingLanguage.Id
: customer?.GetUserFieldFromEntity<string>(SystemCustomerFieldNames.LanguageId);
if (string.IsNullOrEmpty(langId))
@@ -195,7 +195,7 @@ public class ProductAttributeFormatter : IProductAttributeFormatter
if (allowHyperlinks)
{
var downloadLink =
- $"{_workContextAccessor.WorkContext.CurrentHost.Url.TrimEnd('/')}/download/getfileupload/?downloadId={downloadGuid}";
+ $"{_contextAccessor.StoreContext.CurrentHost.Url.TrimEnd('/')}/download/getfileupload/?downloadId={downloadGuid}";
attributeText =
$"<a href=\"{downloadLink}\" class=\"fileuploadattribute\">{attribute.GetTranslation(a => a.TextPrompt, langId)}</a>";
}
@@ -235,20 +235,20 @@ public class ProductAttributeFormatter : IProductAttributeFormatter
var attributeValuePriceAdjustment =
await _pricingService.GetProductAttributeValuePriceAdjustment(attributeValue);
var (priceAdjustmentBase, _) = await _taxService.GetProductPrice(product,
- attributeValuePriceAdjustment, _workContextAccessor.WorkContext.CurrentCustomer);
+ attributeValuePriceAdjustment, _contextAccessor.WorkContext.CurrentCustomer);
switch (priceAdjustmentBase)
{
case > 0:
{
var priceAdjustmentStr = _priceFormatter.FormatPrice(priceAdjustmentBase,
- _workContextAccessor.WorkContext.WorkingCurrency);
+ _contextAccessor.WorkContext.WorkingCurrency);
formattedAttribute += $" [+{priceAdjustmentStr}]";
break;
}
case < 0:
{
var priceAdjustmentStr = _priceFormatter.FormatPrice(-priceAdjustmentBase,
- _workContextAccessor.WorkContext.WorkingCurrency);
+ _contextAccessor.WorkContext.WorkingCurrency);
formattedAttribute += $" [-{priceAdjustmentStr}]";
break;
}
diff --git a/src/Business/Grand.Business.Catalog/Services/Products/ProductService.cs b/src/Business/Grand.Business.Catalog/Services/Products/ProductService.cs
index 579a5d067..3414bd9c0 100644
--- a/src/Business/Grand.Business.Catalog/Services/Products/ProductService.cs
+++ b/src/Business/Grand.Business.Catalog/Services/Products/ProductService.cs
@@ -28,14 +28,14 @@ public class ProductService : IProductService
/// </summary>
public ProductService(ICacheBase cacheBase,
IRepository<Product> productRepository,
- IWorkContextAccessor workContextAccessor,
+ IContextAccessor contextAccessor,
IMediator mediator,
IAclService aclService
)
{
_cacheBase = cacheBase;
_productRepository = productRepository;
- _workContextAccessor = workContextAccessor;
+ _contextAccessor = contextAccessor;
_mediator = mediator;
_aclService = aclService;
}
@@ -46,7 +46,7 @@ public class ProductService : IProductService
private readonly IRepository<Product> _productRepository;
private readonly ICacheBase _cacheBase;
- private readonly IWorkContextAccessor _workContextAccessor;
+ private readonly IContextAccessor _contextAccessor;
private readonly IAclService _aclService;
private readonly IMediator _mediator;
@@ -130,8 +130,8 @@ public class ProductService : IProductService
foreach (var id in productIds)
{
var product = await GetProductById(id);
- if (product != null && (showHidden || (_aclService.Authorize(product, _workContextAccessor.WorkContext.CurrentCustomer) &&
- _aclService.Authorize(product, _workContextAccessor.WorkContext.CurrentStore.Id) &&
+ if (product != null && (showHidden || (_aclService.Authorize(product, _contextAccessor.WorkContext.CurrentCustomer) &&
+ _aclService.Authorize(product, _contextAccessor.StoreContext.CurrentStore.Id) &&
product.IsAvailable())))
products.Add(product);
}
@@ -524,7 +524,7 @@ public class ProductService : IProductService
bool? overridePublished = null)
{
var model = await _mediator.Send(new GetSearchProductsQuery {
- Customer = _workContextAccessor.WorkContext.CurrentCustomer,
+ Customer = _contextAccessor.WorkContext.CurrentCustomer,
LoadFilterableSpecificationAttributeOptionIds = loadFilterableSpecificationAttributeOptionIds,
PageIndex = pageIndex,
PageSize = pageSize,
@@ -608,7 +608,7 @@ public class ProductService : IProductService
//ACL mapping
if (!showHidden)
- products = products.Where(x => _aclService.Authorize(x, _workContextAccessor.WorkContext.CurrentCustomer)).ToList();
+ products = products.Where(x => _aclService.Authorize(x, _contextAccessor.WorkContext.CurrentCustomer)).ToList();
//Store acl
if (!showHidden && !string.IsNullOrEmpty(storeId))
products = products.Where(x => _aclService.Authorize(x, storeId)).ToList();
@@ -895,8 +895,8 @@ public class ProductService : IProductService
var productToAdd = await GetProductById(crossSell);
//validate product
if (productToAdd is not { Published: true }
- || !_aclService.Authorize(productToAdd, _workContextAccessor.WorkContext.CurrentCustomer) ||
- !_aclService.Authorize(productToAdd, _workContextAccessor.WorkContext.CurrentStore.Id)
+ || !_aclService.Authorize(productToAdd, _contextAccessor.WorkContext.CurrentCustomer) ||
+ !_aclService.Authorize(productToAdd, _contextAccessor.StoreContext.CurrentStore.Id)
|| !productToAdd.IsAvailable())
continue;
diff --git a/src/Business/Grand.Business.Catalog/Services/Tax/TaxService.cs b/src/Business/Grand.Business.Catalog/Services/Tax/TaxService.cs
index e4150017b..175e42342 100644
--- a/src/Business/Grand.Business.Catalog/Services/Tax/TaxService.cs
+++ b/src/Business/Grand.Business.Catalog/Services/Tax/TaxService.cs
@@ -22,7 +22,7 @@ public class TaxService : ITaxService
#region Ctor
public TaxService(
- IWorkContextAccessor workContextAccessor,
+ IContextAccessor contextAccessor,
IGroupService groupService,
ICountryService countryService,
IEnumerable<ITaxProvider> taxProviders,
@@ -32,7 +32,7 @@ public class TaxService : ITaxService
CustomerSettings customerSettings,
AddressSettings addressSettings)
{
- _workContextAccessor = workContextAccessor;
+ _contextAccessor = contextAccessor;
_groupService = groupService;
_taxSettings = taxSettings;
_taxProviderSettings = taxProviderSettings;
@@ -47,7 +47,7 @@ public class TaxService : ITaxService
#region Fields
- private readonly IWorkContextAccessor _workContextAccessor;
+ private readonly IContextAccessor _contextAccessor;
private readonly IGroupService _groupService;
private readonly ICountryService _countryService;
private readonly IEnumerable<ITaxProvider> _taxProviders;
@@ -240,7 +240,7 @@ public class TaxService : ITaxService
public virtual ITaxProvider LoadActiveTaxProvider()
{
var taxProvider = LoadTaxProviderBySystemName(_taxProviderSettings.ActiveTaxProviderSystemName) ??
- LoadAllTaxProviders(_workContextAccessor.WorkContext.CurrentCustomer, _workContextAccessor.WorkContext.CurrentStore.Id)
+ LoadAllTaxProviders(_contextAccessor.WorkContext.CurrentCustomer, _contextAccessor.StoreContext.CurrentStore.Id)
.FirstOrDefault();
return taxProvider;
}
@@ -279,7 +279,7 @@ public class TaxService : ITaxService
/// <returns>Price</returns>
public virtual async Task<(double productprice, double taxRate)> GetProductPrice(Product product, double price)
{
- var customer = _workContextAccessor.WorkContext.CurrentCustomer;
+ var customer = _contextAccessor.WorkContext.CurrentCustomer;
return await GetProductPrice(product, price, customer);
}
@@ -293,7 +293,7 @@ public class TaxService : ITaxService
public virtual async Task<(double productprice, double taxRate)> GetProductPrice(Product product, double price,
Customer customer)
{
- var includingTax = _workContextAccessor.WorkContext.TaxDisplayType == TaxDisplayType.IncludingTax;
+ var includingTax = _contextAccessor.WorkContext.TaxDisplayType == TaxDisplayType.IncludingTax;
return await GetProductPrice(product, price, includingTax, customer);
}
@@ -469,7 +469,7 @@ public class TaxService : ITaxService
/// <returns>Price</returns>
public virtual async Task<(double shippingPrice, double taxRate)> GetShippingPrice(double price, Customer customer)
{
- var includingTax = _workContextAccessor.WorkContext.TaxDisplayType == TaxDisplayType.IncludingTax;
+ var includingTax = _contextAccessor.WorkContext.TaxDisplayType == TaxDisplayType.IncludingTax;
return await GetShippingPrice(price, includingTax, customer);
}
@@ -501,7 +501,7 @@ public class TaxService : ITaxService
public virtual async Task<(double paymentPrice, double taxRate)> GetPaymentMethodAdditionalFee(double price,
Customer customer)
{
- var includingTax = _workContextAccessor.WorkContext.TaxDisplayType == TaxDisplayType.IncludingTax;
+ var includingTax = _contextAccessor.WorkContext.TaxDisplayType == TaxDisplayType.IncludingTax;
return await GetPaymentMethodAdditionalFee(price, includingTax, customer);
}
@@ -532,7 +532,7 @@ public class TaxService : ITaxService
public virtual async Task<(double checkoutPrice, double taxRate)> GetCheckoutAttributePrice(CheckoutAttribute ca,
CheckoutAttributeValue cav)
{
- var customer = _workContextAccessor.WorkContext.CurrentCustomer;
+ var customer = _contextAccessor.WorkContext.CurrentCustomer;
return await GetCheckoutAttributePrice(ca, cav, customer);
}
@@ -546,7 +546,7 @@ public class TaxService : ITaxService
public virtual async Task<(double checkoutPrice, double taxRate)> GetCheckoutAttributePrice(CheckoutAttribute ca,
CheckoutAttributeValue cav, Customer customer)
{
- var includingTax = _workContextAccessor.WorkContext.TaxDisplayType == TaxDisplayType.IncludingTax;
+ var includingTax = _contextAccessor.WorkContext.TaxDisplayType == TaxDisplayType.IncludingTax;
return await GetCheckoutAttributePrice(ca, cav, includingTax, customer);
}
diff --git a/src/Business/Grand.Business.Checkout/Commands/Handlers/Orders/PlaceOrderCommandHandler.cs b/src/Business/Grand.Business.Checkout/Commands/Handlers/Orders/PlaceOrderCommandHandler.cs
index 3b844d957..8f276e3b0 100644
--- a/src/Business/Grand.Business.Checkout/Commands/Handlers/Orders/PlaceOrderCommandHandler.cs
+++ b/src/Business/Grand.Business.Checkout/Commands/Handlers/Orders/PlaceOrderCommandHandler.cs
@@ -65,7 +65,7 @@ public class PlaceOrderCommandHandler : IRequestHandler<PlaceOrderCommand, Place
private readonly ITaxService _taxService;
private readonly TaxSettings _taxSettings;
private readonly IVendorService _vendorService;
- private readonly IWorkContextAccessor _workContextAccessor;
+ private readonly IContextAccessor _contextAccessor;
public PlaceOrderCommandHandler(
IOrderService orderService,
@@ -83,7 +83,7 @@ public class PlaceOrderCommandHandler : IRequestHandler<PlaceOrderCommand, Place
ITaxService taxService,
ICustomerService customerService,
IDiscountService discountService,
- IWorkContextAccessor workContextAccessor,
+ IContextAccessor contextAccessor,
IGroupService groupService,
IMessageProviderService messageProviderService,
IVendorService vendorService,
@@ -117,7 +117,7 @@ public class PlaceOrderCommandHandler : IRequestHandler<PlaceOrderCommand, Place
_customerService = customerService;
_groupService = groupService;
_discountService = discountService;
- _workContextAccessor = workContextAccessor;
+ _contextAccessor = contextAccessor;
_messageProviderService = messageProviderService;
_vendorService = vendorService;
_salesEmployeeService = salesEmployeeService;
@@ -177,7 +177,7 @@ public class PlaceOrderCommandHandler : IRequestHandler<PlaceOrderCommand, Place
#region Events & notes
- await _mediator.Send(new OrderNotificationCommand { Order = result.PlacedOrder, WorkContext = _workContextAccessor.WorkContext }, cancellationToken);
+ await _mediator.Send(new OrderNotificationCommand { Order = result.PlacedOrder, WorkContext = _contextAccessor.WorkContext }, cancellationToken);
//check order status
await _mediator.Send(new CheckOrderStatusCommand { Order = result.PlacedOrder }, cancellationToken);
@@ -266,7 +266,7 @@ public class PlaceOrderCommandHandler : IRequestHandler<PlaceOrderCommand, Place
var paymentTransaction = new PaymentTransaction();
var paymentTransactionId =
details.Customer.GetUserFieldFromEntity<string>(SystemCustomerFieldNames.PaymentTransaction,
- _workContextAccessor.WorkContext.CurrentStore.Id);
+ _contextAccessor.StoreContext.CurrentStore.Id);
if (!string.IsNullOrEmpty(paymentTransactionId))
{
paymentTransaction = await _paymentTransactionService.GetById(paymentTransactionId);
@@ -284,7 +284,7 @@ public class PlaceOrderCommandHandler : IRequestHandler<PlaceOrderCommand, Place
paymentTransaction.OrderGuid =
paymentTransaction.OrderGuid == Guid.Empty ? Guid.NewGuid() : paymentTransaction.OrderGuid;
paymentTransaction.PaymentMethodSystemName = details.PaymentMethodSystemName;
- paymentTransaction.StoreId = _workContextAccessor.WorkContext.CurrentStore.Id;
+ paymentTransaction.StoreId = _contextAccessor.StoreContext.CurrentStore.Id;
paymentTransaction.CustomerId = details.Customer.Id;
paymentTransaction.TransactionAmount = details.OrderTotal;
paymentTransaction.CurrencyRate = details.CurrencyRate;
@@ -377,7 +377,7 @@ public class PlaceOrderCommandHandler : IRequestHandler<PlaceOrderCommand, Place
{
var details = new PlaceOrderContainer {
//customer
- Customer = _workContextAccessor.WorkContext.CurrentCustomer
+ Customer = _contextAccessor.WorkContext.CurrentCustomer
};
if (details.Customer == null)
throw new ArgumentException("Customer is not set");
@@ -404,8 +404,8 @@ public class PlaceOrderCommandHandler : IRequestHandler<PlaceOrderCommand, Place
//customer currency
var currencyTmp = await _currencyService.GetCurrencyById(
details.Customer.GetUserFieldFromEntity<string>(SystemCustomerFieldNames.CurrencyId,
- _workContextAccessor.WorkContext.CurrentStore.Id));
- var customerCurrency = currencyTmp is { Published: true } ? currencyTmp : _workContextAccessor.WorkContext.WorkingCurrency;
+ _contextAccessor.StoreContext.CurrentStore.Id));
+ var customerCurrency = currencyTmp is { Published: true } ? currencyTmp : _contextAccessor.WorkContext.WorkingCurrency;
details.Currency = customerCurrency;
var primaryStoreCurrency = await _currencyService.GetPrimaryStoreCurrency();
details.CurrencyRate = Math.Round(customerCurrency.Rate / primaryStoreCurrency.Rate, 6);
@@ -414,10 +414,10 @@ public class PlaceOrderCommandHandler : IRequestHandler<PlaceOrderCommand, Place
//customer language
details.Language = await _languageService.GetLanguageById(
details.Customer.GetUserFieldFromEntity<string>(SystemCustomerFieldNames.LanguageId,
- _workContextAccessor.WorkContext.CurrentStore.Id));
+ _contextAccessor.StoreContext.CurrentStore.Id));
if (details.Language is not { Published: true })
- details.Language = _workContextAccessor.WorkContext.WorkingLanguage;
+ details.Language = _contextAccessor.WorkContext.WorkingLanguage;
details.BillingAddress = details.Customer.BillingAddress;
if (!string.IsNullOrEmpty(details.BillingAddress.CountryId))
@@ -430,14 +430,14 @@ public class PlaceOrderCommandHandler : IRequestHandler<PlaceOrderCommand, Place
//checkout attributes
details.CheckoutAttributes =
details.Customer.GetUserFieldFromEntity<List<CustomAttribute>>(SystemCustomerFieldNames.CheckoutAttributes,
- _workContextAccessor.WorkContext.CurrentStore.Id);
+ _contextAccessor.StoreContext.CurrentStore.Id);
details.CheckoutAttributeDescription =
await _checkoutAttributeFormatter.FormatAttributes(details.CheckoutAttributes, details.Customer);
//load and validate customer shopping cart
details.Cart = details.Customer.ShoppingCartItems
.Where(sci => sci.ShoppingCartTypeId is ShoppingCartType.ShoppingCart or ShoppingCartType.Auctions)
- .LimitPerStore(_shoppingCartSettings.SharedCartBetweenStores, _workContextAccessor.WorkContext.CurrentStore.Id)
+ .LimitPerStore(_shoppingCartSettings.SharedCartBetweenStores, _contextAccessor.StoreContext.CurrentStore.Id)
.ToList();
if (!details.Cart.Any())
@@ -477,7 +477,7 @@ public class PlaceOrderCommandHandler : IRequestHandler<PlaceOrderCommand, Place
if (_taxSettings.AllowCustomersToSelectTaxDisplayType)
details.TaxDisplayType =
(TaxDisplayType)details.Customer.GetUserFieldFromEntity<int>(SystemCustomerFieldNames.TaxDisplayTypeId,
- _workContextAccessor.WorkContext.CurrentStore.Id);
+ _contextAccessor.StoreContext.CurrentStore.Id);
else
details.TaxDisplayType = _taxSettings.TaxDisplayType;
@@ -510,7 +510,7 @@ public class PlaceOrderCommandHandler : IRequestHandler<PlaceOrderCommand, Place
{
var pickupPoint =
details.Customer.GetUserFieldFromEntity<string>(SystemCustomerFieldNames.SelectedPickupPoint,
- _workContextAccessor.WorkContext.CurrentStore.Id);
+ _contextAccessor.StoreContext.CurrentStore.Id);
if (_shippingSettings.AllowPickUpInStore && pickupPoint != null)
{
details.PickUpInStore = true;
@@ -536,7 +536,7 @@ public class PlaceOrderCommandHandler : IRequestHandler<PlaceOrderCommand, Place
var shippingOption =
details.Customer.GetUserFieldFromEntity<ShippingOption>(SystemCustomerFieldNames.SelectedShippingOption,
- _workContextAccessor.WorkContext.CurrentStore.Id);
+ _contextAccessor.StoreContext.CurrentStore.Id);
if (shippingOption != null)
{
details.ShippingMethodName = shippingOption.Name;
@@ -566,8 +566,8 @@ public class PlaceOrderCommandHandler : IRequestHandler<PlaceOrderCommand, Place
//payment
var paymentMethodSystemName =
- _workContextAccessor.WorkContext.CurrentCustomer.GetUserFieldFromEntity<string>(SystemCustomerFieldNames.SelectedPaymentMethod,
- _workContextAccessor.WorkContext.CurrentStore.Id);
+ _contextAccessor.WorkContext.CurrentCustomer.GetUserFieldFromEntity<string>(SystemCustomerFieldNames.SelectedPaymentMethod,
+ _contextAccessor.StoreContext.CurrentStore.Id);
details.PaymentMethodSystemName = paymentMethodSystemName;
var paymentAdditionalFee =
await _paymentService.GetAdditionalHandlingFee(details.Cart, paymentMethodSystemName);
@@ -637,7 +637,7 @@ public class PlaceOrderCommandHandler : IRequestHandler<PlaceOrderCommand, Place
var itemWeight = await GetShoppingCartItemWeight(sc);
var warehouseId = !string.IsNullOrEmpty(sc.WarehouseId)
? sc.WarehouseId
- : _workContextAccessor.WorkContext.CurrentStore.DefaultWarehouseId;
+ : _contextAccessor.StoreContext.CurrentStore.DefaultWarehouseId;
if (!product.UseMultipleWarehouses && string.IsNullOrEmpty(warehouseId))
if (!string.IsNullOrEmpty(product.WarehouseId))
warehouseId = product.WarehouseId;
@@ -734,7 +734,7 @@ public class PlaceOrderCommandHandler : IRequestHandler<PlaceOrderCommand, Place
SenderEmail = giftVoucherSenderEmail,
Message = giftVoucherMessage,
IsRecipientNotified = false,
- StoreId = _orderSettings.GiftVouchers_Assign_StoreId ? _workContextAccessor.WorkContext.CurrentStore.Id : string.Empty
+ StoreId = _orderSettings.GiftVouchers_Assign_StoreId ? _contextAccessor.StoreContext.CurrentStore.Id : string.Empty
};
await _giftVoucherService.InsertGiftVoucher(gc);
}
diff --git a/src/Business/Grand.Business.Checkout/Events/ShoppingCart/CustomerLoggedInEventHandler.cs b/src/Business/Grand.Business.Checkout/Events/ShoppingCart/CustomerLoggedInEventHandler.cs
index f6590eb87..58b827bc3 100644
--- a/src/Business/Grand.Business.Checkout/Events/ShoppingCart/CustomerLoggedInEventHandler.cs
+++ b/src/Business/Grand.Business.Checkout/Events/ShoppingCart/CustomerLoggedInEventHandler.cs
@@ -8,17 +8,17 @@ namespace Grand.Business.Checkout.Events.ShoppingCart;
public class CustomerLoggedInEventHandler : INotificationHandler<CustomerLoggedInEvent>
{
private readonly IShoppingCartService _shoppingCartService;
- private readonly IWorkContextAccessor _workContextAccessor;
+ private readonly IContextAccessor _contextAccessor;
- public CustomerLoggedInEventHandler(IShoppingCartService shoppingCartService, IWorkContextAccessor workContextAccessor)
+ public CustomerLoggedInEventHandler(IShoppingCartService shoppingCartService, IContextAccessor contextAccessor)
{
_shoppingCartService = shoppingCartService;
- _workContextAccessor = workContextAccessor;
+ _contextAccessor = contextAccessor;
}
public async Task Handle(CustomerLoggedInEvent notification, CancellationToken cancellationToken)
{
//migrate shopping cart
- await _shoppingCartService.MigrateShoppingCart(_workContextAccessor.WorkContext.CurrentCustomer, notification.Customer, true);
+ await _shoppingCartService.MigrateShoppingCart(_contextAccessor.WorkContext.CurrentCustomer, notification.Customer, true);
}
}
\ No newline at end of file
diff --git a/src/Business/Grand.Business.Checkout/Services/CheckoutAttributes/CheckoutAttributeFormatter.cs b/src/Business/Grand.Business.Checkout/Services/CheckoutAttributes/CheckoutAttributeFormatter.cs
index 5bde9ab5d..1a274f410 100644
--- a/src/Business/Grand.Business.Checkout/Services/CheckoutAttributes/CheckoutAttributeFormatter.cs
+++ b/src/Business/Grand.Business.Checkout/Services/CheckoutAttributes/CheckoutAttributeFormatter.cs
@@ -22,15 +22,15 @@ public class CheckoutAttributeFormatter : ICheckoutAttributeFormatter
private readonly ICurrencyService _currencyService;
private readonly IPriceFormatter _priceFormatter;
private readonly ITaxService _taxService;
- private readonly IWorkContextAccessor _workContextAccessor;
+ private readonly IContextAccessor _contextAccessor;
- public CheckoutAttributeFormatter(IWorkContextAccessor workContextAccessor,
+ public CheckoutAttributeFormatter(IContextAccessor contextAccessor,
ICheckoutAttributeParser checkoutAttributeParser,
ICurrencyService currencyService,
ITaxService taxService,
IPriceFormatter priceFormatter)
{
- _workContextAccessor = workContextAccessor;
+ _contextAccessor = contextAccessor;
_checkoutAttributeParser = checkoutAttributeParser;
_currencyService = currencyService;
_taxService = taxService;
@@ -76,7 +76,7 @@ public class CheckoutAttributeFormatter : ICheckoutAttributeFormatter
case AttributeControlType.MultilineTextbox:
{
//multiline text box
- var attributeName = attribute.GetTranslation(a => a.Name, _workContextAccessor.WorkContext.WorkingLanguage.Id);
+ var attributeName = attribute.GetTranslation(a => a.Name, _contextAccessor.WorkContext.WorkingLanguage.Id);
//encode (if required)
if (htmlEncode)
attributeName = WebUtility.HtmlEncode(attributeName);
@@ -91,14 +91,14 @@ public class CheckoutAttributeFormatter : ICheckoutAttributeFormatter
{
var attributeText = string.Empty;
var attributeName =
- attribute.GetTranslation(a => a.Name, _workContextAccessor.WorkContext.WorkingLanguage.Id);
+ attribute.GetTranslation(a => a.Name, _contextAccessor.WorkContext.WorkingLanguage.Id);
if (allowHyperlinks)
{
//hyperlinks are allowed
var downloadLink =
- $"{_workContextAccessor.WorkContext.CurrentHost.Url.TrimEnd('/')}/download/getfileupload/?downloadId={downloadGuid}";
+ $"{_contextAccessor.StoreContext.CurrentHost.Url.TrimEnd('/')}/download/getfileupload/?downloadId={downloadGuid}";
attributeText =
- $"<a href=\"{downloadLink}\" class=\"fileuploadattribute\">{attribute.GetTranslation(a => a.TextPrompt, _workContextAccessor.WorkContext.WorkingLanguage.Id)}</a>";
+ $"<a href=\"{downloadLink}\" class=\"fileuploadattribute\">{attribute.GetTranslation(a => a.TextPrompt, _contextAccessor.WorkContext.WorkingLanguage.Id)}</a>";
}
formattedAttribute = $"{attributeName}: {attributeText}";
@@ -110,7 +110,7 @@ public class CheckoutAttributeFormatter : ICheckoutAttributeFormatter
{
//other attributes (text box, datepicker)
formattedAttribute =
- $"{attribute.GetTranslation(a => a.Name, _workContextAccessor.WorkContext.WorkingLanguage.Id)}: {valueStr}";
+ $"{attribute.GetTranslation(a => a.Name, _contextAccessor.WorkContext.WorkingLanguage.Id)}: {valueStr}";
//encode (if required)
if (htmlEncode)
formattedAttribute = WebUtility.HtmlEncode(formattedAttribute);
@@ -124,7 +124,7 @@ public class CheckoutAttributeFormatter : ICheckoutAttributeFormatter
if (attributeValue != null)
{
formattedAttribute =
- $"{attribute.GetTranslation(a => a.Name, _workContextAccessor.WorkContext.WorkingLanguage.Id)}: {attributeValue.GetTranslation(a => a.Name, _workContextAccessor.WorkContext.WorkingLanguage.Id)}";
+ $"{attribute.GetTranslation(a => a.Name, _contextAccessor.WorkContext.WorkingLanguage.Id)}: {attributeValue.GetTranslation(a => a.Name, _contextAccessor.WorkContext.WorkingLanguage.Id)}";
if (renderPrices)
{
var priceAdjustmentBase =
@@ -132,7 +132,7 @@ public class CheckoutAttributeFormatter : ICheckoutAttributeFormatter
.checkoutPrice;
var priceAdjustment =
await _currencyService.ConvertFromPrimaryStoreCurrency(priceAdjustmentBase,
- _workContextAccessor.WorkContext.WorkingCurrency);
+ _contextAccessor.WorkContext.WorkingCurrency);
if (priceAdjustmentBase > 0)
{
var priceAdjustmentStr = _priceFormatter.FormatPrice(priceAdjustment);
diff --git a/src/Business/Grand.Business.Checkout/Services/CheckoutAttributes/CheckoutAttributeService.cs b/src/Business/Grand.Business.Checkout/Services/CheckoutAttributes/CheckoutAttributeService.cs
index 9499f0645..45c37dd04 100644
--- a/src/Business/Grand.Business.Checkout/Services/CheckoutAttributes/CheckoutAttributeService.cs
+++ b/src/Business/Grand.Business.Checkout/Services/CheckoutAttributes/CheckoutAttributeService.cs
@@ -25,12 +25,12 @@ public class CheckoutAttributeService : ICheckoutAttributeService
ICacheBase cacheBase,
IRepository<CheckoutAttribute> checkoutAttributeRepository,
IMediator mediator,
- IWorkContextAccessor workContextAccessor, AccessControlConfig accessControlConfig)
+ IContextAccessor contextAccessor, AccessControlConfig accessControlConfig)
{
_cacheBase = cacheBase;
_checkoutAttributeRepository = checkoutAttributeRepository;
_mediator = mediator;
- _workContextAccessor = workContextAccessor;
+ _contextAccessor = contextAccessor;
_accessControlConfig = accessControlConfig;
}
@@ -41,7 +41,7 @@ public class CheckoutAttributeService : ICheckoutAttributeService
private readonly IRepository<CheckoutAttribute> _checkoutAttributeRepository;
private readonly IMediator _mediator;
private readonly ICacheBase _cacheBase;
- private readonly IWorkContextAccessor _workContextAccessor;
+ private readonly IContextAccessor _contextAccessor;
private readonly AccessControlConfig _accessControlConfig;
#endregion
@@ -71,7 +71,7 @@ public class CheckoutAttributeService : ICheckoutAttributeService
{
if (!ignoreAcl && !_accessControlConfig.IgnoreAcl)
{
- var allowedCustomerGroupsIds = _workContextAccessor.WorkContext.CurrentCustomer.GetCustomerGroupIds();
+ var allowedCustomerGroupsIds = _contextAccessor.WorkContext.CurrentCustomer.GetCustomerGroupIds();
query = from p in query
where !p.LimitedToGroups || allowedCustomerGroupsIds.Any(x => p.CustomerGroups.Contains(x))
select p;
diff --git a/src/Business/Grand.Business.Checkout/Services/Orders/OrderCalculationService.cs b/src/Business/Grand.Business.Checkout/Services/Orders/OrderCalculationService.cs
index 7062e2772..cd9447fd3 100644
--- a/src/Business/Grand.Business.Checkout/Services/Orders/OrderCalculationService.cs
+++ b/src/Business/Grand.Business.Checkout/Services/Orders/OrderCalculationService.cs
@@ -53,7 +53,7 @@ public class OrderCalculationService : IOrderCalculationService
/// <param name="shippingSettings">Shipping settings</param>
/// <param name="shoppingCartSettings">Shopping cart settings</param>
/// <param name="catalogSettings">Catalog settings</param>
- public OrderCalculationService(IWorkContextAccessor workContextAccessor,
+ public OrderCalculationService(IContextAccessor contextAccessor,
IPricingService priceCalculationService,
ITaxService taxService,
IShippingService shippingService,
@@ -72,7 +72,7 @@ public class OrderCalculationService : IOrderCalculationService
ShoppingCartSettings shoppingCartSettings,
CatalogSettings catalogSettings)
{
- _workContextAccessor = workContextAccessor;
+ _contextAccessor = contextAccessor;
_pricingService = priceCalculationService;
_taxService = taxService;
_shippingService = shippingService;
@@ -96,7 +96,7 @@ public class OrderCalculationService : IOrderCalculationService
#region Fields
- private readonly IWorkContextAccessor _workContextAccessor;
+ private readonly IContextAccessor _contextAccessor;
private readonly IPricingService _pricingService;
private readonly ITaxService _taxService;
private readonly IShippingService _shippingService;
@@ -136,7 +136,7 @@ public class OrderCalculationService : IOrderCalculationService
return (discountAmount, appliedDiscounts);
var allDiscounts = await _discountService.GetActiveDiscountsByContext(DiscountType.AssignedToOrderSubTotal,
- _workContextAccessor.WorkContext.CurrentStore.Id, currency.CurrencyCode);
+ _contextAccessor.StoreContext.CurrentStore.Id, currency.CurrencyCode);
var allowedDiscounts = new List<ApplyDiscount>();
if (allDiscounts != null)
foreach (var discount in allDiscounts)
@@ -154,7 +154,7 @@ public class OrderCalculationService : IOrderCalculationService
}
var preferredDiscounts = await _discountService.GetPreferredDiscount(allowedDiscounts, customer,
- _workContextAccessor.WorkContext.WorkingCurrency, orderSubTotal);
+ _contextAccessor.WorkContext.WorkingCurrency, orderSubTotal);
appliedDiscounts = preferredDiscounts.appliedDiscount;
discountAmount = preferredDiscounts.discountAmount;
@@ -181,7 +181,7 @@ public class OrderCalculationService : IOrderCalculationService
return (shippingDiscountAmount, appliedDiscounts);
var allDiscounts = await _discountService.GetActiveDiscountsByContext(DiscountType.AssignedToShipping,
- _workContextAccessor.WorkContext.CurrentStore.Id, currency.CurrencyCode);
+ _contextAccessor.StoreContext.CurrentStore.Id, currency.CurrencyCode);
var allowedDiscounts = new List<ApplyDiscount>();
if (allDiscounts != null)
foreach (var discount in allDiscounts)
@@ -199,7 +199,7 @@ public class OrderCalculationService : IOrderCalculationService
}
var (appliedDiscount, discountAmount) = await _discountService.GetPreferredDiscount(allowedDiscounts,
- customer, _workContextAccessor.WorkContext.WorkingCurrency, shippingTotal);
+ customer, _contextAccessor.WorkContext.WorkingCurrency, shippingTotal);
appliedDiscounts = appliedDiscount;
shippingDiscountAmount = discountAmount;
@@ -208,7 +208,7 @@ public class OrderCalculationService : IOrderCalculationService
if (_shoppingCartSettings.RoundPrices)
shippingDiscountAmount =
- RoundingHelper.RoundPrice(shippingDiscountAmount, _workContextAccessor.WorkContext.WorkingCurrency);
+ RoundingHelper.RoundPrice(shippingDiscountAmount, _contextAccessor.WorkContext.WorkingCurrency);
return (shippingDiscountAmount, appliedDiscounts);
}
@@ -230,7 +230,7 @@ public class OrderCalculationService : IOrderCalculationService
return (discountAmount, appliedDiscounts);
var allDiscounts = await _discountService.GetActiveDiscountsByContext(DiscountType.AssignedToOrderTotal,
- _workContextAccessor.WorkContext.CurrentStore.Id, currency.CurrencyCode);
+ _contextAccessor.StoreContext.CurrentStore.Id, currency.CurrencyCode);
var allowedDiscounts = new List<ApplyDiscount>();
if (allDiscounts != null)
foreach (var discount in allDiscounts)
@@ -248,7 +248,7 @@ public class OrderCalculationService : IOrderCalculationService
}
var preferredDiscount = await _discountService.GetPreferredDiscount(allowedDiscounts, customer,
- _workContextAccessor.WorkContext.WorkingCurrency, orderTotal);
+ _contextAccessor.WorkContext.WorkingCurrency, orderTotal);
appliedDiscounts = preferredDiscount.appliedDiscount;
discountAmount = preferredDiscount.discountAmount;
@@ -256,7 +256,7 @@ public class OrderCalculationService : IOrderCalculationService
discountAmount = 0;
if (_shoppingCartSettings.RoundPrices)
- discountAmount = RoundingHelper.RoundPrice(discountAmount, _workContextAccessor.WorkContext.WorkingCurrency);
+ discountAmount = RoundingHelper.RoundPrice(discountAmount, _contextAccessor.WorkContext.WorkingCurrency);
return (discountAmount, appliedDiscounts);
}
@@ -308,7 +308,7 @@ public class OrderCalculationService : IOrderCalculationService
return (discountAmount, appliedDiscounts, subTotalWithoutDiscount, subTotalWithDiscount, taxRates);
//get the customer
- var customer = _workContextAccessor.WorkContext.CurrentCustomer;
+ var customer = _contextAccessor.WorkContext.CurrentCustomer;
//sub totals
double subTotalExclTaxWithoutDiscount = 0;
@@ -344,7 +344,7 @@ public class OrderCalculationService : IOrderCalculationService
{
var checkoutAttributes =
customer.GetUserFieldFromEntity<List<CustomAttribute>>(SystemCustomerFieldNames.CheckoutAttributes,
- _workContextAccessor.WorkContext.CurrentStore.Id);
+ _contextAccessor.StoreContext.CurrentStore.Id);
var attributeValues = await _checkoutAttributeParser.ParseCheckoutAttributeValue(checkoutAttributes);
foreach (var attributeValue in attributeValues)
{
@@ -353,14 +353,14 @@ public class OrderCalculationService : IOrderCalculationService
customer);
var caExclTax =
await _currencyService.ConvertFromPrimaryStoreCurrency(
- checkoutAttributePriceExclTax.checkoutPrice, _workContextAccessor.WorkContext.WorkingCurrency);
+ checkoutAttributePriceExclTax.checkoutPrice, _contextAccessor.WorkContext.WorkingCurrency);
var (checkoutPrice, taxRate) =
await _taxService.GetCheckoutAttributePrice(attributeValue.ca, attributeValue.cav, true,
customer);
var caInclTax =
await _currencyService.ConvertFromPrimaryStoreCurrency(checkoutPrice,
- _workContextAccessor.WorkContext.WorkingCurrency);
+ _contextAccessor.WorkContext.WorkingCurrency);
subTotalExclTaxWithoutDiscount += caExclTax;
subTotalInclTaxWithoutDiscount += caInclTax;
@@ -383,12 +383,12 @@ public class OrderCalculationService : IOrderCalculationService
if (_shoppingCartSettings.RoundPrices)
subTotalWithoutDiscount =
- RoundingHelper.RoundPrice(subTotalWithoutDiscount, _workContextAccessor.WorkContext.WorkingCurrency);
+ RoundingHelper.RoundPrice(subTotalWithoutDiscount, _contextAccessor.WorkContext.WorkingCurrency);
//We calculate discount amount on order subtotal excl tax (discount first)
//calculate discount amount ('Applied to order subtotal' discount)
- var orderSubtotalDiscount = await GetOrderSubtotalDiscount(customer, _workContextAccessor.WorkContext.CurrentStore,
- _workContextAccessor.WorkContext.WorkingCurrency, subTotalExclTaxWithoutDiscount);
+ var orderSubtotalDiscount = await GetOrderSubtotalDiscount(customer, _contextAccessor.StoreContext.CurrentStore,
+ _contextAccessor.WorkContext.WorkingCurrency, subTotalExclTaxWithoutDiscount);
var discountAmountExclTax = orderSubtotalDiscount.ordersubtotaldiscount;
appliedDiscounts = orderSubtotalDiscount.appliedDiscounts;
@@ -414,7 +414,7 @@ public class OrderCalculationService : IOrderCalculationService
discountAmountInclTax += discountTax;
taxValue = taxRates[taxRate] - discountTax;
if (_shoppingCartSettings.RoundPrices)
- taxValue = RoundingHelper.RoundPrice(taxValue, _workContextAccessor.WorkContext.WorkingCurrency);
+ taxValue = RoundingHelper.RoundPrice(taxValue, _contextAccessor.WorkContext.WorkingCurrency);
taxRates[taxRate] = taxValue;
}
@@ -424,8 +424,8 @@ public class OrderCalculationService : IOrderCalculationService
if (_shoppingCartSettings.RoundPrices)
{
- discountAmountInclTax = RoundingHelper.RoundPrice(discountAmountInclTax, _workContextAccessor.WorkContext.WorkingCurrency);
- discountAmountExclTax = RoundingHelper.RoundPrice(discountAmountExclTax, _workContextAccessor.WorkContext.WorkingCurrency);
+ discountAmountInclTax = RoundingHelper.RoundPrice(discountAmountInclTax, _contextAccessor.WorkContext.WorkingCurrency);
+ discountAmountExclTax = RoundingHelper.RoundPrice(discountAmountExclTax, _contextAccessor.WorkContext.WorkingCurrency);
}
if (includingTax)
@@ -443,7 +443,7 @@ public class OrderCalculationService : IOrderCalculationService
subTotalWithDiscount = 0;
if (_shoppingCartSettings.RoundPrices)
- subTotalWithDiscount = RoundingHelper.RoundPrice(subTotalWithDiscount, _workContextAccessor.WorkContext.WorkingCurrency);
+ subTotalWithDiscount = RoundingHelper.RoundPrice(subTotalWithDiscount, _contextAccessor.WorkContext.WorkingCurrency);
return (discountAmount, appliedDiscounts, subTotalWithoutDiscount, subTotalWithDiscount, taxRates);
}
@@ -473,7 +473,7 @@ public class OrderCalculationService : IOrderCalculationService
/// <returns>A value indicating whether shipping is free</returns>
public virtual async Task<bool> IsFreeShipping(IList<ShoppingCartItem> cart)
{
- var customer = _workContextAccessor.WorkContext.CurrentCustomer;
+ var customer = _contextAccessor.WorkContext.CurrentCustomer;
if (customer != null)
{
//check whether customer has a free shipping
@@ -525,9 +525,9 @@ public class OrderCalculationService : IOrderCalculationService
//discount
var (discountAmount, applyDiscounts) = await GetShippingDiscount(
- _workContextAccessor.WorkContext.CurrentCustomer,
- _workContextAccessor.WorkContext.CurrentStore,
- _workContextAccessor.WorkContext.WorkingCurrency, adjustedRate);
+ _contextAccessor.WorkContext.CurrentCustomer,
+ _contextAccessor.StoreContext.CurrentStore,
+ _contextAccessor.WorkContext.WorkingCurrency, adjustedRate);
appliedDiscounts = applyDiscounts;
adjustedRate -= discountAmount;
@@ -536,7 +536,7 @@ public class OrderCalculationService : IOrderCalculationService
adjustedRate = 0;
if (_shoppingCartSettings.RoundPrices)
- adjustedRate = RoundingHelper.RoundPrice(adjustedRate, _workContextAccessor.WorkContext.WorkingCurrency);
+ adjustedRate = RoundingHelper.RoundPrice(adjustedRate, _contextAccessor.WorkContext.WorkingCurrency);
return (adjustedRate, appliedDiscounts);
}
@@ -550,7 +550,7 @@ public class OrderCalculationService : IOrderCalculationService
Task<(double? shoppingCartShippingTotal, double taxRate, List<ApplyDiscount> appliedDiscounts)>
GetShoppingCartShippingTotal(IList<ShoppingCartItem> cart)
{
- var includingTax = _workContextAccessor.WorkContext.TaxDisplayType == TaxDisplayType.IncludingTax;
+ var includingTax = _contextAccessor.WorkContext.TaxDisplayType == TaxDisplayType.IncludingTax;
return await GetShoppingCartShippingTotal(cart, includingTax);
}
@@ -569,7 +569,7 @@ public class OrderCalculationService : IOrderCalculationService
var appliedDiscounts = new List<ApplyDiscount>();
double taxRate = 0;
- var customer = _workContextAccessor.WorkContext.CurrentCustomer;
+ var customer = _contextAccessor.WorkContext.CurrentCustomer;
var currency = await _currencyService.GetPrimaryExchangeRateCurrency();
var isFreeShipping = await IsFreeShipping(cart);
@@ -580,7 +580,7 @@ public class OrderCalculationService : IOrderCalculationService
if (customer != null)
shippingOption =
customer.GetUserFieldFromEntity<ShippingOption>(SystemCustomerFieldNames.SelectedShippingOption,
- _workContextAccessor.WorkContext.CurrentStore.Id);
+ _contextAccessor.StoreContext.CurrentStore.Id);
if (shippingOption != null)
{
@@ -597,8 +597,8 @@ public class OrderCalculationService : IOrderCalculationService
shippingAddress = customer.ShippingAddress;
var shippingRateMethods =
- await _shippingService.LoadActiveShippingRateCalculationProviders(_workContextAccessor.WorkContext.CurrentCustomer,
- _workContextAccessor.WorkContext.CurrentStore.Id, cart);
+ await _shippingService.LoadActiveShippingRateCalculationProviders(_contextAccessor.WorkContext.CurrentCustomer,
+ _contextAccessor.StoreContext.CurrentStore.Id, cart);
if (!shippingRateMethods.Any() && !_shippingSettings.AllowPickUpInStore)
throw new GrandException("Shipping rate method could not be loaded");
@@ -609,7 +609,7 @@ public class OrderCalculationService : IOrderCalculationService
var shippingOptionRequest = await _shippingService.CreateShippingOptionRequests(customer, cart,
shippingAddress,
- _workContextAccessor.WorkContext.CurrentStore);
+ _contextAccessor.StoreContext.CurrentStore);
double? fixedRate = null;
//calculate fixed rates for each request-package
@@ -670,12 +670,12 @@ public class OrderCalculationService : IOrderCalculationService
var taxRates = new SortedDictionary<double, double>();
- var customer = _workContextAccessor.WorkContext.CurrentCustomer;
+ var customer = _contextAccessor.WorkContext.CurrentCustomer;
var paymentMethodSystemName = "";
if (customer != null)
paymentMethodSystemName = customer.GetUserFieldFromEntity<string>(
SystemCustomerFieldNames.SelectedPaymentMethod,
- _workContextAccessor.WorkContext.CurrentStore.Id);
+ _contextAccessor.StoreContext.CurrentStore.Id);
//order sub total (items + checkout attributes)
double subTotalTaxTotal = 0;
@@ -761,7 +761,7 @@ public class OrderCalculationService : IOrderCalculationService
taxTotal = 0;
//round tax
if (_shoppingCartSettings.RoundPrices)
- taxTotal = RoundingHelper.RoundPrice(taxTotal, _workContextAccessor.WorkContext.WorkingCurrency);
+ taxTotal = RoundingHelper.RoundPrice(taxTotal, _contextAccessor.WorkContext.WorkingCurrency);
return (taxTotal, taxRates);
}
@@ -783,9 +783,9 @@ public class OrderCalculationService : IOrderCalculationService
var redeemedLoyaltyPoints = 0;
double redeemedLoyaltyPointsAmount = 0;
- var paymentMethodSystemName = _workContextAccessor.WorkContext.CurrentCustomer.GetUserFieldFromEntity<string>(
+ var paymentMethodSystemName = _contextAccessor.WorkContext.CurrentCustomer.GetUserFieldFromEntity<string>(
SystemCustomerFieldNames.SelectedPaymentMethod,
- _workContextAccessor.WorkContext.CurrentStore.Id);
+ _contextAccessor.StoreContext.CurrentStore.Id);
//subtotal without tax
var subTotal = await GetShoppingCartSubTotal(cart, false);
@@ -803,7 +803,7 @@ public class OrderCalculationService : IOrderCalculationService
await _paymentService.GetAdditionalHandlingFee(cart, paymentMethodSystemName);
paymentMethodAdditionalFeeWithoutTax =
(await _taxService.GetPaymentMethodAdditionalFee(paymentMethodAdditionalFee, false,
- _workContextAccessor.WorkContext.CurrentCustomer))
+ _contextAccessor.WorkContext.CurrentCustomer))
.paymentPrice;
}
@@ -818,12 +818,12 @@ public class OrderCalculationService : IOrderCalculationService
resultTemp += paymentMethodAdditionalFeeWithoutTax;
resultTemp += shoppingCartTax;
if (_shoppingCartSettings.RoundPrices)
- resultTemp = RoundingHelper.RoundPrice(resultTemp, _workContextAccessor.WorkContext.WorkingCurrency);
+ resultTemp = RoundingHelper.RoundPrice(resultTemp, _contextAccessor.WorkContext.WorkingCurrency);
#region Order total discount
- var totalDiscount = await GetOrderTotalDiscount(_workContextAccessor.WorkContext.CurrentCustomer, _workContextAccessor.WorkContext.CurrentStore,
- _workContextAccessor.WorkContext.WorkingCurrency, resultTemp);
+ var totalDiscount = await GetOrderTotalDiscount(_contextAccessor.WorkContext.CurrentCustomer, _contextAccessor.StoreContext.CurrentStore,
+ _contextAccessor.WorkContext.WorkingCurrency, resultTemp);
var discountAmount = totalDiscount.orderTotalDiscount;
var appliedDiscounts = totalDiscount.appliedDiscounts;
@@ -837,7 +837,7 @@ public class OrderCalculationService : IOrderCalculationService
if (resultTemp < 0)
resultTemp = 0;
if (_shoppingCartSettings.RoundPrices)
- resultTemp = RoundingHelper.RoundPrice(resultTemp, _workContextAccessor.WorkContext.WorkingCurrency);
+ resultTemp = RoundingHelper.RoundPrice(resultTemp, _contextAccessor.WorkContext.WorkingCurrency);
#endregion
@@ -846,8 +846,8 @@ public class OrderCalculationService : IOrderCalculationService
var appliedGiftVouchers = new List<AppliedGiftVoucher>();
//we don't apply gift vouchers for recurring products
var giftVouchers =
- await GetActiveGiftVouchers(_workContextAccessor.WorkContext.CurrentCustomer, _workContextAccessor.WorkContext.WorkingCurrency,
- _workContextAccessor.WorkContext.CurrentStore);
+ await GetActiveGiftVouchers(_contextAccessor.WorkContext.CurrentCustomer, _contextAccessor.WorkContext.WorkingCurrency,
+ _contextAccessor.StoreContext.CurrentStore);
if (giftVouchers != null)
foreach (var gc in giftVouchers)
if (resultTemp > 0)
@@ -870,7 +870,7 @@ public class OrderCalculationService : IOrderCalculationService
if (resultTemp < 0)
resultTemp = 0;
if (_shoppingCartSettings.RoundPrices)
- resultTemp = RoundingHelper.RoundPrice(resultTemp, _workContextAccessor.WorkContext.WorkingCurrency);
+ resultTemp = RoundingHelper.RoundPrice(resultTemp, _contextAccessor.WorkContext.WorkingCurrency);
if (!shoppingCartShipping.HasValue)
//we have errors
@@ -883,15 +883,15 @@ public class OrderCalculationService : IOrderCalculationService
if (_loyaltyPointsSettings.Enabled)
{
- useLoyaltyPoints ??= _workContextAccessor.WorkContext.CurrentCustomer.GetUserFieldFromEntity<bool>(
+ useLoyaltyPoints ??= _contextAccessor.WorkContext.CurrentCustomer.GetUserFieldFromEntity<bool>(
SystemCustomerFieldNames.UseLoyaltyPointsDuringCheckout,
- _workContextAccessor.WorkContext.CurrentStore.Id);
+ _contextAccessor.StoreContext.CurrentStore.Id);
if (useLoyaltyPoints.Value)
{
var loyaltyPointsBalance =
- await _loyaltyPointsService.GetLoyaltyPointsBalance(_workContextAccessor.WorkContext.CurrentCustomer.Id,
- _workContextAccessor.WorkContext.CurrentStore.Id);
+ await _loyaltyPointsService.GetLoyaltyPointsBalance(_contextAccessor.WorkContext.CurrentCustomer.Id,
+ _contextAccessor.StoreContext.CurrentStore.Id);
if (CheckMinimumLoyaltyPointsToUseRequirement(loyaltyPointsBalance))
{
var loyaltyPointsBalanceAmount = await ConvertLoyaltyPointsToAmount(loyaltyPointsBalance);
@@ -902,14 +902,14 @@ public class OrderCalculationService : IOrderCalculationService
redeemedLoyaltyPoints = loyaltyPointsBalance;
redeemedLoyaltyPointsAmount =
await _currencyService.ConvertFromPrimaryStoreCurrency(loyaltyPointsBalanceAmount,
- _workContextAccessor.WorkContext.WorkingCurrency);
+ _contextAccessor.WorkContext.WorkingCurrency);
}
else
{
redeemedLoyaltyPointsAmount = orderTotal;
redeemedLoyaltyPoints = ConvertAmountToLoyaltyPoints(
await _currencyService.ConvertToPrimaryStoreCurrency(redeemedLoyaltyPointsAmount,
- _workContextAccessor.WorkContext.WorkingCurrency));
+ _contextAccessor.WorkContext.WorkingCurrency));
}
}
}
@@ -920,7 +920,7 @@ public class OrderCalculationService : IOrderCalculationService
orderTotal -= redeemedLoyaltyPointsAmount;
if (_shoppingCartSettings.RoundPrices)
- orderTotal = RoundingHelper.RoundPrice(orderTotal, _workContextAccessor.WorkContext.WorkingCurrency);
+ orderTotal = RoundingHelper.RoundPrice(orderTotal, _contextAccessor.WorkContext.WorkingCurrency);
return (orderTotal, discountAmount, appliedDiscounts, appliedGiftVouchers, redeemedLoyaltyPoints,
redeemedLoyaltyPointsAmount);
@@ -937,7 +937,7 @@ public class OrderCalculationService : IOrderCalculationService
return 0;
var result = loyaltyPoints * _loyaltyPointsSettings.ExchangeRate;
- if (_shoppingCartSettings.RoundPrices) result = RoundingHelper.RoundPrice(result, _workContextAccessor.WorkContext.WorkingCurrency);
+ if (_shoppingCartSettings.RoundPrices) result = RoundingHelper.RoundPrice(result, _contextAccessor.WorkContext.WorkingCurrency);
return await Task.FromResult(result);
}
diff --git a/src/Business/Grand.Business.Checkout/Services/Orders/ShoppingCartService.cs b/src/Business/Grand.Business.Checkout/Services/Orders/ShoppingCartService.cs
index 161d01099..7b70b5274 100644
--- a/src/Business/Grand.Business.Checkout/Services/Orders/ShoppingCartService.cs
+++ b/src/Business/Grand.Business.Checkout/Services/Orders/ShoppingCartService.cs
@@ -22,14 +22,14 @@ public class ShoppingCartService : IShoppingCartService
#region Ctor
public ShoppingCartService(
- IWorkContextAccessor workContextAccessor,
+ IContextAccessor contextAccessor,
IProductService productService,
ICustomerService customerService,
IMediator mediator,
IShoppingCartValidator shoppingCartValidator,
ShoppingCartSettings shoppingCartSettings)
{
- _workContextAccessor = workContextAccessor;
+ _contextAccessor = contextAccessor;
_productService = productService;
_customerService = customerService;
_mediator = mediator;
@@ -41,7 +41,7 @@ public class ShoppingCartService : IShoppingCartService
#region Fields
- private readonly IWorkContextAccessor _workContextAccessor;
+ private readonly IContextAccessor _contextAccessor;
private readonly IProductService _productService;
private readonly ICustomerService _customerService;
private readonly IMediator _mediator;
@@ -62,7 +62,7 @@ public class ShoppingCartService : IShoppingCartService
params ShoppingCartType[] shoppingCartType)
{
var model = new List<ShoppingCartItem>();
- var cart = _workContextAccessor.WorkContext.CurrentCustomer.ShoppingCartItems.ToList();
+ var cart = _contextAccessor.WorkContext.CurrentCustomer.ShoppingCartItems.ToList();
if (!string.IsNullOrEmpty(storeId))
cart = cart.LimitPerStore(_shoppingCartSettings.SharedCartBetweenStores, storeId).ToList();
@@ -431,9 +431,9 @@ public class ShoppingCartService : IShoppingCartService
}
//move selected checkout attributes
- var checkoutAttributes = fromCustomer.GetUserFieldFromEntity<List<CustomAttribute>>(SystemCustomerFieldNames.CheckoutAttributes, _workContextAccessor.WorkContext.CurrentStore.Id);
+ var checkoutAttributes = fromCustomer.GetUserFieldFromEntity<List<CustomAttribute>>(SystemCustomerFieldNames.CheckoutAttributes, _contextAccessor.StoreContext.CurrentStore.Id);
await _customerService.UpdateUserField(toCustomer, SystemCustomerFieldNames.CheckoutAttributes, checkoutAttributes,
- _workContextAccessor.WorkContext.CurrentStore.Id);
+ _contextAccessor.StoreContext.CurrentStore.Id);
}
#endregion
diff --git a/src/Business/Grand.Business.Checkout/Services/Orders/ShoppingCartValidator.cs b/src/Business/Grand.Business.Checkout/Services/Orders/ShoppingCartValidator.cs
index 4391b1f72..fb59abede 100644
--- a/src/Business/Grand.Business.Checkout/Services/Orders/ShoppingCartValidator.cs
+++ b/src/Business/Grand.Business.Checkout/Services/Orders/ShoppingCartValidator.cs
@@ -17,14 +17,14 @@ public class ShoppingCartValidator : IShoppingCartValidator
private readonly IMediator _mediator;
private readonly IValidatorFactory _validatorFactory;
- private readonly IWorkContextAccessor _workContextAccessor;
+ private readonly IContextAccessor _contextAccessor;
public ShoppingCartValidator(
- IWorkContextAccessor workContextAccessor,
+ IContextAccessor contextAccessor,
IMediator mediator,
IValidatorFactory validatorFactory)
{
- _workContextAccessor = workContextAccessor;
+ _contextAccessor = contextAccessor;
_mediator = mediator;
_validatorFactory = validatorFactory;
}
@@ -128,8 +128,8 @@ public class ShoppingCartValidator : IShoppingCartValidator
checkoutAttributes ??= new List<CustomAttribute>();
var result = await _validatorFactory.GetValidator<ShoppingCartWarningsValidatorRecord>()
- .ValidateAsync(new ShoppingCartWarningsValidatorRecord(_workContextAccessor.WorkContext.CurrentCustomer,
- _workContextAccessor.WorkContext.CurrentStore, shoppingCart));
+ .ValidateAsync(new ShoppingCartWarningsValidatorRecord(_contextAccessor.WorkContext.CurrentCustomer,
+ _contextAccessor.StoreContext.CurrentStore, shoppingCart));
if (!result.IsValid)
warnings.AddRange(result.Errors.Select(x => x.ErrorMessage));
@@ -138,8 +138,8 @@ public class ShoppingCartValidator : IShoppingCartValidator
{
var resultCheckoutAttributes = await _validatorFactory
.GetValidator<ShoppingCartCheckoutAttributesValidatorRecord>().ValidateAsync(
- new ShoppingCartCheckoutAttributesValidatorRecord(_workContextAccessor.WorkContext.CurrentCustomer,
- _workContextAccessor.WorkContext.CurrentStore,
+ new ShoppingCartCheckoutAttributesValidatorRecord(_contextAccessor.WorkContext.CurrentCustomer,
+ _contextAccessor.StoreContext.CurrentStore,
shoppingCart, checkoutAttributes));
if (!resultCheckoutAttributes.IsValid)
warnings.AddRange(resultCheckoutAttributes.Errors.Select(x => x.ErrorMessage));
@@ -150,8 +150,8 @@ public class ShoppingCartValidator : IShoppingCartValidator
{
var resultCheckoutAttributes = await _validatorFactory
.GetValidator<ShoppingCartTotalAmountValidatorRecord>().ValidateAsync(
- new ShoppingCartTotalAmountValidatorRecord(_workContextAccessor.WorkContext.CurrentCustomer,
- _workContextAccessor.WorkContext.WorkingCurrency, shoppingCart));
+ new ShoppingCartTotalAmountValidatorRecord(_contextAccessor.WorkContext.CurrentCustomer,
+ _contextAccessor.WorkContext.WorkingCurrency, shoppingCart));
if (!resultCheckoutAttributes.IsValid)
warnings.AddRange(resultCheckoutAttributes.Errors.Select(x => x.ErrorMessage));
}
@@ -170,7 +170,7 @@ public class ShoppingCartValidator : IShoppingCartValidator
var warnings = new List<string>();
var result = await _validatorFactory.GetValidator<ShoppingCartCommonWarningsValidatorRecord>().ValidateAsync(
- new ShoppingCartCommonWarningsValidatorRecord(customer, _workContextAccessor.WorkContext.CurrentStore, currentCart,
+ new ShoppingCartCommonWarningsValidatorRecord(customer, _contextAccessor.StoreContext.CurrentStore, currentCart,
product, shoppingCartType, rentalStartDate, rentalEndDate, quantity, reservationId));
if (!result.IsValid)
warnings.AddRange(result.Errors.Select(x => x.ErrorMessage));
@@ -228,8 +228,8 @@ public class ShoppingCartValidator : IShoppingCartValidator
if (!product.RequireOtherProducts) return warnings;
var result = await _validatorFactory.GetValidator<ShoppingCartRequiredProductValidatorRecord>()
- .ValidateAsync(new ShoppingCartRequiredProductValidatorRecord(_workContextAccessor.WorkContext.CurrentCustomer,
- _workContextAccessor.WorkContext.CurrentStore, product, shoppingCartItem));
+ .ValidateAsync(new ShoppingCartRequiredProductValidatorRecord(_contextAccessor.WorkContext.CurrentCustomer,
+ _contextAccessor.StoreContext.CurrentStore, product, shoppingCartItem));
if (!result.IsValid)
warnings.AddRange(result.Errors.Select(x => x.ErrorMessage));
return warnings;
diff --git a/src/Business/Grand.Business.Cms/Services/KnowledgebaseService.cs b/src/Business/Grand.Business.Cms/Services/KnowledgebaseService.cs
index df35f933b..5da0ee58d 100644
--- a/src/Business/Grand.Business.Cms/Services/KnowledgebaseService.cs
+++ b/src/Business/Grand.Business.Cms/Services/KnowledgebaseService.cs
@@ -1,14 +1,18 @@
using Grand.Business.Core.Interfaces.Cms;
using Grand.Data;
using Grand.Domain;
+using Grand.Domain.Catalog;
using Grand.Domain.Customers;
using Grand.Domain.Knowledgebase;
+using Grand.Domain.Permissions;
+using Grand.Domain.Stores;
using Grand.Infrastructure;
using Grand.Infrastructure.Caching;
using Grand.Infrastructure.Caching.Constants;
using Grand.Infrastructure.Configuration;
using Grand.Infrastructure.Extensions;
using MediatR;
+using static Microsoft.Extensions.Logging.EventSource.LoggingEventSource;
namespace Grand.Business.Cms.Services;
@@ -20,7 +24,7 @@ public class KnowledgebaseService : IKnowledgebaseService
private readonly IRepository<KnowledgebaseArticle> _knowledgebaseArticleRepository;
private readonly IRepository<KnowledgebaseCategory> _knowledgebaseCategoryRepository;
private readonly IMediator _mediator;
- private readonly IWorkContextAccessor _workContextAccessor;
+ private readonly IContextAccessor _contextAccessor;
/// <summary>
/// Ctor
@@ -30,18 +34,53 @@ public class KnowledgebaseService : IKnowledgebaseService
IRepository<KnowledgebaseArticle> knowledgebaseArticleRepository,
IRepository<KnowledgebaseArticleComment> articleCommentRepository,
IMediator mediator,
- IWorkContextAccessor workContextAccessor,
+ IContextAccessor contextAccessor,
ICacheBase cacheBase, AccessControlConfig accessControlConfig)
{
_knowledgebaseCategoryRepository = knowledgebaseCategoryRepository;
_knowledgebaseArticleRepository = knowledgebaseArticleRepository;
_articleCommentRepository = articleCommentRepository;
_mediator = mediator;
- _workContextAccessor = workContextAccessor;
+ _contextAccessor = contextAccessor;
_cacheBase = cacheBase;
_accessControlConfig = accessControlConfig;
}
+ private IQueryable<T> ApplyStandardFilter<T>(IQueryable<T> query) where T : BaseEntity, IGroupLinkEntity, IStoreLinkEntity
+ {
+ if (!_accessControlConfig.IgnoreAcl)
+ {
+ var allowedCustomerGroupsIds = _contextAccessor.WorkContext.CurrentCustomer.GetCustomerGroupIds();
+ query = from p in query
+ where !p.LimitedToGroups || allowedCustomerGroupsIds.Any(x => p.CustomerGroups.Contains(x))
+ select p;
+ }
+
+ if (!_accessControlConfig.IgnoreStoreLimitations)
+ {
+ query = from p in query
+ where !p.LimitedToStores || p.Stores.Contains(_contextAccessor.StoreContext.CurrentStore.Id)
+ select p;
+ }
+
+ return query;
+ }
+
+ private string GetCacheKey(string format, params object[] additionalParams)
+ {
+ var standardParams = new[]
+ {
+ string.Join(",", _contextAccessor.WorkContext.CurrentCustomer.GetCustomerGroupIds()),
+ _contextAccessor.StoreContext.CurrentStore.Id
+ };
+
+ var allParams = additionalParams != null
+ ? standardParams.Concat(additionalParams).ToArray()
+ : standardParams;
+
+ return string.Format(format, allParams);
+ }
+
/// <summary>
/// Deletes knowledge base category
/// </summary>
@@ -91,32 +130,16 @@ public class KnowledgebaseService : IKnowledgebaseService
/// <returns>knowledge base category</returns>
public virtual async Task<KnowledgebaseCategory> GetPublicKnowledgebaseCategory(string id)
{
- var key = string.Format(CacheKey.KNOWLEDGEBASE_CATEGORY_BY_ID, id,
- _workContextAccessor.WorkContext.CurrentCustomer.GetCustomerGroupIds(),
- _workContextAccessor.WorkContext.CurrentStore.Id);
+ var key = GetCacheKey(CacheKey.KNOWLEDGEBASE_CATEGORY_BY_ID, id);
+
return await _cacheBase.GetAsync(key, async () =>
{
var query = from p in _knowledgebaseCategoryRepository.Table
- select p;
+ select p;
query = query.Where(x => x.Published);
query = query.Where(x => x.Id == id);
-
- if (!_accessControlConfig.IgnoreAcl)
- {
- //Limited to customer groups rules
- var allowedCustomerGroupsIds = _workContextAccessor.WorkContext.CurrentCustomer.GetCustomerGroupIds();
- query = from p in query
- where !p.LimitedToGroups || allowedCustomerGroupsIds.Any(x => p.CustomerGroups.Contains(x))
- select p;
- }
-
- if (!_accessControlConfig.IgnoreStoreLimitations)
- //Store acl
- query = from p in query
- where !p.LimitedToStores || p.Stores.Contains(_workContextAccessor.WorkContext.CurrentStore.Id)
- select p;
-
+ query = ApplyStandardFilter(query);
var toReturn = await Task.FromResult(query.FirstOrDefault());
return toReturn;
});
@@ -165,20 +188,8 @@ public class KnowledgebaseService : IKnowledgebaseService
public virtual async Task<List<KnowledgebaseArticle>> GetKnowledgebaseArticles(string storeId = "")
{
var query = from p in _knowledgebaseArticleRepository.Table
- select p;
- if (!_accessControlConfig.IgnoreAcl)
- {
- var allowedCustomerGroupsIds = _workContextAccessor.WorkContext.CurrentCustomer.GetCustomerGroupIds();
- query = from p in query
- where !p.LimitedToGroups || allowedCustomerGroupsIds.Any(x => p.CustomerGroups.Contains(x))
- select p;
- }
-
- if (!_accessControlConfig.IgnoreStoreLimitations && !string.IsNullOrEmpty(storeId))
- //Limited to stores rules
- query = from p in query
- where !p.LimitedToStores || p.Stores.Contains(storeId)
- select p;
+ select p;
+ query = ApplyStandardFilter(query);
query = query.OrderBy(x => x.DisplayOrder);
return await Task.FromResult(query.ToList());
}
@@ -239,29 +250,16 @@ public class KnowledgebaseService : IKnowledgebaseService
/// <returns>List of public knowledgebase categories</returns>
public virtual async Task<List<KnowledgebaseCategory>> GetPublicKnowledgebaseCategories()
{
- var key = string.Format(CacheKey.KNOWLEDGEBASE_CATEGORIES,
- string.Join(",", _workContextAccessor.WorkContext.CurrentCustomer.GetCustomerGroupIds()),
- _workContextAccessor.WorkContext.CurrentStore.Id);
+ var key = GetCacheKey(CacheKey.KNOWLEDGEBASE_CATEGORIES);
+
return await _cacheBase.GetAsync(key, async () =>
{
var query = from p in _knowledgebaseCategoryRepository.Table
- select p;
+ select p;
query = query.Where(x => x.Published);
- if (!_accessControlConfig.IgnoreAcl)
- {
- var allowedCustomerGroupsIds = _workContextAccessor.WorkContext.CurrentCustomer.GetCustomerGroupIds();
- query = from p in query
- where !p.LimitedToGroups || allowedCustomerGroupsIds.Any(x => p.CustomerGroups.Contains(x))
- select p;
- }
-
- if (!_accessControlConfig.IgnoreStoreLimitations)
- //Store acl
- query = from p in query
- where !p.LimitedToStores || p.Stores.Contains(_workContextAccessor.WorkContext.CurrentStore.Id)
- select p;
+ query = ApplyStandardFilter(query);
query = query.OrderBy(x => x.DisplayOrder);
return await Task.FromResult(query.ToList());
});
@@ -273,29 +271,15 @@ public class KnowledgebaseService : IKnowledgebaseService
/// <returns>List of public knowledge base articles</returns>
public virtual async Task<List<KnowledgebaseArticle>> GetPublicKnowledgebaseArticles()
{
- var key = string.Format(CacheKey.ARTICLES, string.Join(",", _workContextAccessor.WorkContext.CurrentCustomer.GetCustomerGroupIds()),
- _workContextAccessor.WorkContext.CurrentStore.Id);
+ var key = GetCacheKey(CacheKey.ARTICLES);
return await _cacheBase.GetAsync(key, async () =>
{
var query = from p in _knowledgebaseArticleRepository.Table
- select p;
+ select p;
query = query.Where(x => x.Published);
-
- if (!_accessControlConfig.IgnoreAcl)
- {
- var allowedCustomerGroupsIds = _workContextAccessor.WorkContext.CurrentCustomer.GetCustomerGroupIds();
- query = from p in query
- where !p.LimitedToGroups || allowedCustomerGroupsIds.Any(x => p.CustomerGroups.Contains(x))
- select p;
- }
-
- if (!_accessControlConfig.IgnoreStoreLimitations)
- //Store acl
- query = from p in query
- where !p.LimitedToStores || p.Stores.Contains(_workContextAccessor.WorkContext.CurrentStore.Id)
- select p;
+ query = ApplyStandardFilter(query);
query = query.OrderBy(x => x.DisplayOrder);
return await Task.FromResult(query.ToList());
@@ -308,31 +292,16 @@ public class KnowledgebaseService : IKnowledgebaseService
/// <returns>knowledge base article</returns>
public virtual async Task<KnowledgebaseArticle> GetPublicKnowledgebaseArticle(string id)
{
- var key = string.Format(CacheKey.ARTICLE_BY_ID, id,
- string.Join(",", _workContextAccessor.WorkContext.CurrentCustomer.GetCustomerGroupIds()),
- _workContextAccessor.WorkContext.CurrentStore.Id);
+ var key = GetCacheKey(CacheKey.ARTICLE_BY_ID, id);
+
return await _cacheBase.GetAsync(key, async () =>
{
var query = from p in _knowledgebaseArticleRepository.Table
- select p;
+ select p;
query = query.Where(x => x.Published);
query = query.Where(x => x.Id == id);
-
- if (!_accessControlConfig.IgnoreAcl)
- {
- var allowedCustomerGroupsIds = _workContextAccessor.WorkContext.CurrentCustomer.GetCustomerGroupIds();
- query = from p in query
- where !p.LimitedToGroups || allowedCustomerGroupsIds.Any(x => p.CustomerGroups.Contains(x))
- select p;
- }
-
- if (!_accessControlConfig.IgnoreStoreLimitations)
- //Store acl
- query = from p in query
- where !p.LimitedToStores || p.Stores.Contains(_workContextAccessor.WorkContext.CurrentStore.Id)
- select p;
-
+ query = ApplyStandardFilter(query);
return await Task.FromResult(query.FirstOrDefault());
});
}
@@ -343,30 +312,17 @@ public class KnowledgebaseService : IKnowledgebaseService
/// <returns>List of public knowledge base articles</returns>
public virtual async Task<List<KnowledgebaseArticle>> GetPublicKnowledgebaseArticlesByCategory(string categoryId)
{
- var key = string.Format(CacheKey.ARTICLES_BY_CATEGORY_ID, categoryId,
- string.Join(",", _workContextAccessor.WorkContext.CurrentCustomer.GetCustomerGroupIds()),
- _workContextAccessor.WorkContext.CurrentStore.Id);
+ var key = GetCacheKey(CacheKey.ARTICLES_BY_CATEGORY_ID, categoryId);
+
return await _cacheBase.GetAsync(key, async () =>
{
var query = from p in _knowledgebaseArticleRepository.Table
- select p;
+ select p;
query = query.Where(x => x.Published);
query = query.Where(x => x.ParentCategoryId == categoryId);
- if (!_accessControlConfig.IgnoreAcl)
- {
- var allowedCustomerGroupsIds = _workContextAccessor.WorkContext.CurrentCustomer.GetCustomerGroupIds();
- query = from p in query
- where !p.LimitedToGroups || allowedCustomerGroupsIds.Any(x => p.CustomerGroups.Contains(x))
- select p;
- }
-
- if (!_accessControlConfig.IgnoreStoreLimitations)
- //Store acl
- query = from p in query
- where !p.LimitedToStores || p.Stores.Contains(_workContextAccessor.WorkContext.CurrentStore.Id)
- select p;
+ query = ApplyStandardFilter(query);
query = query.OrderBy(x => x.DisplayOrder);
return await Task.FromResult(query.ToList());
});
@@ -378,14 +334,12 @@ public class KnowledgebaseService : IKnowledgebaseService
/// <returns>List of public knowledge base articles</returns>
public virtual async Task<List<KnowledgebaseArticle>> GetPublicKnowledgebaseArticlesByKeyword(string keyword)
{
- var key = string.Format(CacheKey.ARTICLES_BY_KEYWORD, keyword,
- string.Join(",", _workContextAccessor.WorkContext.CurrentCustomer.GetCustomerGroupIds()),
- _workContextAccessor.WorkContext.CurrentStore.Id);
+ var key = GetCacheKey(CacheKey.ARTICLES_BY_KEYWORD, keyword);
return await _cacheBase.GetAsync(key, async () =>
{
var query = from p in _knowledgebaseArticleRepository.Table
- select p;
+ select p;
query = query.Where(x => x.Published);
@@ -393,19 +347,7 @@ public class KnowledgebaseService : IKnowledgebaseService
p.Locales.Any(x => x.LocaleValue != null && x.LocaleValue.ToLower().Contains(keyword.ToLower()))
|| p.Name.ToLower().Contains(keyword.ToLower()) || p.Content.ToLower().Contains(keyword.ToLower()));
- if (!_accessControlConfig.IgnoreAcl)
- {
- var allowedCustomerGroupsIds = _workContextAccessor.WorkContext.CurrentCustomer.GetCustomerGroupIds();
- query = from p in query
- where !p.LimitedToGroups || allowedCustomerGroupsIds.Any(x => p.CustomerGroups.Contains(x))
- select p;
- }
-
- if (!_accessControlConfig.IgnoreStoreLimitations)
- //Store acl
- query = from p in query
- where !p.LimitedToStores || p.Stores.Contains(_workContextAccessor.WorkContext.CurrentStore.Id)
- select p;
+ query = ApplyStandardFilter(query);
query = query.OrderBy(x => x.DisplayOrder);
return await Task.FromResult(query.ToList());
});
@@ -417,13 +359,12 @@ public class KnowledgebaseService : IKnowledgebaseService
/// <returns>List of public knowledge base categories</returns>
public virtual async Task<List<KnowledgebaseCategory>> GetPublicKnowledgebaseCategoriesByKeyword(string keyword)
{
- var key = string.Format(CacheKey.KNOWLEDGEBASE_CATEGORIES_BY_KEYWORD, keyword,
- string.Join(",", _workContextAccessor.WorkContext.CurrentCustomer.GetCustomerGroupIds()),
- _workContextAccessor.WorkContext.CurrentStore.Id);
+ var key = GetCacheKey(CacheKey.KNOWLEDGEBASE_CATEGORIES_BY_KEYWORD, keyword);
+
return await _cacheBase.GetAsync(key, async () =>
{
var query = from p in _knowledgebaseCategoryRepository.Table
- select p;
+ select p;
query = query.Where(x => x.Published);
@@ -431,19 +372,7 @@ public class KnowledgebaseService : IKnowledgebaseService
p.Locales.Any(x => x.LocaleValue != null && x.LocaleValue.ToLower().Contains(keyword.ToLower()))
|| p.Name.ToLower().Contains(keyword.ToLower()) || p.Description.ToLower().Contains(keyword.ToLower()));
- if (!_accessControlConfig.IgnoreAcl)
- {
- var allowedCustomerGroupsIds = _workContextAccessor.WorkContext.CurrentCustomer.GetCustomerGroupIds();
- query = from p in query
- where !p.LimitedToGroups || allowedCustomerGroupsIds.Any(x => p.CustomerGroups.Contains(x))
- select p;
- }
-
- if (!_accessControlConfig.IgnoreStoreLimitations)
- //Store acl
- query = from p in query
- where !p.LimitedToStores || p.Stores.Contains(_workContextAccessor.WorkContext.CurrentStore.Id)
- select p;
+ query = ApplyStandardFilter(query);
query = query.OrderBy(x => x.DisplayOrder);
return await Task.FromResult(query.ToList());
});
@@ -455,30 +384,16 @@ public class KnowledgebaseService : IKnowledgebaseService
/// <returns>List of homepage knowledge base articles</returns>
public virtual async Task<List<KnowledgebaseArticle>> GetHomepageKnowledgebaseArticles()
{
- var key = string.Format(CacheKey.HOMEPAGE_ARTICLES,
- string.Join(",", _workContextAccessor.WorkContext.CurrentCustomer.GetCustomerGroupIds()),
- _workContextAccessor.WorkContext.CurrentStore.Id);
+ var key = GetCacheKey(CacheKey.HOMEPAGE_ARTICLES);
+
return await _cacheBase.GetAsync(key, async () =>
{
var query = from p in _knowledgebaseArticleRepository.Table
- select p;
+ select p;
query = query.Where(x => x.Published);
query = query.Where(x => x.ShowOnHomepage);
-
- if (!_accessControlConfig.IgnoreAcl)
- {
- var allowedCustomerGroupsIds = _workContextAccessor.WorkContext.CurrentCustomer.GetCustomerGroupIds();
- query = from p in query
- where !p.LimitedToGroups || allowedCustomerGroupsIds.Any(x => p.CustomerGroups.Contains(x))
- select p;
- }
-
- if (!_accessControlConfig.IgnoreStoreLimitations)
- //Store acl
- query = from p in query
- where !p.LimitedToStores || p.Stores.Contains(_workContextAccessor.WorkContext.CurrentStore.Id)
- select p;
+ query = ApplyStandardFilter(query);
query = query.OrderBy(x => x.DisplayOrder);
return await Task.FromResult(query.ToList());
});
@@ -494,8 +409,7 @@ public class KnowledgebaseService : IKnowledgebaseService
int pageIndex = 0, int pageSize = int.MaxValue)
{
var query = from p in _knowledgebaseArticleRepository.Table
- select p;
-
+ select p;
query = query.Where(x => x.Published);
@@ -547,9 +461,9 @@ public class KnowledgebaseService : IKnowledgebaseService
public virtual async Task<IList<KnowledgebaseArticleComment>> GetArticleCommentsByArticleId(string articleId)
{
var query = from c in _articleCommentRepository.Table
- where c.ArticleId == articleId
- orderby c.CreatedOnUtc
- select c;
+ where c.ArticleId == articleId
+ orderby c.CreatedOnUtc
+ select c;
return await Task.FromResult(query.ToList());
}
@@ -568,9 +482,9 @@ public class KnowledgebaseService : IKnowledgebaseService
public virtual async Task<IList<KnowledgebaseArticleComment>> GetAllComments(string customerId)
{
var query = from c in _articleCommentRepository.Table
- orderby c.CreatedOnUtc
- where customerId == "" || c.CustomerId == customerId
- select c;
+ orderby c.CreatedOnUtc
+ where customerId == "" || c.CustomerId == customerId
+ select c;
return await Task.FromResult(query.ToList());
}
@@ -594,8 +508,8 @@ public class KnowledgebaseService : IKnowledgebaseService
return new List<KnowledgebaseArticleComment>();
var query = from bc in _articleCommentRepository.Table
- where commentIds.Contains(bc.Id)
- select bc;
+ where commentIds.Contains(bc.Id)
+ select bc;
var comments = query.ToList();
//sort by passed identifiers
var sortedComments = new List<KnowledgebaseArticleComment>();
diff --git a/src/Business/Grand.Business.Cms/Services/NewsService.cs b/src/Business/Grand.Business.Cms/Services/NewsService.cs
index 31145a467..567b7a9d1 100644
--- a/src/Business/Grand.Business.Cms/Services/NewsService.cs
+++ b/src/Business/Grand.Business.Cms/Services/NewsService.cs
@@ -19,11 +19,11 @@ public class NewsService : INewsService
public NewsService(IRepository<NewsItem> newsItemRepository,
IMediator mediator,
- IWorkContextAccessor workContextAccessor, AccessControlConfig accessControlConfig)
+ IContextAccessor contextAccessor, AccessControlConfig accessControlConfig)
{
_newsItemRepository = newsItemRepository;
_mediator = mediator;
- _workContextAccessor = workContextAccessor;
+ _contextAccessor = contextAccessor;
_accessControlConfig = accessControlConfig;
}
@@ -33,7 +33,7 @@ public class NewsService : INewsService
private readonly IRepository<NewsItem> _newsItemRepository;
private readonly IMediator _mediator;
- private readonly IWorkContextAccessor _workContextAccessor;
+ private readonly IContextAccessor _contextAccessor;
private readonly AccessControlConfig _accessControlConfig;
#endregion
@@ -83,7 +83,7 @@ public class NewsService : INewsService
{
if (!ignoreAcl && !_accessControlConfig.IgnoreAcl)
{
- var allowedCustomerGroupsIds = _workContextAccessor.WorkContext.CurrentCustomer.GetCustomerGroupIds();
+ var allowedCustomerGroupsIds = _contextAccessor.WorkContext.CurrentCustomer.GetCustomerGroupIds();
query = from p in query
where !p.LimitedToGroups || allowedCustomerGroupsIds.Any(x => p.CustomerGroups.Contains(x))
select p;
diff --git a/src/Business/Grand.Business.Cms/Services/PageService.cs b/src/Business/Grand.Business.Cms/Services/PageService.cs
index ce98ac7b1..aaaac3b65 100644
--- a/src/Business/Grand.Business.Cms/Services/PageService.cs
+++ b/src/Business/Grand.Business.Cms/Services/PageService.cs
@@ -20,13 +20,13 @@ public class PageService : IPageService
#region Ctor
public PageService(IRepository<Page> pageRepository,
- IWorkContextAccessor workContextAccessor,
+ IContextAccessor contextAccessor,
IAclService aclService,
IMediator mediator,
ICacheBase cacheBase, AccessControlConfig accessControlConfig)
{
_pageRepository = pageRepository;
- _workContextAccessor = workContextAccessor;
+ _contextAccessor = contextAccessor;
_aclService = aclService;
_mediator = mediator;
_cacheBase = cacheBase;
@@ -38,7 +38,7 @@ public class PageService : IPageService
#region Fields
private readonly IRepository<Page> _pageRepository;
- private readonly IWorkContextAccessor _workContextAccessor;
+ private readonly IContextAccessor _contextAccessor;
private readonly IAclService _aclService;
private readonly IMediator _mediator;
private readonly ICacheBase _cacheBase;
@@ -105,7 +105,7 @@ public class PageService : IPageService
{
if (!ignoreAcl && !_accessControlConfig.IgnoreAcl)
{
- var allowedCustomerGroupsIds = _workContextAccessor.WorkContext.CurrentCustomer.GetCustomerGroupIds();
+ var allowedCustomerGroupsIds = _contextAccessor.WorkContext.CurrentCustomer.GetCustomerGroupIds();
query = from p in query
where !p.LimitedToGroups || allowedCustomerGroupsIds.Any(x => p.CustomerGroups.Contains(x))
select p;
diff --git a/src/Business/Grand.Business.Common/Services/Configuration/SettingService.cs b/src/Business/Grand.Business.Common/Services/Configuration/SettingService.cs
index 443e7f4ad..fadc0d2da 100644
--- a/src/Business/Grand.Business.Common/Services/Configuration/SettingService.cs
+++ b/src/Business/Grand.Business.Common/Services/Configuration/SettingService.cs
@@ -206,7 +206,7 @@ public class SettingService : ISettingService
if (setting == null && !string.IsNullOrEmpty(storeId))
setting = settings.FirstOrDefault(x => string.IsNullOrEmpty(x.StoreId));
- if (setting != null)
+ if (setting != null)
return JsonSerializer.Deserialize(setting.Metadata, type) as ISettings;
return Activator.CreateInstance(type) as ISettings;
diff --git a/src/Business/Grand.Business.Common/Services/Localization/TranslationService.cs b/src/Business/Grand.Business.Common/Services/Localization/TranslationService.cs
index d7dd4b0df..9e531bb0f 100644
--- a/src/Business/Grand.Business.Common/Services/Localization/TranslationService.cs
+++ b/src/Business/Grand.Business.Common/Services/Localization/TranslationService.cs
@@ -24,11 +24,11 @@ public class TranslationService : ITranslationService
/// <param name="trRepository">Translate resource repository</param>
/// <param name="mediator">Mediator</param>
public TranslationService(
- IWorkContextAccessor workContextAccessor,
+ IContextAccessor contextAccessor,
IRepository<TranslationResource> trRepository,
IMediator mediator)
{
- _workContextAccessor = workContextAccessor;
+ _contextAccessor = contextAccessor;
_translationRepository = trRepository;
_mediator = mediator;
}
@@ -40,7 +40,7 @@ public class TranslationService : ITranslationService
private static readonly ConcurrentDictionary<string, IDictionary<string, string>> _cachedResources = new();
private readonly IRepository<TranslationResource> _translationRepository;
- private readonly IWorkContextAccessor _workContextAccessor;
+ private readonly IContextAccessor _contextAccessor;
private readonly IMediator _mediator;
#endregion
@@ -143,7 +143,7 @@ public class TranslationService : ITranslationService
/// <returns>A string representing the requested resource string.</returns>
public virtual string GetResource(string name)
{
- return _workContextAccessor.WorkContext.WorkingLanguage != null ? GetResource(name, _workContextAccessor.WorkContext.WorkingLanguage.Id) : "";
+ return _contextAccessor.WorkContext.WorkingLanguage != null ? GetResource(name, _contextAccessor.WorkContext.WorkingLanguage.Id) : "";
}
/// <summary>
@@ -249,7 +249,7 @@ public class TranslationService : ITranslationService
Name = item.Name.ToLowerInvariant(),
Value = item.Value,
Area = areaEnum,
- CreatedBy = _workContextAccessor.WorkContext.CurrentCustomer.Email
+ CreatedBy = _contextAccessor.WorkContext.CurrentCustomer.Email
});
}
}
diff --git a/src/Business/Grand.Business.Common/Services/Security/PermissionService.cs b/src/Business/Grand.Business.Common/Services/Security/PermissionService.cs
index 6c8479b66..4b3b3dff8 100644
--- a/src/Business/Grand.Business.Common/Services/Security/PermissionService.cs
+++ b/src/Business/Grand.Business.Common/Services/Security/PermissionService.cs
@@ -27,13 +27,13 @@ public class PermissionService : IPermissionService
public PermissionService(
IRepository<Permission> permissionRepository,
IRepository<PermissionAction> permissionActionRepository,
- IWorkContextAccessor workContextAccessor,
+ IContextAccessor contextAccessor,
IGroupService groupService,
ICacheBase cacheBase)
{
_permissionRepository = permissionRepository;
_permissionActionRepository = permissionActionRepository;
- _workContextAccessor = workContextAccessor;
+ _contextAccessor = contextAccessor;
_groupService = groupService;
_cacheBase = cacheBase;
}
@@ -69,7 +69,7 @@ public class PermissionService : IPermissionService
private readonly IRepository<Permission> _permissionRepository;
private readonly IRepository<PermissionAction> _permissionActionRepository;
- private readonly IWorkContextAccessor _workContextAccessor;
+ private readonly IContextAccessor _contextAccessor;
private readonly IGroupService _groupService;
private readonly ICacheBase _cacheBase;
@@ -162,7 +162,7 @@ public class PermissionService : IPermissionService
/// <returns>true - authorized; otherwise, false</returns>
public virtual async Task<bool> Authorize(Permission permission)
{
- return await Authorize(permission, _workContextAccessor.WorkContext.CurrentCustomer);
+ return await Authorize(permission, _contextAccessor.WorkContext.CurrentCustomer);
}
/// <summary>
@@ -189,7 +189,7 @@ public class PermissionService : IPermissionService
/// <returns>true - authorized; otherwise, false</returns>
public virtual async Task<bool> Authorize(string permissionSystemName)
{
- return await Authorize(permissionSystemName, _workContextAccessor.WorkContext.CurrentCustomer);
+ return await Authorize(permissionSystemName, _contextAccessor.WorkContext.CurrentCustomer);
}
/// <summary>
@@ -267,7 +267,7 @@ public class PermissionService : IPermissionService
if (!await Authorize(permissionSystemName))
return false;
- var customerGroups = await _groupService.GetAllByIds(_workContextAccessor.WorkContext.CurrentCustomer.Groups.ToArray());
+ var customerGroups = await _groupService.GetAllByIds(_contextAccessor.WorkContext.CurrentCustomer.Groups.ToArray());
foreach (var group in customerGroups)
{
if (!await Authorize(permissionSystemName, group))
diff --git a/src/Business/Grand.Business.Common/Services/Stores/StoreService.cs b/src/Business/Grand.Business.Common/Services/Stores/StoreService.cs
index 051dcaa49..9ede97eba 100644
--- a/src/Business/Grand.Business.Common/Services/Stores/StoreService.cs
+++ b/src/Business/Grand.Business.Common/Services/Stores/StoreService.cs
@@ -1,3 +1,5 @@
+#nullable enable
+
using Grand.Business.Core.Interfaces.Common.Stores;
using Grand.Data;
using Grand.Domain.Stores;
@@ -38,8 +40,6 @@ public class StoreService : IStoreService
private readonly IMediator _mediator;
private readonly ICacheBase _cacheBase;
- private List<Store> _allStores;
-
#endregion
#region Methods
@@ -50,7 +50,7 @@ public class StoreService : IStoreService
/// <returns>Stores</returns>
public virtual async Task<IList<Store>> GetAllStores()
{
- return _allStores ??= await _cacheBase.GetAsync(CacheKey.STORES_ALL_KEY, async () =>
+ return await _cacheBase.GetAsync(CacheKey.STORES_ALL_KEY, async () =>
{
return await Task.FromResult(_storeRepository.Table.OrderBy(x => x.DisplayOrder).ToList());
});
@@ -121,6 +121,16 @@ public class StoreService : IStoreService
//event notification
await _mediator.EntityDeleted(store);
}
+ /// <summary>
+ /// Get store by host
+ /// </summary>
+ /// <param name="host"></param>
+ /// <returns></returns>
+ public async Task<Store?> GetStoreByHost(string host)
+ {
+ var allStores = await GetAllStores();
+ return allStores.FirstOrDefault(s => s.ContainsHostValue(host));
+ }
#endregion
}
\ No newline at end of file
diff --git a/src/Business/Grand.Business.Core/Extensions/TranslateExtensions.cs b/src/Business/Grand.Business.Core/Extensions/TranslateExtensions.cs
index c665cd36f..37b9573e3 100644
--- a/src/Business/Grand.Business.Core/Extensions/TranslateExtensions.cs
+++ b/src/Business/Grand.Business.Core/Extensions/TranslateExtensions.cs
@@ -67,12 +67,12 @@ public static class TranslateExtensions
/// <returns>Translation value</returns>
public static string GetTranslationEnum<T>(this T enumValue,
ITranslationService translationService,
- IWorkContextAccessor workContextAccessor)
+ IContextAccessor contextAccessor)
where T : struct
{
- ArgumentNullException.ThrowIfNull(workContextAccessor);
+ ArgumentNullException.ThrowIfNull(contextAccessor);
- return GetTranslationEnum(enumValue, translationService, workContextAccessor.WorkContext.WorkingLanguage.Id);
+ return GetTranslationEnum(enumValue, translationService, contextAccessor.WorkContext.WorkingLanguage.Id);
}
/// <summary>
diff --git a/src/Business/Grand.Business.Core/Interfaces/Common/Stores/IStoreService.cs b/src/Business/Grand.Business.Core/Interfaces/Common/Stores/IStoreService.cs
index 446386370..80e5d7b13 100644
--- a/src/Business/Grand.Business.Core/Interfaces/Common/Stores/IStoreService.cs
+++ b/src/Business/Grand.Business.Core/Interfaces/Common/Stores/IStoreService.cs
@@ -1,3 +1,5 @@
+#nullable enable
+
using Grand.Domain.Stores;
namespace Grand.Business.Core.Interfaces.Common.Stores;
@@ -37,4 +39,11 @@ public interface IStoreService
/// </summary>
/// <param name="store">Store</param>
Task DeleteStore(Store store);
+
+ /// <summary>
+ /// Get store by host
+ /// </summary>
+ /// <param name="host"></param>
+ /// <returns></returns>
+ Task<Store?> GetStoreByHost(string host);
}
\ No newline at end of file
diff --git a/src/Business/Grand.Business.Core/Interfaces/Marketing/PushNotifications/IPushNotificationsService.cs b/src/Business/Grand.Business.Core/Interfaces/Marketing/PushNotifications/IPushNotificationsService.cs
index 90ac74783..623bc4cb9 100644
--- a/src/Business/Grand.Business.Core/Interfaces/Marketing/PushNotifications/IPushNotificationsService.cs
+++ b/src/Business/Grand.Business.Core/Interfaces/Marketing/PushNotifications/IPushNotificationsService.cs
@@ -26,7 +26,7 @@ public interface IPushNotificationsService
/// <summary>
/// Gets all push receivers
/// </summary>
- Task<List<PushRegistration>> GetPushReceivers();
+ Task<List<PushRegistration>> GetAllowedPushReceivers();
/// <summary>
/// Gets all push receivers
diff --git a/src/Business/Grand.Business.Marketing/Services/Campaigns/CampaignService.cs b/src/Business/Grand.Business.Marketing/Services/Campaigns/CampaignService.cs
index ddaba96b4..df835ea0c 100644
--- a/src/Business/Grand.Business.Marketing/Services/Campaigns/CampaignService.cs
+++ b/src/Business/Grand.Business.Marketing/Services/Campaigns/CampaignService.cs
@@ -24,7 +24,7 @@ public class CampaignService(
IStoreService storeService,
IMediator mediator,
ILanguageService languageService,
- IWorkContextAccessor workContextAccessor)
+ IContextAccessor contextAccessor)
: ICampaignService
{
/// <summary>
@@ -252,10 +252,10 @@ public class CampaignService(
(await storeService.GetAllStores()).FirstOrDefault();
builder.AddStoreTokens(store, language, emailAccount)
- .AddNewsLetterSubscriptionTokens(subscription, store, workContextAccessor.WorkContext.CurrentHost);
+ .AddNewsLetterSubscriptionTokens(subscription, store, contextAccessor.StoreContext.CurrentHost);
if (customer != null)
- builder.AddCustomerTokens(customer, store, workContextAccessor.WorkContext.CurrentHost, language)
+ builder.AddCustomerTokens(customer, store, contextAccessor.StoreContext.CurrentHost, language)
.AddShoppingCartTokens(customer, store, language);
var email = new QueuedEmail();
@@ -309,7 +309,7 @@ public class CampaignService(
builder.AddStoreTokens(store, language, emailAccount);
var customer = customerRepository.Table.FirstOrDefault(x => x.Email == email.ToLowerInvariant());
if (customer != null)
- builder.AddCustomerTokens(customer, store, workContextAccessor.WorkContext.CurrentHost, language)
+ builder.AddCustomerTokens(customer, store, contextAccessor.StoreContext.CurrentHost, language)
.AddShoppingCartTokens(customer, store, language);
var liquidObject = await builder.BuildAsync();
diff --git a/src/Business/Grand.Business.Marketing/Services/Contacts/ContactAttributeParser.cs b/src/Business/Grand.Business.Marketing/Services/Contacts/ContactAttributeParser.cs
index 7e288973a..5d9c109a1 100644
--- a/src/Business/Grand.Business.Marketing/Services/Contacts/ContactAttributeParser.cs
+++ b/src/Business/Grand.Business.Marketing/Services/Contacts/ContactAttributeParser.cs
@@ -17,15 +17,15 @@ namespace Grand.Business.Marketing.Services.Contacts;
public class ContactAttributeParser : IContactAttributeParser
{
private readonly IContactAttributeService _contactAttributeService;
- private readonly IWorkContextAccessor _workContextAccessor;
+ private readonly IContextAccessor _contextAccessor;
public ContactAttributeParser(
IContactAttributeService contactAttributeService,
- IWorkContextAccessor workContextAccessor
+ IContextAccessor contextAccessor
)
{
_contactAttributeService = contactAttributeService;
- _workContextAccessor = workContextAccessor;
+ _contextAccessor = contextAccessor;
}
/// <summary>
@@ -213,7 +213,7 @@ public class ContactAttributeParser : IContactAttributeParser
if (allowHyperlinks)
{
var downloadLink =
- $"{_workContextAccessor.WorkContext.CurrentHost.Url.TrimEnd('/')}/download/getfileupload/?downloadId={downloadGuid}";
+ $"{_contextAccessor.StoreContext.CurrentHost.Url.TrimEnd('/')}/download/getfileupload/?downloadId={downloadGuid}";
attributeText =
$"<a href=\"{downloadLink}\" class=\"fileuploadattribute\">{attribute.GetTranslation(a => a.TextPrompt, language.Id)}</a>";
}
diff --git a/src/Business/Grand.Business.Marketing/Services/Contacts/ContactAttributeService.cs b/src/Business/Grand.Business.Marketing/Services/Contacts/ContactAttributeService.cs
index 5db25916e..12f984d9f 100644
--- a/src/Business/Grand.Business.Marketing/Services/Contacts/ContactAttributeService.cs
+++ b/src/Business/Grand.Business.Marketing/Services/Contacts/ContactAttributeService.cs
@@ -24,12 +24,12 @@ public class ContactAttributeService : IContactAttributeService
public ContactAttributeService(ICacheBase cacheBase,
IRepository<ContactAttribute> contactAttributeRepository,
IMediator mediator,
- IWorkContextAccessor workContextAccessor, AccessControlConfig accessControlConfig)
+ IContextAccessor contextAccessor, AccessControlConfig accessControlConfig)
{
_cacheBase = cacheBase;
_contactAttributeRepository = contactAttributeRepository;
_mediator = mediator;
- _workContextAccessor = workContextAccessor;
+ _contextAccessor = contextAccessor;
_accessControlConfig = accessControlConfig;
}
@@ -40,7 +40,7 @@ public class ContactAttributeService : IContactAttributeService
private readonly IRepository<ContactAttribute> _contactAttributeRepository;
private readonly IMediator _mediator;
private readonly ICacheBase _cacheBase;
- private readonly IWorkContextAccessor _workContextAccessor;
+ private readonly IContextAccessor _contextAccessor;
private readonly AccessControlConfig _accessControlConfig;
#endregion
@@ -87,7 +87,7 @@ public class ContactAttributeService : IContactAttributeService
(ignoreAcl || _accessControlConfig.IgnoreAcl)) return await Task.FromResult(query.ToList());
if (!ignoreAcl && !_accessControlConfig.IgnoreAcl)
{
- var allowedCustomerGroupsIds = _workContextAccessor.WorkContext.CurrentCustomer.GetCustomerGroupIds();
+ var allowedCustomerGroupsIds = _contextAccessor.WorkContext.CurrentCustomer.GetCustomerGroupIds();
query = from p in query
where !p.LimitedToGroups || allowedCustomerGroupsIds.Any(x => p.CustomerGroups.Contains(x))
select p;
diff --git a/src/Business/Grand.Business.Marketing/Services/Customers/CustomerCoordinatesService.cs b/src/Business/Grand.Business.Marketing/Services/Customers/CustomerCoordinatesService.cs
index 167cfd7f6..15f549276 100644
--- a/src/Business/Grand.Business.Marketing/Services/Customers/CustomerCoordinatesService.cs
+++ b/src/Business/Grand.Business.Marketing/Services/Customers/CustomerCoordinatesService.cs
@@ -12,21 +12,21 @@ public class CustomerCoordinatesService : ICustomerCoordinatesService
{
private readonly IRepository<Customer> _customerRepository;
private readonly IMediator _mediator;
- private readonly IWorkContextAccessor _workContextAccessor;
+ private readonly IContextAccessor _contextAccessor;
public CustomerCoordinatesService(
IRepository<Customer> customerRepository,
- IWorkContextAccessor workContextAccessor,
+ IContextAccessor contextAccessor,
IMediator mediator)
{
_customerRepository = customerRepository;
- _workContextAccessor = workContextAccessor;
+ _contextAccessor = contextAccessor;
_mediator = mediator;
}
public Task<(double longitude, double latitude)> GetGeoCoordinate()
{
- return GetGeoCoordinate(_workContextAccessor.WorkContext.CurrentCustomer);
+ return GetGeoCoordinate(_contextAccessor.WorkContext.CurrentCustomer);
}
public async Task<(double longitude, double latitude)> GetGeoCoordinate(Customer customer)
@@ -41,7 +41,7 @@ public class CustomerCoordinatesService : ICustomerCoordinatesService
public async Task SaveGeoCoordinate(double longitude, double latitude)
{
- await SaveGeoCoordinate(_workContextAccessor.WorkContext.CurrentCustomer, longitude, latitude);
+ await SaveGeoCoordinate(_contextAccessor.WorkContext.CurrentCustomer, longitude, latitude);
}
public async Task SaveGeoCoordinate(Customer customer, double longitude, double latitude)
diff --git a/src/Business/Grand.Business.Marketing/Services/PushNotifications/PushNotificationsService.cs b/src/Business/Grand.Business.Marketing/Services/PushNotifications/PushNotificationsService.cs
index 4321aa64a..12e5426e6 100644
--- a/src/Business/Grand.Business.Marketing/Services/PushNotifications/PushNotificationsService.cs
+++ b/src/Business/Grand.Business.Marketing/Services/PushNotifications/PushNotificationsService.cs
@@ -80,7 +80,7 @@ public class PushNotificationsService : IPushNotificationsService
/// <summary>
/// Gets all push receivers
/// </summary>
- public virtual async Task<List<PushRegistration>> GetPushReceivers()
+ public virtual async Task<List<PushRegistration>> GetAllowedPushReceivers()
{
return await Task.FromResult(_pushRegistrationRepository.Table.Where(x => x.Allowed).ToList());
}
@@ -150,7 +150,7 @@ public class PushNotificationsService : IPushNotificationsService
}
else
{
- var receivers = await GetPushReceivers();
+ var receivers = await GetAllowedPushReceivers();
if (!receivers.Any()) return (false, "Admin.PushNotifications.Error.NoReceivers");
const int batchSize = 1000;
diff --git a/src/Business/Grand.Business.Messages/Services/MessageProviderService.cs b/src/Business/Grand.Business.Messages/Services/MessageProviderService.cs
index 97604bb68..9c1166148 100644
--- a/src/Business/Grand.Business.Messages/Services/MessageProviderService.cs
+++ b/src/Business/Grand.Business.Messages/Services/MessageProviderService.cs
@@ -30,7 +30,7 @@ public class MessageProviderService : IMessageProviderService
#region Ctor
public MessageProviderService(
- IWorkContextAccessor workContextAccessor,
+ IContextAccessor contextAccessor,
IMessageTemplateService messageTemplateService,
IQueuedEmailService queuedEmailService,
ILanguageService languageService,
@@ -41,7 +41,7 @@ public class MessageProviderService : IMessageProviderService
EmailAccountSettings emailAccountSettings,
CommonSettings commonSettings)
{
- _workContextAccessor = workContextAccessor;
+ _contextAccessor = contextAccessor;
_messageTemplateService = messageTemplateService;
_queuedEmailService = queuedEmailService;
_languageService = languageService;
@@ -56,7 +56,7 @@ public class MessageProviderService : IMessageProviderService
#endregion
#region Fields
- private readonly IWorkContextAccessor _workContextAccessor;
+ private readonly IContextAccessor _contextAccessor;
private readonly IMessageTemplateService _messageTemplateService;
private readonly IQueuedEmailService _queuedEmailService;
private readonly ILanguageService _languageService;
@@ -68,6 +68,8 @@ public class MessageProviderService : IMessageProviderService
private readonly EmailAccountSettings _emailAccountSettings;
private readonly CommonSettings _commonSettings;
+ private DomainHost CurrentHost => _contextAccessor.StoreContext.CurrentHost;
+
#endregion
#region Utilities
@@ -118,6 +120,14 @@ public class MessageProviderService : IMessageProviderService
return language;
}
+ private void AddCustomerTokensIfNotNull(LiquidObjectBuilder builder, Customer customer, Store store, Language language)
+ {
+ if (customer != null)
+ {
+ builder.AddCustomerTokens(customer, store, CurrentHost, language);
+ }
+ }
+
#endregion
#region Methods
@@ -149,7 +159,7 @@ public class MessageProviderService : IMessageProviderService
var builder = new LiquidObjectBuilder(_mediator);
builder.AddStoreTokens(store, language, emailAccount)
- .AddCustomerTokens(customer, store, _workContextAccessor.WorkContext.CurrentHost, language, customerNote);
+ .AddCustomerTokens(customer, store, CurrentHost, language, customerNote);
var liquidObject = await builder.BuildAsync();
//event notification
@@ -315,9 +325,8 @@ public class MessageProviderService : IMessageProviderService
var liquidBuilder = new LiquidObjectBuilder(_mediator);
liquidBuilder.AddStoreTokens(store, language, emailAccount)
- .AddOrderTokens(order, customer, store, _workContextAccessor.WorkContext.CurrentHost);
- if (customer != null)
- liquidBuilder.AddCustomerTokens(customer, store, _workContextAccessor.WorkContext.CurrentHost, language);
+ .AddOrderTokens(order, customer, store, CurrentHost);
+ AddCustomerTokensIfNotNull(liquidBuilder, customer, store, language);
var liquidObject = await liquidBuilder.BuildAsync();
//event notification
@@ -447,10 +456,8 @@ public class MessageProviderService : IMessageProviderService
var builder = new LiquidObjectBuilder(_mediator);
builder.AddStoreTokens(store, language, emailAccount)
- .AddOrderTokens(order, customer, store, _workContextAccessor.WorkContext.CurrentHost);
-
- if (customer != null)
- builder.AddCustomerTokens(customer, store, _workContextAccessor.WorkContext.CurrentHost, language);
+ .AddOrderTokens(order, customer, store, CurrentHost);
+ AddCustomerTokensIfNotNull(builder, customer, store, language);
var liquidObject = await builder.BuildAsync();
//event notification
@@ -530,10 +537,9 @@ public class MessageProviderService : IMessageProviderService
var builder = new LiquidObjectBuilder(_mediator);
builder.AddStoreTokens(store, language, emailAccount)
- .AddOrderTokens(order, customer, store, _workContextAccessor.WorkContext.CurrentHost, vendor: vendor);
+ .AddOrderTokens(order, customer, store, CurrentHost, vendor: vendor);
- if (customer != null)
- builder.AddCustomerTokens(customer, store, _workContextAccessor.WorkContext.CurrentHost, language);
+ AddCustomerTokensIfNotNull(builder, customer, store, language);
var liquidObject = await builder.BuildAsync();
//event notification
@@ -596,11 +602,10 @@ public class MessageProviderService : IMessageProviderService
var builder = new LiquidObjectBuilder(_mediator);
builder.AddStoreTokens(store, language, emailAccount)
- .AddShipmentTokens(shipment, order, store, _workContextAccessor.WorkContext.CurrentHost, language)
- .AddOrderTokens(order, customer, store, _workContextAccessor.WorkContext.CurrentHost);
+ .AddShipmentTokens(shipment, order, store, CurrentHost, language)
+ .AddOrderTokens(order, customer, store, CurrentHost);
- if (customer != null)
- builder.AddCustomerTokens(customer, store, _workContextAccessor.WorkContext.CurrentHost, language);
+ AddCustomerTokensIfNotNull(builder, customer, store, language);
var liquidObject = await builder.BuildAsync();
//event notification
@@ -640,9 +645,9 @@ public class MessageProviderService : IMessageProviderService
var builder = new LiquidObjectBuilder(_mediator);
builder.AddStoreTokens(store, language, emailAccount)
- .AddOrderTokens(order, customer, store, _workContextAccessor.WorkContext.CurrentHost, orderNote);
- if (customer != null)
- builder.AddCustomerTokens(customer, store, _workContextAccessor.WorkContext.CurrentHost, language);
+ .AddOrderTokens(order, customer, store, CurrentHost, orderNote);
+
+ AddCustomerTokensIfNotNull(builder, customer, store, language);
var liquidObject = await builder.BuildAsync();
//event notification
@@ -707,7 +712,7 @@ public class MessageProviderService : IMessageProviderService
var builder = new LiquidObjectBuilder(_mediator);
builder.AddStoreTokens(store, language, emailAccount)
- .AddNewsLetterSubscriptionTokens(subscription, store, _workContextAccessor.WorkContext.CurrentHost);
+ .AddNewsLetterSubscriptionTokens(subscription, store, CurrentHost);
var liquidObject = await builder.BuildAsync();
//event notification
@@ -753,8 +758,8 @@ public class MessageProviderService : IMessageProviderService
var builder = new LiquidObjectBuilder(_mediator);
builder.AddStoreTokens(store, language, emailAccount)
.AddEmailAFriendTokens(personalMessage, customerEmail, friendsEmail)
- .AddCustomerTokens(customer, store, _workContextAccessor.WorkContext.CurrentHost, language)
- .AddProductTokens(product, language, store, _workContextAccessor.WorkContext.CurrentHost);
+ .AddCustomerTokens(customer, store, CurrentHost, language)
+ .AddProductTokens(product, language, store, CurrentHost);
var liquidObject = await builder.BuildAsync();
//event notification
@@ -795,7 +800,7 @@ public class MessageProviderService : IMessageProviderService
var builder = new LiquidObjectBuilder(_mediator);
builder.AddStoreTokens(store, language, emailAccount)
- .AddCustomerTokens(customer, store, _workContextAccessor.WorkContext.CurrentHost, language)
+ .AddCustomerTokens(customer, store, CurrentHost, language)
.AddEmailAFriendTokens(personalMessage, customerEmail, friendsEmail);
var liquidObject = await builder.BuildAsync();
@@ -833,8 +838,8 @@ public class MessageProviderService : IMessageProviderService
var builder = new LiquidObjectBuilder(_mediator);
builder.AddStoreTokens(store, language, emailAccount)
- .AddCustomerTokens(customer, store, _workContextAccessor.WorkContext.CurrentHost, language)
- .AddProductTokens(product, language, store, _workContextAccessor.WorkContext.CurrentHost);
+ .AddCustomerTokens(customer, store, CurrentHost, language)
+ .AddProductTokens(product, language, store, CurrentHost);
var liquidObject = await builder.BuildAsync();
liquidObject.AskQuestion = new LiquidAskQuestion(message, customerEmail, fullName, phone);
@@ -913,10 +918,9 @@ public class MessageProviderService : IMessageProviderService
var builder = new LiquidObjectBuilder(_mediator);
builder.AddStoreTokens(store, language, emailAccount);
- if (customer != null)
- builder.AddCustomerTokens(customer, store, _workContextAccessor.WorkContext.CurrentHost, language);
+ AddCustomerTokensIfNotNull(builder, customer, store, language);
- builder.AddMerchandiseReturnTokens(merchandiseReturn, store, _workContextAccessor.WorkContext.CurrentHost, order, language);
+ builder.AddMerchandiseReturnTokens(merchandiseReturn, store, CurrentHost, order, language);
var liquidObject = await builder.BuildAsync();
@@ -970,10 +974,10 @@ public class MessageProviderService : IMessageProviderService
var builder = new LiquidObjectBuilder(_mediator);
builder.AddStoreTokens(store, language, emailAccount);
- if (customer != null)
- builder.AddCustomerTokens(customer, store, _workContextAccessor.WorkContext.CurrentHost, language);
- builder.AddMerchandiseReturnTokens(merchandiseReturn, store, _workContextAccessor.WorkContext.CurrentHost, order, language);
+ AddCustomerTokensIfNotNull(builder, customer, store, language);
+
+ builder.AddMerchandiseReturnTokens(merchandiseReturn, store, CurrentHost, order, language);
var liquidObject = await builder.BuildAsync();
//event notification
await _mediator.MessageTokensAdded(messageTemplate, liquidObject);
@@ -1012,10 +1016,9 @@ public class MessageProviderService : IMessageProviderService
var builder = new LiquidObjectBuilder(_mediator);
builder.AddStoreTokens(store, language, emailAccount);
- if (customer != null)
- builder.AddCustomerTokens(customer, store, _workContextAccessor.WorkContext.CurrentHost, language);
+ AddCustomerTokensIfNotNull(builder, customer, store, language);
- builder.AddMerchandiseReturnTokens(merchandiseReturn, store, _workContextAccessor.WorkContext.CurrentHost, order, language);
+ builder.AddMerchandiseReturnTokens(merchandiseReturn, store, CurrentHost, order, language);
var liquidObject = await builder.BuildAsync();
//event notification
await _mediator.MessageTokensAdded(messageTemplate, liquidObject);
@@ -1055,10 +1058,9 @@ public class MessageProviderService : IMessageProviderService
var builder = new LiquidObjectBuilder(_mediator);
builder.AddStoreTokens(store, language, emailAccount);
- if (customer != null)
- builder.AddCustomerTokens(customer, store, _workContextAccessor.WorkContext.CurrentHost, language);
+ AddCustomerTokensIfNotNull(builder, customer, store, language);
- builder.AddMerchandiseReturnTokens(merchandiseReturn, store, _workContextAccessor.WorkContext.CurrentHost, order, language,
+ builder.AddMerchandiseReturnTokens(merchandiseReturn, store, CurrentHost, order, language,
merchandiseReturnNote);
var liquidObject = await builder.BuildAsync();
//event notification
@@ -1099,7 +1101,7 @@ public class MessageProviderService : IMessageProviderService
var emailAccount = await GetEmailAccountOfMessageTemplate(messageTemplate, language.Id);
var builder = new LiquidObjectBuilder(_mediator).AddStoreTokens(store, language, emailAccount)
- .AddCustomerTokens(customer, store, _workContextAccessor.WorkContext.CurrentHost, language)
+ .AddCustomerTokens(customer, store, CurrentHost, language)
.AddVendorTokens(vendor, language);
var liquidObject = await builder.BuildAsync();
@@ -1210,9 +1212,7 @@ public class MessageProviderService : IMessageProviderService
var builder = new LiquidObjectBuilder(_mediator);
builder.AddStoreTokens(store, language, emailAccount)
.AddProductReviewTokens(product, productReview);
-
- if (customer != null)
- builder.AddCustomerTokens(customer, store, _workContextAccessor.WorkContext.CurrentHost, language);
+ AddCustomerTokensIfNotNull(builder, customer, store, language);
var liquidObject = await builder.BuildAsync();
//event notification
@@ -1254,9 +1254,7 @@ public class MessageProviderService : IMessageProviderService
var builder = new LiquidObjectBuilder(_mediator);
builder.AddStoreTokens(store, language, emailAccount)
.AddVendorReviewTokens(vendor, vendorReview);
-
- if (customer != null)
- builder.AddCustomerTokens(customer, store, _workContextAccessor.WorkContext.CurrentHost, language);
+ AddCustomerTokensIfNotNull(builder, customer, store, language);
builder.AddVendorTokens(vendor, language);
var liquidObject = await builder.BuildAsync();
@@ -1293,7 +1291,7 @@ public class MessageProviderService : IMessageProviderService
var builder = new LiquidObjectBuilder(_mediator);
builder.AddStoreTokens(store, language, emailAccount)
- .AddProductTokens(product, language, store, _workContextAccessor.WorkContext.CurrentHost);
+ .AddProductTokens(product, language, store, CurrentHost);
var liquidObject = await builder.BuildAsync();
//event notification
await _mediator.MessageTokensAdded(messageTemplate, liquidObject);
@@ -1330,7 +1328,7 @@ public class MessageProviderService : IMessageProviderService
var builder = new LiquidObjectBuilder(_mediator);
builder.AddStoreTokens(store, language, emailAccount)
- .AddProductTokens(product, language, store, _workContextAccessor.WorkContext.CurrentHost)
+ .AddProductTokens(product, language, store, CurrentHost)
.AddAttributeCombinationTokens(product, combination);
var liquidObject = await builder.BuildAsync();
//event notification
@@ -1365,7 +1363,7 @@ public class MessageProviderService : IMessageProviderService
var builder = new LiquidObjectBuilder(_mediator);
builder.AddStoreTokens(store, language, emailAccount)
- .AddCustomerTokens(customer, store, _workContextAccessor.WorkContext.CurrentHost, language);
+ .AddCustomerTokens(customer, store, CurrentHost, language);
var liquidObject = await builder.BuildAsync();
@@ -1396,11 +1394,11 @@ public class MessageProviderService : IMessageProviderService
var builder = new LiquidObjectBuilder(_mediator);
builder.AddStoreTokens(store, language, emailAccount)
- .AddBlogCommentTokens(blogPost, blogComment, store, _workContextAccessor.WorkContext.CurrentHost, language);
+ .AddBlogCommentTokens(blogPost, blogComment, store, CurrentHost, language);
var customer = await _mediator.Send(new GetCustomerByIdQuery { Id = blogComment.CustomerId });
if (customer != null && await _groupService.IsRegistered(customer))
- builder.AddCustomerTokens(customer, store, _workContextAccessor.WorkContext.CurrentHost, language);
+ builder.AddCustomerTokens(customer, store, CurrentHost, language);
var liquidObject = await builder.BuildAsync();
//event notification
@@ -1437,11 +1435,11 @@ public class MessageProviderService : IMessageProviderService
var builder = new LiquidObjectBuilder(_mediator);
builder.AddStoreTokens(store, language, emailAccount)
- .AddArticleCommentTokens(article, articleComment, store, _workContextAccessor.WorkContext.CurrentHost, language);
+ .AddArticleCommentTokens(article, articleComment, store, CurrentHost, language);
var customer = await _mediator.Send(new GetCustomerByIdQuery { Id = articleComment.CustomerId });
if (customer != null && await _groupService.IsRegistered(customer))
- builder.AddCustomerTokens(customer, store, _workContextAccessor.WorkContext.CurrentHost, language);
+ builder.AddCustomerTokens(customer, store, CurrentHost, language);
var liquidObject = await builder.BuildAsync();
//event notification
await _mediator.MessageTokensAdded(messageTemplate, liquidObject);
@@ -1475,10 +1473,9 @@ public class MessageProviderService : IMessageProviderService
var builder = new LiquidObjectBuilder(_mediator);
builder.AddStoreTokens(store, language, emailAccount)
- .AddNewsCommentTokens(newsItem, newsComment, store, _workContextAccessor.WorkContext.CurrentHost, language);
+ .AddNewsCommentTokens(newsItem, newsComment, store, CurrentHost, language);
var customer = await _mediator.Send(new GetCustomerByIdQuery { Id = newsComment.CustomerId });
- if (customer != null)
- builder.AddCustomerTokens(customer, store, _workContextAccessor.WorkContext.CurrentHost, language);
+ AddCustomerTokensIfNotNull(builder, customer, store, language);
var liquidObject = await builder.BuildAsync();
//event notification
@@ -1515,10 +1512,9 @@ public class MessageProviderService : IMessageProviderService
var builder = new LiquidObjectBuilder(_mediator);
builder.AddStoreTokens(store, language, emailAccount);
- if (customer != null)
- builder.AddCustomerTokens(customer, store, _workContextAccessor.WorkContext.CurrentHost, language);
+ AddCustomerTokensIfNotNull(builder, customer, store, language);
- builder.AddOutOfStockTokens(product, subscription, store, _workContextAccessor.WorkContext.CurrentHost, language);
+ builder.AddOutOfStockTokens(product, subscription, store, CurrentHost, language);
var liquidObject = await builder.BuildAsync();
//event notification
await _mediator.MessageTokensAdded(messageTemplate, liquidObject);
@@ -1575,7 +1571,7 @@ public class MessageProviderService : IMessageProviderService
var builder = new LiquidObjectBuilder(_mediator);
builder.AddStoreTokens(store, language, emailAccount)
- .AddCustomerTokens(customer, store, _workContextAccessor.WorkContext.CurrentHost, language);
+ .AddCustomerTokens(customer, store, CurrentHost, language);
var liquidObject = await builder.BuildAsync();
liquidObject.ContactUs = new LiquidContactUs(senderEmail, senderName, body, attrInfo);
@@ -1654,7 +1650,7 @@ public class MessageProviderService : IMessageProviderService
var builder = new LiquidObjectBuilder(_mediator);
builder.AddStoreTokens(store, language, emailAccount)
- .AddCustomerTokens(customer, store, _workContextAccessor.WorkContext.CurrentHost, language);
+ .AddCustomerTokens(customer, store, CurrentHost, language);
var liquidObject = await builder.BuildAsync();
liquidObject.ContactUs = new LiquidContactUs(senderEmail, senderName, body, "");
//event notification
@@ -1708,8 +1704,8 @@ public class MessageProviderService : IMessageProviderService
var builder = new LiquidObjectBuilder(_mediator);
builder.AddAuctionTokens(product, bid)
- .AddCustomerTokens(customer, store, _workContextAccessor.WorkContext.CurrentHost, language)
- .AddProductTokens(product, language, store, _workContextAccessor.WorkContext.CurrentHost)
+ .AddCustomerTokens(customer, store, CurrentHost, language)
+ .AddProductTokens(product, language, store, CurrentHost)
.AddStoreTokens(store, language, emailAccount);
var liquidObject = await builder.BuildAsync();
@@ -1743,7 +1739,7 @@ public class MessageProviderService : IMessageProviderService
var builder = new LiquidObjectBuilder(_mediator);
builder.AddAuctionTokens(product, bid)
- .AddProductTokens(product, language, store, _workContextAccessor.WorkContext.CurrentHost)
+ .AddProductTokens(product, language, store, CurrentHost)
.AddStoreTokens(store, language, emailAccount);
var liquidObject = await builder.BuildAsync();
@@ -1755,7 +1751,7 @@ public class MessageProviderService : IMessageProviderService
var customer = await _mediator.Send(new GetCustomerByIdQuery { Id = item.Key });
if (string.IsNullOrEmpty(languageId))
languageId = customer.GetUserFieldFromEntity<string>(SystemCustomerFieldNames.LanguageId);
- builder2.AddCustomerTokens(customer, store, _workContextAccessor.WorkContext.CurrentHost, language);
+ builder2.AddCustomerTokens(customer, store, CurrentHost, language);
var liquidObject2 = await builder2.BuildAsync();
//event notification
@@ -1787,7 +1783,7 @@ public class MessageProviderService : IMessageProviderService
var emailAccount = await GetEmailAccountOfMessageTemplate(messageTemplate, language.Id);
var builder = new LiquidObjectBuilder(_mediator);
- builder.AddProductTokens(product, language, store, _workContextAccessor.WorkContext.CurrentHost)
+ builder.AddProductTokens(product, language, store, CurrentHost)
.AddStoreTokens(store, language, emailAccount);
var liquidObject = await builder.BuildAsync();
@@ -1802,7 +1798,7 @@ public class MessageProviderService : IMessageProviderService
if (string.IsNullOrEmpty(languageId))
languageId = customer.GetUserFieldFromEntity<string>(SystemCustomerFieldNames.LanguageId);
- builder2.AddCustomerTokens(customer, store, _workContextAccessor.WorkContext.CurrentHost, language);
+ AddCustomerTokensIfNotNull(builder2, customer, store, language);
var liquidObject2 = await builder2.BuildAsync();
//event notification
await _mediator.MessageTokensAdded(messageTemplate, liquidObject2);
@@ -1843,7 +1839,7 @@ public class MessageProviderService : IMessageProviderService
emailAccount = await GetEmailAccountOfMessageTemplate(messageTemplate, language.Id);
builder.AddAuctionTokens(product, bid)
- .AddCustomerTokens(customer, store, _workContextAccessor.WorkContext.CurrentHost, language)
+ .AddCustomerTokens(customer, store, CurrentHost, language)
.AddStoreTokens(store, language, emailAccount);
}
else
@@ -1855,7 +1851,7 @@ public class MessageProviderService : IMessageProviderService
return 0;
emailAccount = await GetEmailAccountOfMessageTemplate(messageTemplate, language.Id);
- builder.AddProductTokens(product, language, store, _workContextAccessor.WorkContext.CurrentHost);
+ builder.AddProductTokens(product, language, store, CurrentHost);
}
var liquidObject = await builder.BuildAsync();
@@ -1897,7 +1893,7 @@ public class MessageProviderService : IMessageProviderService
var builder = new LiquidObjectBuilder(_mediator);
builder.AddAuctionTokens(product, bid)
- .AddCustomerTokens(customer, store, _workContextAccessor.WorkContext.CurrentHost, language)
+ .AddCustomerTokens(customer, store, CurrentHost, language)
.AddStoreTokens(store, language, emailAccount);
var liquidObject = await builder.BuildAsync();
diff --git a/src/Core/Grand.Infrastructure/IWorkContextAccessor.cs b/src/Core/Grand.Infrastructure/IContextAccessor.cs
similarity index 50%
rename from src/Core/Grand.Infrastructure/IWorkContextAccessor.cs
rename to src/Core/Grand.Infrastructure/IContextAccessor.cs
index 3bfd6af71..7fff7cf67 100644
--- a/src/Core/Grand.Infrastructure/IWorkContextAccessor.cs
+++ b/src/Core/Grand.Infrastructure/IContextAccessor.cs
@@ -1,6 +1,8 @@
namespace Grand.Infrastructure;
-public interface IWorkContextAccessor
+public interface IContextAccessor
{
IWorkContext WorkContext { get; set; }
+
+ IStoreContext StoreContext { get; set; }
}
diff --git a/src/Core/Grand.Infrastructure/IStoreContext.cs b/src/Core/Grand.Infrastructure/IStoreContext.cs
new file mode 100644
index 000000000..a09df7981
--- /dev/null
+++ b/src/Core/Grand.Infrastructure/IStoreContext.cs
@@ -0,0 +1,25 @@
+using Grand.Domain.Stores;
+
+namespace Grand.Infrastructure;
+
+public interface IStoreContext
+{
+ /// <summary>
+ /// Gets or sets the current store
+ /// </summary>
+ Store CurrentStore { get; }
+
+ /// <summary>
+ /// Gets the current host
+ /// </summary>
+ DomainHost CurrentHost { get; }
+}
+
+public interface IStoreContextSetter
+{
+ /// <summary>
+ /// Initialize the store context
+ /// </summary>
+ /// <returns></returns>
+ Task<IStoreContext> InitializeStoreContext(string storeId = null);
+}
\ No newline at end of file
diff --git a/src/Core/Grand.Infrastructure/IWorkContext.cs b/src/Core/Grand.Infrastructure/IWorkContext.cs
index 83feb039d..c233e4381 100644
--- a/src/Core/Grand.Infrastructure/IWorkContext.cs
+++ b/src/Core/Grand.Infrastructure/IWorkContext.cs
@@ -1,7 +1,6 @@
using Grand.Domain.Customers;
using Grand.Domain.Directory;
using Grand.Domain.Localization;
-using Grand.Domain.Stores;
using Grand.Domain.Tax;
using Grand.Domain.Vendors;
@@ -41,17 +40,6 @@ public interface IWorkContext
/// Get current tax display type
/// </summary>
TaxDisplayType TaxDisplayType { get; }
-
- /// <summary>
- /// Gets or sets the current store
- /// </summary>
- Store CurrentStore { get; }
-
- /// <summary>
- /// Gets the current host
- /// </summary>
- DomainHost CurrentHost { get; }
-
}
public interface IWorkContextSetter
diff --git a/src/Modules/Grand.Module.Api/Commands/Handlers/Catalog/AddProductAttributeCommandHandler.cs b/src/Modules/Grand.Module.Api/Commands/Handlers/Catalog/AddProductAttributeCommandHandler.cs
index 1fdd9718f..39ab60b34 100644
--- a/src/Modules/Grand.Module.Api/Commands/Handlers/Catalog/AddProductAttributeCommandHandler.cs
+++ b/src/Modules/Grand.Module.Api/Commands/Handlers/Catalog/AddProductAttributeCommandHandler.cs
@@ -1,9 +1,7 @@
-using Grand.Module.Api.Commands.Models.Catalog;
+using Grand.Business.Core.Interfaces.Catalog.Products;
+using Grand.Module.Api.Commands.Models.Catalog;
using Grand.Module.Api.DTOs.Catalog;
using Grand.Module.Api.Extensions;
-using Grand.Business.Core.Interfaces.Catalog.Products;
-using Grand.Business.Core.Interfaces.Common.Localization;
-using Grand.Infrastructure;
using MediatR;
namespace Grand.Module.Api.Commands.Handlers.Catalog;
@@ -11,17 +9,11 @@ namespace Grand.Module.Api.Commands.Handlers.Catalog;
public class AddProductAttributeCommandHandler : IRequestHandler<AddProductAttributeCommand, ProductAttributeDto>
{
private readonly IProductAttributeService _productAttributeService;
- private readonly ITranslationService _translationService;
- private readonly IWorkContextAccessor _workContextAccessor;
public AddProductAttributeCommandHandler(
- IProductAttributeService productAttributeService,
- ITranslationService translationService,
- IWorkContextAccessor workContextAccessor)
+ IProductAttributeService productAttributeService)
{
_productAttributeService = productAttributeService;
- _translationService = translationService;
- _workContextAccessor = workContextAccessor;
}
public async Task<ProductAttributeDto> Handle(AddProductAttributeCommand request,
diff --git a/src/Modules/Grand.Module.Api/Commands/Handlers/Catalog/AddSpecificationAttributeCommandHandler.cs b/src/Modules/Grand.Module.Api/Commands/Handlers/Catalog/AddSpecificationAttributeCommandHandler.cs
index c765314a7..61cfbcfa4 100644
--- a/src/Modules/Grand.Module.Api/Commands/Handlers/Catalog/AddSpecificationAttributeCommandHandler.cs
+++ b/src/Modules/Grand.Module.Api/Commands/Handlers/Catalog/AddSpecificationAttributeCommandHandler.cs
@@ -1,9 +1,7 @@
-using Grand.Module.Api.Commands.Models.Catalog;
+using Grand.Business.Core.Interfaces.Catalog.Products;
+using Grand.Module.Api.Commands.Models.Catalog;
using Grand.Module.Api.DTOs.Catalog;
using Grand.Module.Api.Extensions;
-using Grand.Business.Core.Interfaces.Catalog.Products;
-using Grand.Business.Core.Interfaces.Common.Localization;
-using Grand.Infrastructure;
using MediatR;
namespace Grand.Module.Api.Commands.Handlers.Catalog;
@@ -13,17 +11,11 @@ public class
SpecificationAttributeDto>
{
private readonly ISpecificationAttributeService _specificationAttributeService;
- private readonly ITranslationService _translationService;
- private readonly IWorkContextAccessor _workContextAccessor;
public AddSpecificationAttributeCommandHandler(
- ISpecificationAttributeService specificationAttributeService,
- ITranslationService translationService,
- IWorkContextAccessor workContextAccessor)
+ ISpecificationAttributeService specificationAttributeService)
{
_specificationAttributeService = specificationAttributeService;
- _translationService = translationService;
- _workContextAccessor = workContextAccessor;
}
public async Task<SpecificationAttributeDto> Handle(AddSpecificationAttributeCommand request,
diff --git a/src/Modules/Grand.Module.Api/Commands/Handlers/Catalog/DeleteBrandCommandHandler.cs b/src/Modules/Grand.Module.Api/Commands/Handlers/Catalog/DeleteBrandCommandHandler.cs
index 93e7c6048..b417c460f 100644
--- a/src/Modules/Grand.Module.Api/Commands/Handlers/Catalog/DeleteBrandCommandHandler.cs
+++ b/src/Modules/Grand.Module.Api/Commands/Handlers/Catalog/DeleteBrandCommandHandler.cs
@@ -1,7 +1,5 @@
-using Grand.Module.Api.Commands.Models.Catalog;
-using Grand.Business.Core.Interfaces.Catalog.Brands;
-using Grand.Business.Core.Interfaces.Common.Localization;
-using Grand.Infrastructure;
+using Grand.Business.Core.Interfaces.Catalog.Brands;
+using Grand.Module.Api.Commands.Models.Catalog;
using MediatR;
namespace Grand.Module.Api.Commands.Handlers.Catalog;
@@ -9,17 +7,11 @@ namespace Grand.Module.Api.Commands.Handlers.Catalog;
public class DeleteBrandCommandHandler : IRequestHandler<DeleteBrandCommand, bool>
{
private readonly IBrandService _brandService;
- private readonly ITranslationService _translationService;
- private readonly IWorkContextAccessor _workContextAccessor;
public DeleteBrandCommandHandler(
- IBrandService brandService,
- ITranslationService translationService,
- IWorkContextAccessor workContextAccessor)
+ IBrandService brandService)
{
_brandService = brandService;
- _translationService = translationService;
- _workContextAccessor = workContextAccessor;
}
public async Task<bool> Handle(DeleteBrandCommand request, CancellationToken cancellationToken)
diff --git a/src/Modules/Grand.Module.Api/Commands/Handlers/Catalog/DeleteCategoryCommandHandler.cs b/src/Modules/Grand.Module.Api/Commands/Handlers/Catalog/DeleteCategoryCommandHandler.cs
index 0f8e7ab71..bae2bd4c0 100644
--- a/src/Modules/Grand.Module.Api/Commands/Handlers/Catalog/DeleteCategoryCommandHandler.cs
+++ b/src/Modules/Grand.Module.Api/Commands/Handlers/Catalog/DeleteCategoryCommandHandler.cs
@@ -1,7 +1,5 @@
-using Grand.Module.Api.Commands.Models.Catalog;
-using Grand.Business.Core.Interfaces.Catalog.Categories;
-using Grand.Business.Core.Interfaces.Common.Localization;
-using Grand.Infrastructure;
+using Grand.Business.Core.Interfaces.Catalog.Categories;
+using Grand.Module.Api.Commands.Models.Catalog;
using MediatR;
namespace Grand.Module.Api.Commands.Handlers.Catalog;
@@ -9,17 +7,10 @@ namespace Grand.Module.Api.Commands.Handlers.Catalog;
public class DeleteCategoryCommandHandler : IRequestHandler<DeleteCategoryCommand, bool>
{
private readonly ICategoryService _categoryService;
- private readonly ITranslationService _translationService;
- private readonly IWorkContextAccessor _workContextAccessor;
- public DeleteCategoryCommandHandler(
- ICategoryService categoryService,
- ITranslationService translationService,
- IWorkContextAccessor workContextAccessor)
+ public DeleteCategoryCommandHandler(ICategoryService categoryService)
{
_categoryService = categoryService;
- _translationService = translationService;
- _workContextAccessor = workContextAccessor;
}
public async Task<bool> Handle(DeleteCategoryCommand request, CancellationToken cancellationToken)
diff --git a/src/Modules/Grand.Module.Api/Commands/Handlers/Catalog/DeleteCollectionCommandHandler.cs b/src/Modules/Grand.Module.Api/Commands/Handlers/Catalog/DeleteCollectionCommandHandler.cs
index 0e9557c50..0412e26f5 100644
--- a/src/Modules/Grand.Module.Api/Commands/Handlers/Catalog/DeleteCollectionCommandHandler.cs
+++ b/src/Modules/Grand.Module.Api/Commands/Handlers/Catalog/DeleteCollectionCommandHandler.cs
@@ -1,7 +1,5 @@
-using Grand.Module.Api.Commands.Models.Catalog;
-using Grand.Business.Core.Interfaces.Catalog.Collections;
-using Grand.Business.Core.Interfaces.Common.Localization;
-using Grand.Infrastructure;
+using Grand.Business.Core.Interfaces.Catalog.Collections;
+using Grand.Module.Api.Commands.Models.Catalog;
using MediatR;
namespace Grand.Module.Api.Commands.Handlers.Catalog;
@@ -9,17 +7,10 @@ namespace Grand.Module.Api.Commands.Handlers.Catalog;
public class DeleteCollectionCommandHandler : IRequestHandler<DeleteCollectionCommand, bool>
{
private readonly ICollectionService _collectionService;
- private readonly ITranslationService _translationService;
- private readonly IWorkContextAccessor _workContextAccessor;
- public DeleteCollectionCommandHandler(
- ICollectionService collectionService,
- ITranslationService translationService,
- IWorkContextAccessor workContextAccessor)
+ public DeleteCollectionCommandHandler(ICollectionService collectionService)
{
_collectionService = collectionService;
- _translationService = translationService;
- _workContextAccessor = workContextAccessor;
}
public async Task<bool> Handle(DeleteCollectionCommand request, CancellationToken cancellationToken)
diff --git a/src/Modules/Grand.Module.Api/Commands/Handlers/Catalog/DeleteProductAttributeCommandHandler.cs b/src/Modules/Grand.Module.Api/Commands/Handlers/Catalog/DeleteProductAttributeCommandHandler.cs
index 01cb14ed7..e1ea8ef1b 100644
--- a/src/Modules/Grand.Module.Api/Commands/Handlers/Catalog/DeleteProductAttributeCommandHandler.cs
+++ b/src/Modules/Grand.Module.Api/Commands/Handlers/Catalog/DeleteProductAttributeCommandHandler.cs
@@ -1,7 +1,5 @@
-using Grand.Module.Api.Commands.Models.Catalog;
-using Grand.Business.Core.Interfaces.Catalog.Products;
-using Grand.Business.Core.Interfaces.Common.Localization;
-using Grand.Infrastructure;
+using Grand.Business.Core.Interfaces.Catalog.Products;
+using Grand.Module.Api.Commands.Models.Catalog;
using MediatR;
namespace Grand.Module.Api.Commands.Handlers.Catalog;
@@ -9,17 +7,10 @@ namespace Grand.Module.Api.Commands.Handlers.Catalog;
public class DeleteProductAttributeCommandHandler : IRequestHandler<DeleteProductAttributeCommand, bool>
{
private readonly IProductAttributeService _productAttributeService;
- private readonly ITranslationService _translationService;
- private readonly IWorkContextAccessor _workContextAccessor;
- public DeleteProductAttributeCommandHandler(
- IProductAttributeService productAttributeService,
- ITranslationService translationService,
- IWorkContextAccessor workContextAccessor)
+ public DeleteProductAttributeCommandHandler(IProductAttributeService productAttributeService)
{
_productAttributeService = productAttributeService;
- _translationService = translationService;
- _workContextAccessor = workContextAccessor;
}
public async Task<bool> Handle(DeleteProductAttributeCommand request, CancellationToken cancellationToken)
diff --git a/src/Modules/Grand.Module.Api/Commands/Handlers/Catalog/DeleteProductCommandHandler.cs b/src/Modules/Grand.Module.Api/Commands/Handlers/Catalog/DeleteProductCommandHandler.cs
index 60a74301b..29943013f 100644
--- a/src/Modules/Grand.Module.Api/Commands/Handlers/Catalog/DeleteProductCommandHandler.cs
+++ b/src/Modules/Grand.Module.Api/Commands/Handlers/Catalog/DeleteProductCommandHandler.cs
@@ -1,7 +1,5 @@
-using Grand.Module.Api.Commands.Models.Catalog;
-using Grand.Business.Core.Interfaces.Catalog.Products;
-using Grand.Business.Core.Interfaces.Common.Localization;
-using Grand.Infrastructure;
+using Grand.Business.Core.Interfaces.Catalog.Products;
+using Grand.Module.Api.Commands.Models.Catalog;
using MediatR;
namespace Grand.Module.Api.Commands.Handlers.Catalog;
@@ -9,17 +7,10 @@ namespace Grand.Module.Api.Commands.Handlers.Catalog;
public class DeleteProductCommandHandler : IRequestHandler<DeleteProductCommand, bool>
{
private readonly IProductService _productService;
- private readonly ITranslationService _translationService;
- private readonly IWorkContextAccessor _workContextAccessor;
- public DeleteProductCommandHandler(
- IProductService productService,
- ITranslationService translationService,
- IWorkContextAccessor workContextAccessor)
+ public DeleteProductCommandHandler(IProductService productService)
{
_productService = productService;
- _translationService = translationService;
- _workContextAccessor = workContextAccessor;
}
public async Task<bool> Handle(DeleteProductCommand request, CancellationToken cancellationToken)
diff --git a/src/Modules/Grand.Module.Api/Commands/Handlers/Catalog/DeleteSpecificationAttributeCommandHandler.cs b/src/Modules/Grand.Module.Api/Commands/Handlers/Catalog/DeleteSpecificationAttributeCommandHandler.cs
index ef75913c5..4f1f3462e 100644
--- a/src/Modules/Grand.Module.Api/Commands/Handlers/Catalog/DeleteSpecificationAttributeCommandHandler.cs
+++ b/src/Modules/Grand.Module.Api/Commands/Handlers/Catalog/DeleteSpecificationAttributeCommandHandler.cs
@@ -1,7 +1,5 @@
-using Grand.Module.Api.Commands.Models.Catalog;
-using Grand.Business.Core.Interfaces.Catalog.Products;
-using Grand.Business.Core.Interfaces.Common.Localization;
-using Grand.Infrastructure;
+using Grand.Business.Core.Interfaces.Catalog.Products;
+using Grand.Module.Api.Commands.Models.Catalog;
using MediatR;
namespace Grand.Module.Api.Commands.Handlers.Catalog;
@@ -9,17 +7,10 @@ namespace Grand.Module.Api.Commands.Handlers.Catalog;
public class DeleteSpecificationAttributeCommandHandler : IRequestHandler<DeleteSpecificationAttributeCommand, bool>
{
private readonly ISpecificationAttributeService _specificationAttributeService;
- private readonly ITranslationService _translationService;
- private readonly IWorkContextAccessor _workContextAccessor;
- public DeleteSpecificationAttributeCommandHandler(
- ISpecificationAttributeService specificationAttributeService,
- ITranslationService translationService,
- IWorkContextAccessor workContextAccessor)
+ public DeleteSpecificationAttributeCommandHandler(ISpecificationAttributeService specificationAttributeService)
{
_specificationAttributeService = specificationAttributeService;
- _translationService = translationService;
- _workContextAccessor = workContextAccessor;
}
public async Task<bool> Handle(DeleteSpecificationAttributeCommand request, CancellationToken cancellationToken)
diff --git a/src/Modules/Grand.Module.Api/Commands/Handlers/Catalog/UpdateProductAttributeCommandHandler.cs b/src/Modules/Grand.Module.Api/Commands/Handlers/Catalog/UpdateProductAttributeCommandHandler.cs
index 818af906b..6ad6ffad6 100644
--- a/src/Modules/Grand.Module.Api/Commands/Handlers/Catalog/UpdateProductAttributeCommandHandler.cs
+++ b/src/Modules/Grand.Module.Api/Commands/Handlers/Catalog/UpdateProductAttributeCommandHandler.cs
@@ -1,9 +1,7 @@
-using Grand.Module.Api.Commands.Models.Catalog;
+using Grand.Business.Core.Interfaces.Catalog.Products;
+using Grand.Module.Api.Commands.Models.Catalog;
using Grand.Module.Api.DTOs.Catalog;
using Grand.Module.Api.Extensions;
-using Grand.Business.Core.Interfaces.Catalog.Products;
-using Grand.Business.Core.Interfaces.Common.Localization;
-using Grand.Infrastructure;
using MediatR;
namespace Grand.Module.Api.Commands.Handlers.Catalog;
@@ -11,17 +9,10 @@ namespace Grand.Module.Api.Commands.Handlers.Catalog;
public class UpdateProductAttributeCommandHandler : IRequestHandler<UpdateProductAttributeCommand, ProductAttributeDto>
{
private readonly IProductAttributeService _productAttributeService;
- private readonly ITranslationService _translationService;
- private readonly IWorkContextAccessor _workContextAccessor;
- public UpdateProductAttributeCommandHandler(
- IProductAttributeService productAttributeService,
- ITranslationService translationService,
- IWorkContextAccessor workContextAccessor)
+ public UpdateProductAttributeCommandHandler(IProductAttributeService productAttributeService)
{
_productAttributeService = productAttributeService;
- _translationService = translationService;
- _workContextAccessor = workContextAccessor;
}
public async Task<ProductAttributeDto> Handle(UpdateProductAttributeCommand request,
diff --git a/src/Modules/Grand.Module.Api/Commands/Handlers/Catalog/UpdateProductStockCommandHandler.cs b/src/Modules/Grand.Module.Api/Commands/Handlers/Catalog/UpdateProductStockCommandHandler.cs
index 42e50cd3c..27548936d 100644
--- a/src/Modules/Grand.Module.Api/Commands/Handlers/Catalog/UpdateProductStockCommandHandler.cs
+++ b/src/Modules/Grand.Module.Api/Commands/Handlers/Catalog/UpdateProductStockCommandHandler.cs
@@ -1,8 +1,6 @@
-using Grand.Module.Api.Commands.Models.Catalog;
-using Grand.Business.Core.Interfaces.Catalog.Products;
-using Grand.Business.Core.Interfaces.Common.Localization;
+using Grand.Business.Core.Interfaces.Catalog.Products;
using Grand.Domain.Catalog;
-using Grand.Infrastructure;
+using Grand.Module.Api.Commands.Models.Catalog;
using MediatR;
namespace Grand.Module.Api.Commands.Handlers.Catalog;
@@ -13,23 +11,17 @@ public class UpdateProductStockCommandHandler : IRequestHandler<UpdateProductSto
private readonly IOutOfStockSubscriptionService _outOfStockSubscriptionService;
private readonly IProductService _productService;
private readonly IStockQuantityService _stockQuantityService;
- private readonly ITranslationService _translationService;
- private readonly IWorkContextAccessor _workContextAccessor;
public UpdateProductStockCommandHandler(
IProductService productService,
IInventoryManageService inventoryManageService,
IStockQuantityService stockQuantityService,
- ITranslationService translationService,
- IOutOfStockSubscriptionService outOfStockSubscriptionService,
- IWorkContextAccessor workContextAccessor)
+ IOutOfStockSubscriptionService outOfStockSubscriptionService)
{
_productService = productService;
_inventoryManageService = inventoryManageService;
_stockQuantityService = stockQuantityService;
- _translationService = translationService;
_outOfStockSubscriptionService = outOfStockSubscriptionService;
- _workContextAccessor = workContextAccessor;
}
public async Task<bool> Handle(UpdateProductStockCommand request, CancellationToken cancellationToken)
@@ -39,8 +31,10 @@ public class UpdateProductStockCommandHandler : IRequestHandler<UpdateProductSto
{
var prevStockQuantity = _stockQuantityService.GetTotalStockQuantity(product);
var prevMultiWarehouseStock = product.ProductWarehouseInventory.Select(i => new ProductWarehouseInventory {
- WarehouseId = i.WarehouseId, StockQuantity = i.StockQuantity, ReservedQuantity = i.ReservedQuantity
- })
+ WarehouseId = i.WarehouseId,
+ StockQuantity = i.StockQuantity,
+ ReservedQuantity = i.ReservedQuantity
+ })
.ToList();
if (string.IsNullOrEmpty(request.WarehouseId))
diff --git a/src/Modules/Grand.Module.Api/Commands/Handlers/Catalog/UpdateSpecificationAttributeCommandHandler.cs b/src/Modules/Grand.Module.Api/Commands/Handlers/Catalog/UpdateSpecificationAttributeCommandHandler.cs
index 14b1c9cf1..593ac9775 100644
--- a/src/Modules/Grand.Module.Api/Commands/Handlers/Catalog/UpdateSpecificationAttributeCommandHandler.cs
+++ b/src/Modules/Grand.Module.Api/Commands/Handlers/Catalog/UpdateSpecificationAttributeCommandHandler.cs
@@ -1,9 +1,7 @@
-using Grand.Module.Api.Commands.Models.Catalog;
+using Grand.Business.Core.Interfaces.Catalog.Products;
+using Grand.Module.Api.Commands.Models.Catalog;
using Grand.Module.Api.DTOs.Catalog;
using Grand.Module.Api.Extensions;
-using Grand.Business.Core.Interfaces.Catalog.Products;
-using Grand.Business.Core.Interfaces.Common.Localization;
-using Grand.Infrastructure;
using MediatR;
namespace Grand.Module.Api.Commands.Handlers.Catalog;
@@ -13,17 +11,10 @@ public class
SpecificationAttributeDto>
{
private readonly ISpecificationAttributeService _specificationAttributeService;
- private readonly ITranslationService _translationService;
- private readonly IWorkContextAccessor _workContextAccessor;
- public UpdateSpecificationAttributeCommandHandler(
- ISpecificationAttributeService specificationAttributeService,
- ITranslationService translationService,
- IWorkContextAccessor workContextAccessor)
+ public UpdateSpecificationAttributeCommandHandler(ISpecificationAttributeService specificationAttributeService)
{
_specificationAttributeService = specificationAttributeService;
- _translationService = translationService;
- _workContextAccessor = workContextAccessor;
}
public async Task<SpecificationAttributeDto> Handle(UpdateSpecificationAttributeCommand request,
diff --git a/src/Modules/Grand.Module.Api/Commands/Handlers/Customers/AddCustomerGroupCommandHandler.cs b/src/Modules/Grand.Module.Api/Commands/Handlers/Customers/AddCustomerGroupCommandHandler.cs
index d3a3c85c5..013bb8b95 100644
--- a/src/Modules/Grand.Module.Api/Commands/Handlers/Customers/AddCustomerGroupCommandHandler.cs
+++ b/src/Modules/Grand.Module.Api/Commands/Handlers/Customers/AddCustomerGroupCommandHandler.cs
@@ -1,9 +1,7 @@
-using Grand.Module.Api.Commands.Models.Customers;
+using Grand.Business.Core.Interfaces.Common.Directory;
+using Grand.Module.Api.Commands.Models.Customers;
using Grand.Module.Api.DTOs.Customers;
using Grand.Module.Api.Extensions;
-using Grand.Business.Core.Interfaces.Common.Directory;
-using Grand.Business.Core.Interfaces.Common.Localization;
-using Grand.Infrastructure;
using MediatR;
namespace Grand.Module.Api.Commands.Handlers.Customers;
@@ -11,17 +9,10 @@ namespace Grand.Module.Api.Commands.Handlers.Customers;
public class AddCustomerGroupCommandHandler : IRequestHandler<AddCustomerGroupCommand, CustomerGroupDto>
{
private readonly IGroupService _groupService;
- private readonly ITranslationService _translationService;
- private readonly IWorkContextAccessor _workContextAccessor;
- public AddCustomerGroupCommandHandler(
- IGroupService groupService,
- ITranslationService translationService,
- IWorkContextAccessor workContextAccessor)
+ public AddCustomerGroupCommandHandler(IGroupService groupService)
{
_groupService = groupService;
- _translationService = translationService;
- _workContextAccessor = workContextAccessor;
}
public async Task<CustomerGroupDto> Handle(AddCustomerGroupCommand request, CancellationToken cancellationToken)
diff --git a/src/Modules/Grand.Module.Api/Commands/Handlers/Customers/DeleteCustomerCommandHandler.cs b/src/Modules/Grand.Module.Api/Commands/Handlers/Customers/DeleteCustomerCommandHandler.cs
index 2011f37e7..a77d92170 100644
--- a/src/Modules/Grand.Module.Api/Commands/Handlers/Customers/DeleteCustomerCommandHandler.cs
+++ b/src/Modules/Grand.Module.Api/Commands/Handlers/Customers/DeleteCustomerCommandHandler.cs
@@ -1,7 +1,5 @@
-using Grand.Module.Api.Commands.Models.Customers;
-using Grand.Business.Core.Interfaces.Common.Localization;
-using Grand.Business.Core.Interfaces.Customers;
-using Grand.Infrastructure;
+using Grand.Business.Core.Interfaces.Customers;
+using Grand.Module.Api.Commands.Models.Customers;
using MediatR;
namespace Grand.Module.Api.Commands.Handlers.Customers;
@@ -9,17 +7,10 @@ namespace Grand.Module.Api.Commands.Handlers.Customers;
public class DeleteCustomerCommandHandler : IRequestHandler<DeleteCustomerCommand, bool>
{
private readonly ICustomerService _customerService;
- private readonly ITranslationService _translationService;
- private readonly IWorkContextAccessor _workContextAccessor;
- public DeleteCustomerCommandHandler(
- ICustomerService customerService,
- ITranslationService translationService,
- IWorkContextAccessor workContextAccessor)
+ public DeleteCustomerCommandHandler(ICustomerService customerService)
{
_customerService = customerService;
- _translationService = translationService;
- _workContextAccessor = workContextAccessor;
}
public async Task<bool> Handle(DeleteCustomerCommand request, CancellationToken cancellationToken)
diff --git a/src/Modules/Grand.Module.Api/Commands/Handlers/Customers/DeleteCustomerGroupCommandHandler.cs b/src/Modules/Grand.Module.Api/Commands/Handlers/Customers/DeleteCustomerGroupCommandHandler.cs
index b9a46ad4c..c5f7808de 100644
--- a/src/Modules/Grand.Module.Api/Commands/Handlers/Customers/DeleteCustomerGroupCommandHandler.cs
+++ b/src/Modules/Grand.Module.Api/Commands/Handlers/Customers/DeleteCustomerGroupCommandHandler.cs
@@ -1,7 +1,5 @@
-using Grand.Module.Api.Commands.Models.Customers;
-using Grand.Business.Core.Interfaces.Common.Directory;
-using Grand.Business.Core.Interfaces.Common.Localization;
-using Grand.Infrastructure;
+using Grand.Business.Core.Interfaces.Common.Directory;
+using Grand.Module.Api.Commands.Models.Customers;
using MediatR;
namespace Grand.Module.Api.Commands.Handlers.Customers;
@@ -9,17 +7,10 @@ namespace Grand.Module.Api.Commands.Handlers.Customers;
public class DeleteCustomerGroupCommandHandler : IRequestHandler<DeleteCustomerGroupCommand, bool>
{
private readonly IGroupService _groupService;
- private readonly ITranslationService _translationService;
- private readonly IWorkContextAccessor _workContextAccessor;
- public DeleteCustomerGroupCommandHandler(
- IGroupService groupService,
- ITranslationService translationService,
- IWorkContextAccessor workContextAccessor)
+ public DeleteCustomerGroupCommandHandler(IGroupService groupService)
{
_groupService = groupService;
- _translationService = translationService;
- _workContextAccessor = workContextAccessor;
}
public async Task<bool> Handle(DeleteCustomerGroupCommand request, CancellationToken cancellationToken)
diff --git a/src/Modules/Grand.Module.Api/Commands/Handlers/Customers/UpdateCustomerGroupCommandHandler.cs b/src/Modules/Grand.Module.Api/Commands/Handlers/Customers/UpdateCustomerGroupCommandHandler.cs
index 97c1122f2..21baf951c 100644
--- a/src/Modules/Grand.Module.Api/Commands/Handlers/Customers/UpdateCustomerGroupCommandHandler.cs
+++ b/src/Modules/Grand.Module.Api/Commands/Handlers/Customers/UpdateCustomerGroupCommandHandler.cs
@@ -1,9 +1,7 @@
-using Grand.Module.Api.Commands.Models.Customers;
+using Grand.Business.Core.Interfaces.Common.Directory;
+using Grand.Module.Api.Commands.Models.Customers;
using Grand.Module.Api.DTOs.Customers;
using Grand.Module.Api.Extensions;
-using Grand.Business.Core.Interfaces.Common.Directory;
-using Grand.Business.Core.Interfaces.Common.Localization;
-using Grand.Infrastructure;
using MediatR;
namespace Grand.Module.Api.Commands.Handlers.Customers;
@@ -11,17 +9,10 @@ namespace Grand.Module.Api.Commands.Handlers.Customers;
public class UpdateCustomerGroupCommandHandler : IRequestHandler<UpdateCustomerGroupCommand, CustomerGroupDto>
{
private readonly IGroupService _groupService;
- private readonly ITranslationService _translationService;
- private readonly IWorkContextAccessor _workContextAccessor;
- public UpdateCustomerGroupCommandHandler(
- IGroupService groupService,
- ITranslationService translationService,
- IWorkContextAccessor workContextAccessor)
+ public UpdateCustomerGroupCommandHandler(IGroupService groupService)
{
_groupService = groupService;
- _translationService = translationService;
- _workContextAccessor = workContextAccessor;
}
public async Task<CustomerGroupDto> Handle(UpdateCustomerGroupCommand request, CancellationToken cancellationToken)
diff --git a/src/Modules/Grand.Module.Api/Controllers/TokenWebController.cs b/src/Modules/Grand.Module.Api/Controllers/TokenWebController.cs
index 58b9b77d0..326a0a2df 100644
--- a/src/Modules/Grand.Module.Api/Controllers/TokenWebController.cs
+++ b/src/Modules/Grand.Module.Api/Controllers/TokenWebController.cs
@@ -27,19 +27,19 @@ public class TokenWebController : ControllerBase
private readonly ICustomerService _customerService;
private readonly IMediator _mediator;
private readonly IRefreshTokenService _refreshTokenService;
- private readonly IWorkContextAccessor _workContextAccessor;
+ private readonly IContextAccessor _contextAccessor;
public TokenWebController(
ICustomerService customerService,
IMediator mediator,
- IWorkContextAccessor workContextAccessor,
+ IContextAccessor contextAccessor,
IRefreshTokenService refreshTokenService,
IAntiforgery antiforgery,
FrontendAPIConfig apiConfig)
{
_customerService = customerService;
_mediator = mediator;
- _workContextAccessor = workContextAccessor;
+ _contextAccessor = contextAccessor;
_refreshTokenService = refreshTokenService;
_antiforgery = antiforgery;
_apiConfig = apiConfig;
@@ -56,7 +56,7 @@ public class TokenWebController : ControllerBase
var customer = new Customer {
CustomerGuid = Guid.NewGuid(),
Active = true,
- StoreId = _workContextAccessor.WorkContext.CurrentStore.Id,
+ StoreId = _contextAccessor.StoreContext.CurrentStore.Id,
LastActivityDateUtc = DateTime.UtcNow
};
diff --git a/src/Modules/Grand.Module.ScheduledTasks/BackgroundServices/CancelOrderScheduledTask.cs b/src/Modules/Grand.Module.ScheduledTasks/BackgroundServices/CancelOrderScheduledTask.cs
index 0548db3b3..9ae0b932e 100644
--- a/src/Modules/Grand.Module.ScheduledTasks/BackgroundServices/CancelOrderScheduledTask.cs
+++ b/src/Modules/Grand.Module.ScheduledTasks/BackgroundServices/CancelOrderScheduledTask.cs
@@ -26,8 +26,5 @@ public class CancelOrderScheduledTask : IScheduleTask
await _orderService.CancelExpiredOrders(startCancelDate);
}
- private DateTime CalculateStartCancelDate(int daysToCancelUnpaidOrder)
- {
- return DateTime.UtcNow.Date.AddDays(-daysToCancelUnpaidOrder);
- }
+ private static DateTime CalculateStartCancelDate(int daysToCancelUnpaidOrder) => DateTime.UtcNow.Date.AddDays(-daysToCancelUnpaidOrder);
}
\ No newline at end of file
diff --git a/src/Plugins/Authentication.Facebook/Infrastructure/Cache/FacebookAuthenticationEventConsumer.cs b/src/Plugins/Authentication.Facebook/Infrastructure/Cache/FacebookAuthenticationEventConsumer.cs
index 402502255..9c6432e3f 100644
--- a/src/Plugins/Authentication.Facebook/Infrastructure/Cache/FacebookAuthenticationEventConsumer.cs
+++ b/src/Plugins/Authentication.Facebook/Infrastructure/Cache/FacebookAuthenticationEventConsumer.cs
@@ -1,8 +1,8 @@
using Grand.Business.Core.Commands.Customers;
-using Grand.Business.Core.Interfaces.Common.Directory;
using Grand.Business.Core.Interfaces.Customers;
using Grand.Business.Core.Interfaces.Messages;
using Grand.Domain.Customers;
+using Grand.Domain.Stores;
using Grand.Infrastructure;
using MediatR;
using System.Security.Claims;
@@ -14,17 +14,29 @@ namespace Authentication.Facebook.Infrastructure.Cache;
/// </summary>
public class FacebookAuthenticationEventConsumer : INotificationHandler<RegisteredByExternalMethod>
{
+ #region Fields
+
+ private readonly ICustomerService _customerService;
+ private readonly IMessageProviderService _messageProviderService;
+ private readonly IContextAccessor _contextAccessor;
+ private readonly CustomerSettings _customerSettings;
+
+ private string WorkingLanguageId => _contextAccessor.WorkContext.WorkingLanguage.Id;
+ private Store CurrentStore => _contextAccessor.StoreContext.CurrentStore;
+
+ #endregion
+
#region Ctor
public FacebookAuthenticationEventConsumer(
ICustomerService customerService,
IMessageProviderService messageProviderService,
- IWorkContextAccessor workContextAccessor,
+ IContextAccessor contextAccessor,
CustomerSettings customerSettings)
{
_customerService = customerService;
_messageProviderService = messageProviderService;
- _workContextAccessor = workContextAccessor;
+ _contextAccessor = contextAccessor;
_customerSettings = customerSettings;
}
@@ -55,22 +67,10 @@ public class FacebookAuthenticationEventConsumer : INotificationHandler<Register
//notifications for admin
if (_customerSettings.NotifyNewCustomerRegistration)
- await _messageProviderService.SendCustomerRegisteredMessage(eventMessage.Customer,
- _workContextAccessor.WorkContext.CurrentStore, _workContextAccessor.WorkContext.WorkingLanguage.Id);
+ await _messageProviderService.SendCustomerRegisteredMessage(eventMessage.Customer, CurrentStore, WorkingLanguageId);
//send welcome message
- await _messageProviderService.SendCustomerWelcomeMessage(eventMessage.Customer, _workContextAccessor.WorkContext.CurrentStore,
- _workContextAccessor.WorkContext.WorkingLanguage.Id);
+ await _messageProviderService.SendCustomerWelcomeMessage(eventMessage.Customer, CurrentStore, WorkingLanguageId);
}
-
- #endregion
-
- #region Fields
-
- private readonly ICustomerService _customerService;
- private readonly IMessageProviderService _messageProviderService;
- private readonly IWorkContextAccessor _workContextAccessor;
- private readonly CustomerSettings _customerSettings;
-
#endregion
}
\ No newline at end of file
diff --git a/src/Plugins/Authentication.Google/Infrastructure/GoogleAuthenticationEventConsumer.cs b/src/Plugins/Authentication.Google/Infrastructure/GoogleAuthenticationEventConsumer.cs
index 867202321..2a8292768 100644
--- a/src/Plugins/Authentication.Google/Infrastructure/GoogleAuthenticationEventConsumer.cs
+++ b/src/Plugins/Authentication.Google/Infrastructure/GoogleAuthenticationEventConsumer.cs
@@ -1,8 +1,8 @@
using Grand.Business.Core.Commands.Customers;
-using Grand.Business.Core.Interfaces.Common.Directory;
using Grand.Business.Core.Interfaces.Customers;
using Grand.Business.Core.Interfaces.Messages;
using Grand.Domain.Customers;
+using Grand.Domain.Stores;
using Grand.Infrastructure;
using MediatR;
using System.Security.Claims;
@@ -14,18 +14,28 @@ namespace Authentication.Google.Infrastructure;
/// </summary>
public class GoogleAuthenticationEventConsumer : INotificationHandler<RegisteredByExternalMethod>
{
+ #region Fields
+
+ private readonly ICustomerService _customerService;
+ private readonly IMessageProviderService _messageProviderService;
+ private readonly IContextAccessor _contextAccessor;
+ private readonly CustomerSettings _customerSettings;
+ private string WorkingLanguageId => _contextAccessor.WorkContext.WorkingLanguage.Id;
+ private Store CurrentStore => _contextAccessor.StoreContext.CurrentStore;
+
+ #endregion
#region Ctor
public GoogleAuthenticationEventConsumer(
ICustomerService customerService,
IMessageProviderService messageProviderService,
- IWorkContextAccessor workContextAccessor,
+ IContextAccessor contextAccessor,
CustomerSettings customerSettings
)
{
_customerService = customerService;
_messageProviderService = messageProviderService;
- _workContextAccessor = workContextAccessor;
+ _contextAccessor = contextAccessor;
_customerSettings = customerSettings;
}
@@ -56,22 +66,12 @@ public class GoogleAuthenticationEventConsumer : INotificationHandler<Registered
//notifications for admin
if (_customerSettings.NotifyNewCustomerRegistration)
- await _messageProviderService.SendCustomerRegisteredMessage(eventMessage.Customer,
- _workContextAccessor.WorkContext.CurrentStore, _workContextAccessor.WorkContext.WorkingLanguage.Id);
+ await _messageProviderService.SendCustomerRegisteredMessage(eventMessage.Customer, CurrentStore, WorkingLanguageId);
//send welcome message
- await _messageProviderService.SendCustomerWelcomeMessage(eventMessage.Customer, _workContextAccessor.WorkContext.CurrentStore,
- _workContextAccessor.WorkContext.WorkingLanguage.Id);
+ await _messageProviderService.SendCustomerWelcomeMessage(eventMessage.Customer, CurrentStore, WorkingLanguageId);
}
#endregion
- #region Fields
-
- private readonly ICustomerService _customerService;
- private readonly IMessageProviderService _messageProviderService;
- private readonly IWorkContextAccessor _workContextAccessor;
- private readonly CustomerSettings _customerSettings;
-
- #endregion
}
\ No newline at end of file
diff --git a/src/Plugins/DiscountRules.Standard/Areas/Admin/Controllers/HasAllProductsController.cs b/src/Plugins/DiscountRules.Standard/Areas/Admin/Controllers/HasAllProductsController.cs
index 6a4daef46..0d7f5fc4f 100644
--- a/src/Plugins/DiscountRules.Standard/Areas/Admin/Controllers/HasAllProductsController.cs
+++ b/src/Plugins/DiscountRules.Standard/Areas/Admin/Controllers/HasAllProductsController.cs
@@ -5,9 +5,9 @@ using Grand.Business.Core.Interfaces.Common.Localization;
using Grand.Business.Core.Interfaces.Common.Security;
using Grand.Business.Core.Interfaces.Common.Stores;
using Grand.Business.Core.Interfaces.Customers;
-using Grand.Domain.Permissions;
using Grand.Domain.Catalog;
using Grand.Domain.Discounts;
+using Grand.Domain.Permissions;
using Grand.Infrastructure;
using Grand.Web.Common.Controllers;
using Grand.Web.Common.DataSource;
@@ -25,21 +25,22 @@ public class HasAllProductsController : BaseAdminPluginController
private readonly IStoreService _storeService;
private readonly ITranslationService _translationService;
private readonly IVendorService _vendorService;
- private readonly IWorkContextAccessor _workContextAccessor;
+ private readonly IContextAccessor _contextAccessor;
private readonly IEnumTranslationService _enumTranslationService;
-
+
+
public HasAllProductsController(IDiscountService discountService,
IPermissionService permissionService,
- IWorkContextAccessor workContextAccessor,
+ IContextAccessor contextAccessor,
ITranslationService translationService,
IStoreService storeService,
IVendorService vendorService,
- IProductService productService,
+ IProductService productService,
IEnumTranslationService enumTranslationService)
{
_discountService = discountService;
_permissionService = permissionService;
- _workContextAccessor = workContextAccessor;
+ _contextAccessor = contextAccessor;
_translationService = translationService;
_storeService = storeService;
_vendorService = vendorService;
@@ -49,10 +50,10 @@ public class HasAllProductsController : BaseAdminPluginController
public async Task<IActionResult> Configure(string discountId, string discountRequirementId)
{
- if (!await _permissionService.Authorize(StandardPermission.ManageDiscounts))
+ if (!await AuthorizeManageDiscounts())
return Content("Access denied");
- var discount = await _discountService.GetDiscountById(discountId);
+ var discount = await GetDiscountById(discountId);
if (discount == null)
throw new ArgumentException("Discount could not be loaded");
@@ -84,10 +85,10 @@ public class HasAllProductsController : BaseAdminPluginController
[AutoValidateAntiforgeryToken]
public async Task<IActionResult> Configure(string discountId, string discountRequirementId, string productIds)
{
- if (!await _permissionService.Authorize(StandardPermission.ManageDiscounts))
+ if (!await AuthorizeManageDiscounts())
return Content("Access denied");
- var discount = await _discountService.GetDiscountById(discountId);
+ var discount = await GetDiscountById(discountId);
if (discount == null)
throw new ArgumentException("Discount could not be loaded");
@@ -118,23 +119,21 @@ public class HasAllProductsController : BaseAdminPluginController
public async Task<IActionResult> ProductAddPopup(string btnId, string productIdsInput)
{
- if (!await _permissionService.Authorize(StandardPermission.ManageProducts))
+ if (!await AuthorizeManageProducts())
return Content("Access denied");
var model = new RequirementAllProductsModel.AddProductModel {
//a vendor should have access only to his products
- IsLoggedInAsVendor = _workContextAccessor.WorkContext.CurrentVendor != null
+ IsLoggedInAsVendor = _contextAccessor.WorkContext.CurrentVendor != null
};
//stores
- model.AvailableStores.Add(new SelectListItem
- { Text = _translationService.GetResource("Admin.Common.All"), Value = "" });
+ model.AvailableStores.Add(new SelectListItem { Text = _translationService.GetResource("Admin.Common.All"), Value = "" });
foreach (var s in await _storeService.GetAllStores())
model.AvailableStores.Add(new SelectListItem { Text = s.Shortcut, Value = s.Id });
//vendors
- model.AvailableVendors.Add(new SelectListItem
- { Text = _translationService.GetResource("Admin.Common.All"), Value = "" });
+ model.AvailableVendors.Add(new SelectListItem { Text = _translationService.GetResource("Admin.Common.All"), Value = "" });
foreach (var v in await _vendorService.GetAllVendors(showHidden: true))
model.AvailableVendors.Add(new SelectListItem { Text = v.Name, Value = v.Id });
@@ -155,11 +154,11 @@ public class HasAllProductsController : BaseAdminPluginController
public async Task<IActionResult> ProductAddPopupList(DataSourceRequest command,
RequirementAllProductsModel.AddProductModel model)
{
- if (!await _permissionService.Authorize(StandardPermission.ManageProducts))
+ if (!await AuthorizeManageProducts())
return Content("Access denied");
//a vendor should have access only to his products
- if (_workContextAccessor.WorkContext.CurrentVendor != null) model.SearchVendorId = _workContextAccessor.WorkContext.CurrentVendor.Id;
+ if (_contextAccessor.WorkContext.CurrentVendor != null) model.SearchVendorId = _contextAccessor.WorkContext.CurrentVendor.Id;
var searchCategoryIds = new List<string>();
if (!string.IsNullOrEmpty(model.SearchCategoryId))
searchCategoryIds.Add(model.SearchCategoryId);
@@ -193,7 +192,7 @@ public class HasAllProductsController : BaseAdminPluginController
{
var result = "";
- if (!await _permissionService.Authorize(StandardPermission.ManageProducts))
+ if (!await AuthorizeManageProducts())
return new JsonResult(new { Text = result });
if (string.IsNullOrWhiteSpace(productIds)) return new JsonResult(new { Text = result });
@@ -230,4 +229,19 @@ public class HasAllProductsController : BaseAdminPluginController
return new JsonResult(new { Text = result });
}
-}
\ No newline at end of file
+
+ private async Task<bool> AuthorizeManageDiscounts()
+ {
+ return await _permissionService.Authorize(StandardPermission.ManageDiscounts);
+ }
+
+ private async Task<bool> AuthorizeManageProducts()
+ {
+ return await _permissionService.Authorize(StandardPermission.ManageProducts);
+ }
+
+ private async Task<Discount> GetDiscountById(string discountId)
+ {
+ return await _discountService.GetDiscountById(discountId);
+ }
+}
diff --git a/src/Plugins/DiscountRules.Standard/Areas/Admin/Controllers/HasOneProductController.cs b/src/Plugins/DiscountRules.Standard/Areas/Admin/Controllers/HasOneProductController.cs
index ea62e179e..c9bf369db 100644
--- a/src/Plugins/DiscountRules.Standard/Areas/Admin/Controllers/HasOneProductController.cs
+++ b/src/Plugins/DiscountRules.Standard/Areas/Admin/Controllers/HasOneProductController.cs
@@ -5,13 +5,15 @@ using Grand.Business.Core.Interfaces.Common.Localization;
using Grand.Business.Core.Interfaces.Common.Security;
using Grand.Business.Core.Interfaces.Common.Stores;
using Grand.Business.Core.Interfaces.Customers;
-using Grand.Domain.Permissions;
using Grand.Domain.Catalog;
using Grand.Domain.Discounts;
+using Grand.Domain.Localization;
+using Grand.Domain.Permissions;
+using Grand.Domain.Stores;
+using Grand.Domain.Vendors;
using Grand.Infrastructure;
using Grand.Web.Common.Controllers;
using Grand.Web.Common.DataSource;
-using Grand.Web.Common.Extensions;
using Grand.Web.Common.Localization;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.Rendering;
@@ -26,21 +28,23 @@ public class HasOneProductController : BaseAdminPluginController
private readonly IStoreService _storeService;
private readonly ITranslationService _translationService;
private readonly IVendorService _vendorService;
- private readonly IWorkContextAccessor _workContextAccessor;
+ private readonly IContextAccessor _contextAccessor;
private readonly IEnumTranslationService _enumTranslationService;
+ private Vendor CurrentVendor => _contextAccessor.WorkContext.CurrentVendor;
+
public HasOneProductController(IDiscountService discountService,
IPermissionService permissionService,
- IWorkContextAccessor workContextAccessor,
+ IContextAccessor contextAccessor,
ITranslationService translationService,
IStoreService storeService,
IVendorService vendorService,
- IProductService productService,
+ IProductService productService,
IEnumTranslationService enumTranslationService)
{
_discountService = discountService;
_permissionService = permissionService;
- _workContextAccessor = workContextAccessor;
+ _contextAccessor = contextAccessor;
_translationService = translationService;
_storeService = storeService;
_vendorService = vendorService;
@@ -48,14 +52,27 @@ public class HasOneProductController : BaseAdminPluginController
_enumTranslationService = enumTranslationService;
}
- public async Task<IActionResult> Configure(string discountId, string discountRequirementId)
+ private async Task<IActionResult> AuthorizeAsync(Permission permission)
{
- if (!await _permissionService.Authorize(StandardPermission.ManageDiscounts))
+ if (!await _permissionService.Authorize(permission))
return Content("Access denied");
+ return null;
+ }
+ private async Task<Discount> GetDiscountAsync(string discountId)
+ {
var discount = await _discountService.GetDiscountById(discountId);
if (discount == null)
throw new ArgumentException("Discount could not be loaded");
+ return discount;
+ }
+
+ public async Task<IActionResult> Configure(string discountId, string discountRequirementId)
+ {
+ var authResult = await AuthorizeAsync(StandardPermission.ManageDiscounts);
+ if (authResult != null) return authResult;
+
+ var discount = await GetDiscountAsync(discountId);
var restrictedProductIds = string.Empty;
if (!string.IsNullOrEmpty(discountRequirementId))
@@ -84,12 +101,10 @@ public class HasOneProductController : BaseAdminPluginController
[AutoValidateAntiforgeryToken]
public async Task<IActionResult> Configure(string discountId, string discountRequirementId, string productIds)
{
- if (!await _permissionService.Authorize(StandardPermission.ManageDiscounts))
- return Content("Access denied");
+ var authResult = await AuthorizeAsync(StandardPermission.ManageDiscounts);
+ if (authResult != null) return authResult;
- var discount = await _discountService.GetDiscountById(discountId);
- if (discount == null)
- throw new ArgumentException("Discount could not be loaded");
+ var discount = await GetDiscountAsync(discountId);
DiscountRule discountRequirement = null;
if (!string.IsNullOrEmpty(discountRequirementId))
@@ -117,23 +132,21 @@ public class HasOneProductController : BaseAdminPluginController
public async Task<IActionResult> ProductAddPopup(string btnId, string productIdsInput)
{
- if (!await _permissionService.Authorize(StandardPermission.ManageProducts))
- return Content("Access denied");
+ var authResult = await AuthorizeAsync(StandardPermission.ManageProducts);
+ if (authResult != null) return authResult;
var model = new RequirementOneProductModel.AddProductModel {
//a vendor should have access only to his products
- IsLoggedInAsVendor = _workContextAccessor.WorkContext.CurrentVendor != null
+ IsLoggedInAsVendor = CurrentVendor != null
};
//stores
- model.AvailableStores.Add(new SelectListItem
- { Text = _translationService.GetResource("Admin.Common.All"), Value = "" });
+ model.AvailableStores.Add(new SelectListItem { Text = _translationService.GetResource("Admin.Common.All"), Value = "" });
foreach (var s in await _storeService.GetAllStores())
model.AvailableStores.Add(new SelectListItem { Text = s.Shortcut, Value = s.Id });
//vendors
- model.AvailableVendors.Add(new SelectListItem
- { Text = _translationService.GetResource("Admin.Common.All"), Value = "" });
+ model.AvailableVendors.Add(new SelectListItem { Text = _translationService.GetResource("Admin.Common.All"), Value = "" });
foreach (var v in await _vendorService.GetAllVendors(showHidden: true))
model.AvailableVendors.Add(new SelectListItem { Text = v.Name, Value = v.Id });
@@ -142,7 +155,6 @@ public class HasOneProductController : BaseAdminPluginController
model.AvailableProductTypes.Insert(0,
new SelectListItem { Text = _translationService.GetResource("Admin.Common.All"), Value = "" });
-
ViewBag.productIdsInput = productIdsInput;
ViewBag.btnId = btnId;
@@ -154,11 +166,11 @@ public class HasOneProductController : BaseAdminPluginController
public async Task<IActionResult> ProductAddPopupList(DataSourceRequest command,
RequirementOneProductModel.AddProductModel model)
{
- if (!await _permissionService.Authorize(StandardPermission.ManageProducts))
- return Content("Access denied");
+ var authResult = await AuthorizeAsync(StandardPermission.ManageProducts);
+ if (authResult != null) return authResult;
//a vendor should have access only to his products
- if (_workContextAccessor.WorkContext.CurrentVendor != null) model.SearchVendorId = _workContextAccessor.WorkContext.CurrentVendor.Id;
+ if (CurrentVendor != null) model.SearchVendorId = CurrentVendor.Id;
var searchCategoryIds = new List<string>();
if (!string.IsNullOrEmpty(model.SearchCategoryId))
@@ -191,43 +203,20 @@ public class HasOneProductController : BaseAdminPluginController
[AutoValidateAntiforgeryToken]
public async Task<IActionResult> LoadProductFriendlyNames(string productIds)
{
- var result = "";
+ var authResult = await AuthorizeAsync(StandardPermission.ManageProducts);
+ if (authResult != null) return authResult;
- if (!await _permissionService.Authorize(StandardPermission.ManageProducts))
- return new JsonResult(new { Text = result });
+ var result = "";
if (string.IsNullOrWhiteSpace(productIds)) return new JsonResult(new { Text = result });
- var ids = new List<string>();
- var rangeArray = productIds
- .Split([','], StringSplitOptions.RemoveEmptyEntries)
- .Select(x => x.Trim())
+ var ids = productIds
+ .Split(',', StringSplitOptions.RemoveEmptyEntries)
+ .Select(x => x.Split(':')[0].Trim())
.ToList();
- //we support three ways of specifying products:
- //1. The comma-separated list of product identifiers (e.g. 77, 123, 156).
- //2. The comma-separated list of product identifiers with quantities.
- // {Product ID}:{Quantity}. For example, 77:1, 123:2, 156:3
- //3. The comma-separated list of product identifiers with quantity range.
- // {Product ID}:{Min quantity}-{Max quantity}. For example, 77:1-3, 123:2-5, 156:3-8
- foreach (var str1 in rangeArray)
- {
- var str2 = str1;
- //we do not display specified quantities and ranges
- //parse only product names (before : sign)
- if (str2.Contains(':'))
- str2 = str2[..str2.IndexOf(":", StringComparison.Ordinal)];
-
- ids.Add(str2);
- }
-
var products = await _productService.GetProductsByIds(ids.ToArray(), true);
- for (var i = 0; i <= products.Count - 1; i++)
- {
- result += products[i].Name;
- if (i != products.Count - 1)
- result += ", ";
- }
+ result = string.Join(", ", products.Select(p => p.Name));
return new JsonResult(new { Text = result });
}
-}
\ No newline at end of file
+}
diff --git a/src/Plugins/DiscountRules.Standard/Providers/ShoppingCartDiscountRule.cs b/src/Plugins/DiscountRules.Standard/Providers/ShoppingCartDiscountRule.cs
index 8b0ad6ebe..b5c6c166b 100644
--- a/src/Plugins/DiscountRules.Standard/Providers/ShoppingCartDiscountRule.cs
+++ b/src/Plugins/DiscountRules.Standard/Providers/ShoppingCartDiscountRule.cs
@@ -14,15 +14,15 @@ public class ShoppingCartDiscountRule : IDiscountRule
private readonly IHttpContextAccessor _httpContextAccessor;
private readonly IProductService _productService;
private readonly ShoppingCartSettings _shoppingCartSettings;
- private readonly IWorkContextAccessor _workContextAccessor;
+ private readonly IContextAccessor _contextAccessor;
public ShoppingCartDiscountRule(
- IWorkContextAccessor workContextAccessor,
+ IContextAccessor contextAccessor,
IProductService productService,
IHttpContextAccessor httpContextAccessor,
ShoppingCartSettings shoppingCartSettings)
{
- _workContextAccessor = workContextAccessor;
+ _contextAccessor = contextAccessor;
_productService = productService;
_httpContextAccessor = httpContextAccessor;
_shoppingCartSettings = shoppingCartSettings;
@@ -50,7 +50,7 @@ public class ShoppingCartDiscountRule : IDiscountRule
return result;
}
- var cart = _workContextAccessor.WorkContext.CurrentCustomer.ShoppingCartItems
+ var cart = _contextAccessor.WorkContext.CurrentCustomer.ShoppingCartItems
.Where(sci => sci.ShoppingCartTypeId == ShoppingCartType.ShoppingCart)
.LimitPerStore(_shoppingCartSettings.SharedCartBetweenStores, request.Store.Id)
.ToList();
diff --git a/src/Plugins/Payments.BrainTree/BrainTreePaymentProvider.cs b/src/Plugins/Payments.BrainTree/BrainTreePaymentProvider.cs
index 028f90911..aec592ca0 100644
--- a/src/Plugins/Payments.BrainTree/BrainTreePaymentProvider.cs
+++ b/src/Plugins/Payments.BrainTree/BrainTreePaymentProvider.cs
@@ -242,7 +242,7 @@ public class BrainTreePaymentProvider : IPaymentProvider
if (!(result > 0)) return await Task.FromResult(result);
var currencyService = _httpContextAccessor.HttpContext!.RequestServices.GetRequiredService<ICurrencyService>();
- var workContext = _httpContextAccessor.HttpContext!.RequestServices.GetRequiredService<IWorkContextAccessor>().WorkContext;
+ var workContext = _httpContextAccessor.HttpContext!.RequestServices.GetRequiredService<IContextAccessor>().WorkContext;
result = await currencyService.ConvertFromPrimaryStoreCurrency(result, workContext.WorkingCurrency);
//return result;
diff --git a/src/Plugins/Payments.BrainTree/Controllers/PaymentBrainTreeController.cs b/src/Plugins/Payments.BrainTree/Controllers/PaymentBrainTreeController.cs
index 75b1dd2c4..83a9291c5 100644
--- a/src/Plugins/Payments.BrainTree/Controllers/PaymentBrainTreeController.cs
+++ b/src/Plugins/Payments.BrainTree/Controllers/PaymentBrainTreeController.cs
@@ -19,18 +19,18 @@ public class PaymentBrainTreeController : BasePaymentController
private readonly IOrderCalculationService _orderTotalCalculationService;
private readonly IShoppingCartService _shoppingCartService;
private readonly ITranslationService _translationService;
- private readonly IWorkContextAccessor _workContextAccessor;
+ private readonly IContextAccessor _contextAccessor;
public PaymentBrainTreeController(BrainTreePaymentSettings brainTreePaymentSettings,
IOrderCalculationService orderTotalCalculationService,
IShoppingCartService shoppingCartService,
- IWorkContextAccessor workContextAccessor,
+ IContextAccessor contextAccessor,
ITranslationService translationService)
{
_brainTreePaymentSettings = brainTreePaymentSettings;
_orderTotalCalculationService = orderTotalCalculationService;
_shoppingCartService = shoppingCartService;
- _workContextAccessor = workContextAccessor;
+ _contextAccessor = contextAccessor;
_translationService = translationService;
}
@@ -40,7 +40,7 @@ public class PaymentBrainTreeController : BasePaymentController
if (_brainTreePaymentSettings.Use3DS)
{
- var cart = await _shoppingCartService.GetShoppingCart(_workContextAccessor.WorkContext.CurrentStore.Id,
+ var cart = await _shoppingCartService.GetShoppingCart(_contextAccessor.StoreContext.CurrentStore.Id,
ShoppingCartType.ShoppingCart);
if (!cart.Any())
diff --git a/src/Plugins/Payments.BrainTree/Views/PaymentBrainTree/PaymentInfo_3DS.cshtml b/src/Plugins/Payments.BrainTree/Views/PaymentBrainTree/PaymentInfo_3DS.cshtml
index c720f4cf4..2882b7ade 100644
--- a/src/Plugins/Payments.BrainTree/Views/PaymentBrainTree/PaymentInfo_3DS.cshtml
+++ b/src/Plugins/Payments.BrainTree/Views/PaymentBrainTree/PaymentInfo_3DS.cshtml
@@ -3,7 +3,7 @@
@{
Layout = "";
}
-@inject IWorkContextAccessor _workContextAccessor
+@inject IContextAccessor _contextAccessor
<style type="text/css">
.braintree-input {
@@ -115,15 +115,15 @@
amount: '@ViewBag.OrderTotal',
nonce: payload.nonce,
challengeRequested: true,
- email: '@_workContextAccessor.WorkContext.CurrentCustomer.BillingAddress?.Email',
+ email: '@_contextAccessor.WorkContext.CurrentCustomer.BillingAddress?.Email',
billingAddress: {
- givenName: '@_workContextAccessor.WorkContext.CurrentCustomer.BillingAddress?.FirstName',
- surname: '@_workContextAccessor.WorkContext.CurrentCustomer.BillingAddress?.LastName',
- phoneNumber: '@_workContextAccessor.WorkContext.CurrentCustomer.BillingAddress?.PhoneNumber',
- streetAddress: '@_workContextAccessor.WorkContext.CurrentCustomer.BillingAddress?.Address1',
- extendedAddress: '@_workContextAccessor.WorkContext.CurrentCustomer.BillingAddress?.Address2',
- locality: '@_workContextAccessor.WorkContext.CurrentCustomer.BillingAddress?.City',
- postalCode: '@_workContextAccessor.WorkContext.CurrentCustomer.BillingAddress?.ZipPostalCode',
+ givenName: '@_contextAccessor.WorkContext.CurrentCustomer.BillingAddress?.FirstName',
+ surname: '@_contextAccessor.WorkContext.CurrentCustomer.BillingAddress?.LastName',
+ phoneNumber: '@_contextAccessor.WorkContext.CurrentCustomer.BillingAddress?.PhoneNumber',
+ streetAddress: '@_contextAccessor.WorkContext.CurrentCustomer.BillingAddress?.Address1',
+ extendedAddress: '@_contextAccessor.WorkContext.CurrentCustomer.BillingAddress?.Address2',
+ locality: '@_contextAccessor.WorkContext.CurrentCustomer.BillingAddress?.City',
+ postalCode: '@_contextAccessor.WorkContext.CurrentCustomer.BillingAddress?.ZipPostalCode',
},
onLookupComplete: function (data, next) {
// use `data` here, then call `next()`
diff --git a/src/Plugins/Payments.CashOnDelivery/Areas/Admin/Controllers/PaymentCashOnDeliveryController.cs b/src/Plugins/Payments.CashOnDelivery/Areas/Admin/Controllers/PaymentCashOnDeliveryController.cs
index a7ae30271..c14c995ca 100644
--- a/src/Plugins/Payments.CashOnDelivery/Areas/Admin/Controllers/PaymentCashOnDeliveryController.cs
+++ b/src/Plugins/Payments.CashOnDelivery/Areas/Admin/Controllers/PaymentCashOnDeliveryController.cs
@@ -1,12 +1,9 @@
using Grand.Business.Core.Interfaces.Common.Configuration;
using Grand.Business.Core.Interfaces.Common.Localization;
-using Grand.Business.Core.Interfaces.Common.Stores;
using Grand.Domain.Permissions;
-using Grand.Domain.Common;
-using Grand.Domain.Customers;
-using Grand.Infrastructure;
using Grand.Web.Common.Controllers;
using Grand.Web.Common.Filters;
+using Grand.Web.Common.Helpers;
using Grand.Web.Common.Security.Authorization;
using Microsoft.AspNetCore.Mvc;
using Payments.CashOnDelivery.Models;
@@ -19,41 +16,23 @@ namespace Payments.CashOnDelivery.Areas.Admin.Controllers;
public class PaymentCashOnDeliveryController : BasePaymentController
{
private readonly ISettingService _settingService;
- private readonly IStoreService _storeService;
private readonly ITranslationService _translationService;
- private readonly IWorkContextAccessor _workContextAccessor;
+ private readonly IAdminStoreService _adminStoreService;
-
- public PaymentCashOnDeliveryController(IWorkContextAccessor workContextAccessor,
- IStoreService storeService,
+ public PaymentCashOnDeliveryController(
ISettingService settingService,
- ITranslationService translationService)
+ ITranslationService translationService,
+ IAdminStoreService adminStoreService)
{
- _workContextAccessor = workContextAccessor;
- _storeService = storeService;
_settingService = settingService;
_translationService = translationService;
- }
-
-
- protected virtual async Task<string> GetActiveStore(IStoreService storeService, IWorkContext workContext)
- {
- var stores = await storeService.GetAllStores();
- if (stores.Count < 2)
- return stores.FirstOrDefault().Id;
-
- var storeId =
- workContext.CurrentCustomer.GetUserFieldFromEntity<string>(SystemCustomerFieldNames
- .AdminAreaStoreScopeConfiguration);
- var store = await storeService.GetStoreById(storeId);
-
- return store != null ? store.Id : "";
+ _adminStoreService = adminStoreService;
}
public async Task<IActionResult> Configure()
{
//load settings for a chosen store scope
- var storeScope = await GetActiveStore(_storeService, _workContextAccessor.WorkContext);
+ var storeScope = await _adminStoreService.GetActiveStore();
var cashOnDeliveryPaymentSettings = await _settingService.LoadSetting<CashOnDeliveryPaymentSettings>(storeScope);
var model = new ConfigurationModel {
@@ -78,7 +57,7 @@ public class PaymentCashOnDeliveryController : BasePaymentController
return await Configure();
//load settings for a chosen store scope
- var storeScope = await GetActiveStore(_storeService, _workContextAccessor.WorkContext);
+ var storeScope = await _adminStoreService.GetActiveStore();
var cashOnDeliveryPaymentSettings = await _settingService.LoadSetting<CashOnDeliveryPaymentSettings>(storeScope);
//save settings
diff --git a/src/Plugins/Payments.CashOnDelivery/CashOnDeliveryPaymentProvider.cs b/src/Plugins/Payments.CashOnDelivery/CashOnDeliveryPaymentProvider.cs
index fb935724b..2857e877f 100644
--- a/src/Plugins/Payments.CashOnDelivery/CashOnDeliveryPaymentProvider.cs
+++ b/src/Plugins/Payments.CashOnDelivery/CashOnDeliveryPaymentProvider.cs
@@ -103,7 +103,7 @@ public class CashOnDeliveryPaymentProvider : IPaymentProvider
if (!(result > 0)) return result;
var currencyService = _httpContextAccessor.HttpContext!.RequestServices.GetRequiredService<ICurrencyService>();
- var workContext = _httpContextAccessor.HttpContext!.RequestServices.GetRequiredService<IWorkContextAccessor>().WorkContext;
+ var workContext = _httpContextAccessor.HttpContext!.RequestServices.GetRequiredService<IContextAccessor>().WorkContext;
result = await currencyService.ConvertFromPrimaryStoreCurrency(result, workContext.WorkingCurrency);
//return result;
diff --git a/src/Plugins/Payments.CashOnDelivery/Controllers/PaymentCashOnDeliveryController.cs b/src/Plugins/Payments.CashOnDelivery/Controllers/PaymentCashOnDeliveryController.cs
index f340757cc..18f9174df 100644
--- a/src/Plugins/Payments.CashOnDelivery/Controllers/PaymentCashOnDeliveryController.cs
+++ b/src/Plugins/Payments.CashOnDelivery/Controllers/PaymentCashOnDeliveryController.cs
@@ -9,19 +9,19 @@ namespace Payments.CashOnDelivery.Controllers;
public class PaymentCashOnDeliveryController : BasePaymentController
{
private readonly ISettingService _settingService;
- private readonly IWorkContextAccessor _workContextAccessor;
+ private readonly IContextAccessor _contextAccessor;
public PaymentCashOnDeliveryController(
- IWorkContextAccessor workContextAccessor,
+ IContextAccessor contextAccessor,
ISettingService settingService)
{
- _workContextAccessor = workContextAccessor;
+ _contextAccessor = contextAccessor;
_settingService = settingService;
}
public async Task<IActionResult> PaymentInfo()
{
- var cashOnDeliveryPaymentSettings = await _settingService.LoadSetting<CashOnDeliveryPaymentSettings>(_workContextAccessor.WorkContext.CurrentStore.Id);
+ var cashOnDeliveryPaymentSettings = await _settingService.LoadSetting<CashOnDeliveryPaymentSettings>(_contextAccessor.StoreContext.CurrentStore.Id);
var model = new PaymentInfoModel {
DescriptionText = cashOnDeliveryPaymentSettings.DescriptionText
diff --git a/src/Plugins/Payments.StripeCheckout/Areas/Admin/Controllers/StripeCheckoutController.cs b/src/Plugins/Payments.StripeCheckout/Areas/Admin/Controllers/StripeCheckoutController.cs
index 07a16723b..b1e44a16a 100644
--- a/src/Plugins/Payments.StripeCheckout/Areas/Admin/Controllers/StripeCheckoutController.cs
+++ b/src/Plugins/Payments.StripeCheckout/Areas/Admin/Controllers/StripeCheckoutController.cs
@@ -1,13 +1,10 @@
using Grand.Business.Core.Interfaces.Common.Configuration;
using Grand.Business.Core.Interfaces.Common.Localization;
using Grand.Business.Core.Interfaces.Common.Security;
-using Grand.Business.Core.Interfaces.Common.Stores;
using Grand.Domain.Permissions;
-using Grand.Domain.Common;
-using Grand.Domain.Customers;
-using Grand.Infrastructure;
using Grand.Web.Common.Controllers;
using Grand.Web.Common.Filters;
+using Grand.Web.Common.Helpers;
using Grand.Web.Common.Security.Authorization;
using Microsoft.AspNetCore.Mvc;
using Payments.StripeCheckout.Models;
@@ -21,44 +18,28 @@ public class StripeCheckoutController : BasePaymentController
{
private readonly IPermissionService _permissionService;
private readonly ISettingService _settingService;
- private readonly IStoreService _storeService;
private readonly ITranslationService _translationService;
- private readonly IWorkContextAccessor _workContextAccessor;
+ private readonly IAdminStoreService _adminStoreService;
- public StripeCheckoutController(IWorkContextAccessor workContextAccessor,
- IStoreService storeService,
+ public StripeCheckoutController(
ISettingService settingService,
ITranslationService translationService,
- IPermissionService permissionService)
+ IPermissionService permissionService,
+ IAdminStoreService adminStoreService)
{
- _workContextAccessor = workContextAccessor;
- _storeService = storeService;
+ _adminStoreService = adminStoreService;
_settingService = settingService;
_translationService = translationService;
_permissionService = permissionService;
}
- private async Task<string> GetActiveStore()
- {
- var stores = await _storeService.GetAllStores();
- if (stores.Count < 2)
- return stores.FirstOrDefault()?.Id;
-
- var storeId =
- _workContextAccessor.WorkContext.CurrentCustomer.GetUserFieldFromEntity<string>(SystemCustomerFieldNames
- .AdminAreaStoreScopeConfiguration);
- var store = await _storeService.GetStoreById(storeId);
-
- return store != null ? store.Id : "";
- }
-
public async Task<IActionResult> Configure()
{
if (!await _permissionService.Authorize(StandardPermission.ManagePaymentMethods))
return AccessDeniedView();
//load settings for a chosen store scope
- var storeScope = await GetActiveStore();
+ var storeScope = await _adminStoreService.GetActiveStore();
var stripeCheckoutPaymentSettings = await _settingService.LoadSetting<StripeCheckoutPaymentSettings>(storeScope);
var model = new ConfigurationModel {
@@ -83,7 +64,7 @@ public class StripeCheckoutController : BasePaymentController
return await Configure();
//load settings for a chosen store scope
- var storeScope = await GetActiveStore();
+ var storeScope = await _adminStoreService.GetActiveStore();
var stripeCheckoutPaymentSettings = await _settingService.LoadSetting<StripeCheckoutPaymentSettings>(storeScope);
//save settings
diff --git a/src/Plugins/Payments.StripeCheckout/Areas/Admin/Views/StripeCheckout/Configure.cshtml b/src/Plugins/Payments.StripeCheckout/Areas/Admin/Views/StripeCheckout/Configure.cshtml
index b72e79a10..7eeb90901 100644
--- a/src/Plugins/Payments.StripeCheckout/Areas/Admin/Views/StripeCheckout/Configure.cshtml
+++ b/src/Plugins/Payments.StripeCheckout/Areas/Admin/Views/StripeCheckout/Configure.cshtml
@@ -1,10 +1,10 @@
@inject IUrlHelperFactory UrlHelperFactory
@inject IActionContextAccessor ActionContextAccessor
-@inject IWorkContextAccessor WorkContextAccessor
+@inject IContextAccessor contextAccessor
@{
Layout = "_ConfigurePlugin";
var urlHelper = UrlHelperFactory.GetUrlHelper(ActionContextAccessor.ActionContext!);
- var webhookUrl = WorkContextAccessor.WorkContext.CurrentHost.Url.TrimEnd('/') + urlHelper.RouteUrl(StripeCheckoutDefaults.WebHook);
+ var webhookUrl = contextAccessor.StoreContext.CurrentHost.Url.TrimEnd('/') + urlHelper.RouteUrl(StripeCheckoutDefaults.WebHook);
}
@using Grand.Infrastructure
@using Microsoft.AspNetCore.Mvc.Infrastructure
diff --git a/src/Plugins/Payments.StripeCheckout/Controllers/PaymentStripeCheckoutController.cs b/src/Plugins/Payments.StripeCheckout/Controllers/PaymentStripeCheckoutController.cs
index a4c438c96..e97fc9ef3 100644
--- a/src/Plugins/Payments.StripeCheckout/Controllers/PaymentStripeCheckoutController.cs
+++ b/src/Plugins/Payments.StripeCheckout/Controllers/PaymentStripeCheckoutController.cs
@@ -19,17 +19,17 @@ public class PaymentStripeCheckoutController : BasePaymentController
private readonly IPaymentTransactionService _paymentTransactionService;
private readonly StripeCheckoutPaymentSettings _stripeCheckoutPaymentSettings;
private readonly IStripeCheckoutService _stripeCheckoutService;
- private readonly IWorkContextAccessor _workContextAccessor;
+ private readonly IContextAccessor _contextAccessor;
public PaymentStripeCheckoutController(
- IWorkContextAccessor workContextAccessor,
+ IContextAccessor contextAccessor,
IOrderService orderService,
ILogger<PaymentStripeCheckoutController> logger,
IPaymentTransactionService paymentTransactionService,
PaymentSettings paymentSettings,
StripeCheckoutPaymentSettings stripeCheckoutPaymentSettings, IStripeCheckoutService stripeCheckoutService)
{
- _workContextAccessor = workContextAccessor;
+ _contextAccessor = contextAccessor;
_orderService = orderService;
_logger = logger;
_paymentTransactionService = paymentTransactionService;
@@ -56,7 +56,7 @@ public class PaymentStripeCheckoutController : BasePaymentController
public async Task<IActionResult> CancelOrder(string orderId)
{
var order = await _orderService.GetOrderById(orderId);
- if (order != null && order.CustomerId == _workContextAccessor.WorkContext.CurrentCustomer.Id)
+ if (order != null && order.CustomerId == _contextAccessor.WorkContext.CurrentCustomer.Id)
return RedirectToRoute("OrderDetails", new { orderId = order.Id });
return RedirectToRoute("HomePage");
diff --git a/src/Plugins/Payments.StripeCheckout/Services/StripeCheckoutService.cs b/src/Plugins/Payments.StripeCheckout/Services/StripeCheckoutService.cs
index 7509d7800..f25399af6 100644
--- a/src/Plugins/Payments.StripeCheckout/Services/StripeCheckoutService.cs
+++ b/src/Plugins/Payments.StripeCheckout/Services/StripeCheckoutService.cs
@@ -15,16 +15,16 @@ public class StripeCheckoutService : IStripeCheckoutService
private readonly IMediator _mediator;
private readonly IPaymentTransactionService _paymentTransactionService;
private readonly StripeCheckoutPaymentSettings _stripeCheckoutPaymentSettings;
- private readonly IWorkContextAccessor _workContextAccessor;
+ private readonly IContextAccessor _contextAccessor;
public StripeCheckoutService(
- IWorkContextAccessor workContextAccessor,
+ IContextAccessor contextAccessor,
StripeCheckoutPaymentSettings stripeCheckoutPaymentSettings,
ILogger<StripeCheckoutService> logger,
IMediator mediator,
IPaymentTransactionService paymentTransactionService)
{
- _workContextAccessor = workContextAccessor;
+ _contextAccessor = contextAccessor;
_stripeCheckoutPaymentSettings = stripeCheckoutPaymentSettings;
_logger = logger;
_mediator = mediator;
@@ -95,7 +95,7 @@ public class StripeCheckoutService : IStripeCheckoutService
{
StripeConfiguration.ApiKey = _stripeCheckoutPaymentSettings.ApiKey;
- var storeLocation = _workContextAccessor.WorkContext.CurrentHost.Url.TrimEnd('/');
+ var storeLocation = _contextAccessor.StoreContext.CurrentHost.Url.TrimEnd('/');
var options = new SessionCreateOptions {
LineItems = [
diff --git a/src/Plugins/Shipping.ByWeight/ByWeightShippingProvider.cs b/src/Plugins/Shipping.ByWeight/ByWeightShippingProvider.cs
index c4186992c..ae5873311 100644
--- a/src/Plugins/Shipping.ByWeight/ByWeightShippingProvider.cs
+++ b/src/Plugins/Shipping.ByWeight/ByWeightShippingProvider.cs
@@ -25,7 +25,7 @@ public class ByWeightShippingCalcPlugin : IShippingRateCalculationProvider
public ByWeightShippingCalcPlugin(
IShippingMethodService shippingMethodService,
- IWorkContextAccessor workContextAccessor,
+ IContextAccessor contextAccessor,
ITranslationService translationService,
IProductService productService,
ICheckoutAttributeParser checkoutAttributeParser,
@@ -34,7 +34,7 @@ public class ByWeightShippingCalcPlugin : IShippingRateCalculationProvider
ByWeightShippingSettings byWeightShippingSettings)
{
_shippingMethodService = shippingMethodService;
- _workContextAccessor = workContextAccessor;
+ _contextAccessor = contextAccessor;
_translationService = translationService;
_productService = productService;
_checkoutAttributeParser = checkoutAttributeParser;
@@ -89,7 +89,7 @@ public class ByWeightShippingCalcPlugin : IShippingRateCalculationProvider
#region Fields
private readonly IShippingMethodService _shippingMethodService;
- private readonly IWorkContextAccessor _workContextAccessor;
+ private readonly IContextAccessor _contextAccessor;
private readonly ITranslationService _translationService;
private readonly IProductService _productService;
private readonly ICheckoutAttributeParser _checkoutAttributeParser;
@@ -207,7 +207,7 @@ public class ByWeightShippingCalcPlugin : IShippingRateCalculationProvider
var storeId = getShippingOptionRequest.StoreId;
if (string.IsNullOrEmpty(storeId))
- storeId = _workContextAccessor.WorkContext.CurrentStore.Id;
+ storeId = _contextAccessor.StoreContext.CurrentStore.Id;
var countryId = getShippingOptionRequest.ShippingAddress.CountryId;
var stateProvinceId = getShippingOptionRequest.ShippingAddress.StateProvinceId;
@@ -231,7 +231,7 @@ public class ByWeightShippingCalcPlugin : IShippingRateCalculationProvider
var weight = await GetTotalWeight(getShippingOptionRequest);
var shippingMethods =
- await _shippingMethodService.GetAllShippingMethods(countryId, _workContextAccessor.WorkContext.CurrentCustomer);
+ await _shippingMethodService.GetAllShippingMethods(countryId, _contextAccessor.WorkContext.CurrentCustomer);
foreach (var shippingMethod in shippingMethods)
{
double? rate = null;
@@ -251,10 +251,10 @@ public class ByWeightShippingCalcPlugin : IShippingRateCalculationProvider
if (rate is not null)
{
var shippingOption = new ShippingOption {
- Name = shippingMethod.GetTranslation(x => x.Name, _workContextAccessor.WorkContext.WorkingLanguage.Id),
- Description = shippingMethod.GetTranslation(x => x.Description, _workContextAccessor.WorkContext.WorkingLanguage.Id),
+ Name = shippingMethod.GetTranslation(x => x.Name, _contextAccessor.WorkContext.WorkingLanguage.Id),
+ Description = shippingMethod.GetTranslation(x => x.Description, _contextAccessor.WorkContext.WorkingLanguage.Id),
Rate = await _currencyService.ConvertFromPrimaryStoreCurrency(rate.Value,
- _workContextAccessor.WorkContext.WorkingCurrency)
+ _contextAccessor.WorkContext.WorkingCurrency)
};
response.ShippingOptions.Add(shippingOption);
}
diff --git a/src/Plugins/Shipping.FixedRateShipping/FixedRateShippingProvider.cs b/src/Plugins/Shipping.FixedRateShipping/FixedRateShippingProvider.cs
index 69a7a2ecc..1323187b8 100644
--- a/src/Plugins/Shipping.FixedRateShipping/FixedRateShippingProvider.cs
+++ b/src/Plugins/Shipping.FixedRateShipping/FixedRateShippingProvider.cs
@@ -20,12 +20,12 @@ public class FixedRateShippingProvider : IShippingRateCalculationProvider
private readonly IShippingMethodService _shippingMethodService;
private readonly ITranslationService _translationService;
- private readonly IWorkContextAccessor _workContextAccessor;
+ private readonly IContextAccessor _contextAccessor;
public FixedRateShippingProvider(
IShippingMethodService shippingMethodService,
- IWorkContextAccessor workContextAccessor,
+ IContextAccessor contextAccessor,
ISettingService settingService,
ICurrencyService currencyService,
ITranslationService translationService,
@@ -33,7 +33,7 @@ public class FixedRateShippingProvider : IShippingRateCalculationProvider
)
{
_shippingMethodService = shippingMethodService;
- _workContextAccessor = workContextAccessor;
+ _contextAccessor = contextAccessor;
_settingService = settingService;
_currencyService = currencyService;
_translationService = translationService;
@@ -68,10 +68,10 @@ public class FixedRateShippingProvider : IShippingRateCalculationProvider
foreach (var shippingMethod in shippingMethods)
{
var shippingOption = new ShippingOption {
- Name = shippingMethod.GetTranslation(x => x.Name, _workContextAccessor.WorkContext.WorkingLanguage.Id),
- Description = shippingMethod.GetTranslation(x => x.Description, _workContextAccessor.WorkContext.WorkingLanguage.Id),
+ Name = shippingMethod.GetTranslation(x => x.Name, _contextAccessor.WorkContext.WorkingLanguage.Id),
+ Description = shippingMethod.GetTranslation(x => x.Description, _contextAccessor.WorkContext.WorkingLanguage.Id),
Rate = await _currencyService.ConvertFromPrimaryStoreCurrency(await GetRate(shippingMethod.Id),
- _workContextAccessor.WorkContext.WorkingCurrency)
+ _contextAccessor.WorkContext.WorkingCurrency)
};
response.ShippingOptions.Add(shippingOption);
}
diff --git a/src/Plugins/Shipping.ShippingPoint/Controllers/SelectedShippingPointController.cs b/src/Plugins/Shipping.ShippingPoint/Controllers/SelectedShippingPointController.cs
index a144e2ce5..305f5d3b8 100644
--- a/src/Plugins/Shipping.ShippingPoint/Controllers/SelectedShippingPointController.cs
+++ b/src/Plugins/Shipping.ShippingPoint/Controllers/SelectedShippingPointController.cs
@@ -16,20 +16,20 @@ public class SelectedShippingPointController : Controller
private readonly IPriceFormatter _priceFormatter;
private readonly IShippingPointService _shippingPointService;
private readonly ITranslationService _translationService;
- private readonly IWorkContextAccessor _workContextAccessor;
+ private readonly IContextAccessor _contextAccessor;
public SelectedShippingPointController(
IShippingPointService shippingPointService,
ICountryService countryService,
IPriceFormatter priceFormatter,
- IWorkContextAccessor workContextAccessor,
+ IContextAccessor contextAccessor,
ICurrencyService currencyService,
ITranslationService translationService)
{
_shippingPointService = shippingPointService;
_countryService = countryService;
_priceFormatter = priceFormatter;
- _workContextAccessor = workContextAccessor;
+ _contextAccessor = contextAccessor;
_currencyService = currencyService;
_translationService = translationService;
}
@@ -40,8 +40,8 @@ public class SelectedShippingPointController : Controller
if (shippingPoint == null) return Content("ShippingPointController: given Shipping Option doesn't exist");
var rateBase =
await _currencyService.ConvertFromPrimaryStoreCurrency(shippingPoint.PickupFee,
- _workContextAccessor.WorkContext.WorkingCurrency);
- var fee = _priceFormatter.FormatPrice(rateBase, _workContextAccessor.WorkContext.WorkingCurrency);
+ _contextAccessor.WorkContext.WorkingCurrency);
+ var fee = _priceFormatter.FormatPrice(rateBase, _contextAccessor.WorkContext.WorkingCurrency);
var viewModel = new PointModel {
ShippingPointName = shippingPoint.ShippingPointName,
@@ -62,7 +62,7 @@ public class SelectedShippingPointController : Controller
if (parameter != _translationService.GetResource("Shipping.ShippingPoint.PluginName"))
return Content("ShippingPointController: given Shipping Option doesn't exist");
- var shippingPoints = await _shippingPointService.GetAllStoreShippingPoint(_workContextAccessor.WorkContext.CurrentStore.Id);
+ var shippingPoints = await _shippingPointService.GetAllStoreShippingPoint(_contextAccessor.StoreContext.CurrentStore.Id);
var shippingPointsModel = new List<SelectListItem> {
new() { Value = "", Text = _translationService.GetResource("Shipping.ShippingPoint.SelectShippingOption") }
diff --git a/src/Plugins/Shipping.ShippingPoint/ShippingPointRateProvider.cs b/src/Plugins/Shipping.ShippingPoint/ShippingPointRateProvider.cs
index dc8f0efd7..c8158692c 100644
--- a/src/Plugins/Shipping.ShippingPoint/ShippingPointRateProvider.cs
+++ b/src/Plugins/Shipping.ShippingPoint/ShippingPointRateProvider.cs
@@ -23,7 +23,7 @@ public class ShippingPointRateProvider : IShippingRateCalculationProvider
public ShippingPointRateProvider(
IShippingPointService shippingPointService,
ITranslationService translationService,
- IWorkContextAccessor workContextAccessor,
+ IContextAccessor contextAccessor,
ICustomerService customerService,
ICountryService countryService,
ICurrencyService currencyService,
@@ -32,7 +32,7 @@ public class ShippingPointRateProvider : IShippingRateCalculationProvider
{
_shippingPointService = shippingPointService;
_translationService = translationService;
- _workContextAccessor = workContextAccessor;
+ _contextAccessor = contextAccessor;
_customerService = customerService;
_countryService = countryService;
_currencyService = currencyService;
@@ -45,7 +45,7 @@ public class ShippingPointRateProvider : IShippingRateCalculationProvider
private readonly IShippingPointService _shippingPointService;
private readonly ITranslationService _translationService;
- private readonly IWorkContextAccessor _workContextAccessor;
+ private readonly IContextAccessor _contextAccessor;
private readonly ICustomerService _customerService;
private readonly ICountryService _countryService;
private readonly ICurrencyService _currencyService;
@@ -110,25 +110,25 @@ public class ShippingPointRateProvider : IShippingRateCalculationProvider
return new List<string> { _translationService.GetResource("Shipping.ShippingPoint.SelectBeforeProceed") };
//override price
- var offeredShippingOptions = _workContextAccessor.WorkContext.CurrentCustomer.GetUserFieldFromEntity<List<ShippingOption>>(SystemCustomerFieldNames.OfferedShippingOptions, _workContextAccessor.WorkContext.CurrentStore.Id);
+ var offeredShippingOptions = _contextAccessor.WorkContext.CurrentCustomer.GetUserFieldFromEntity<List<ShippingOption>>(SystemCustomerFieldNames.OfferedShippingOptions, _contextAccessor.StoreContext.CurrentStore.Id);
offeredShippingOptions.Find(x => x.Name == shippingMethodName).Rate =
await _currencyService.ConvertFromPrimaryStoreCurrency(chosenShippingOption.PickupFee,
- _workContextAccessor.WorkContext.WorkingCurrency);
+ _contextAccessor.WorkContext.WorkingCurrency);
await _customerService.UpdateUserField(
- _workContextAccessor.WorkContext.CurrentCustomer,
+ _contextAccessor.WorkContext.CurrentCustomer,
SystemCustomerFieldNames.OfferedShippingOptions,
offeredShippingOptions,
- _workContextAccessor.WorkContext.CurrentStore.Id);
+ _contextAccessor.StoreContext.CurrentStore.Id);
var forCustomer =
$"<strong>{_translationService.GetResource("Shipping.ShippingPoint.Fields.ShippingPointName")}:</strong> {chosenShippingOption.ShippingPointName}<br><strong>{_translationService.GetResource("Shipping.ShippingPoint.Fields.Description")}:</strong> {chosenShippingOption.Description}<br>";
await _customerService.UpdateUserField(
- _workContextAccessor.WorkContext.CurrentCustomer,
+ _contextAccessor.WorkContext.CurrentCustomer,
SystemCustomerFieldNames.ShippingOptionAttributeDescription,
forCustomer,
- _workContextAccessor.WorkContext.CurrentStore.Id);
+ _contextAccessor.StoreContext.CurrentStore.Id);
var serializedObject = new ShippingPointSerializable {
Id = chosenShippingOption.Id,
@@ -152,10 +152,10 @@ public class ShippingPointRateProvider : IShippingRateCalculationProvider
serializedAttribute = stringBuilder.ToString();
}
- await _customerService.UpdateUserField(_workContextAccessor.WorkContext.CurrentCustomer,
+ await _customerService.UpdateUserField(_contextAccessor.WorkContext.CurrentCustomer,
SystemCustomerFieldNames.ShippingOptionAttribute,
serializedAttribute,
- _workContextAccessor.WorkContext.CurrentStore.Id);
+ _contextAccessor.StoreContext.CurrentStore.Id);
return new List<string>();
}
diff --git a/src/Plugins/Tax.CountryStateZip/CountryStateZipTaxProvider.cs b/src/Plugins/Tax.CountryStateZip/CountryStateZipTaxProvider.cs
index 34a5eee53..48cd0c96e 100644
--- a/src/Plugins/Tax.CountryStateZip/CountryStateZipTaxProvider.cs
+++ b/src/Plugins/Tax.CountryStateZip/CountryStateZipTaxProvider.cs
@@ -15,18 +15,18 @@ public class CountryStateZipTaxProvider : ITaxProvider
private readonly CountryStateZipTaxSettings _countryStateZipTaxSettings;
private readonly ITaxRateService _taxRateService;
private readonly ITranslationService _translationService;
- private readonly IWorkContextAccessor _workContextAccessor;
+ private readonly IContextAccessor _contextAccessor;
public CountryStateZipTaxProvider(ITranslationService translationService,
ICacheBase cacheBase,
- IWorkContextAccessor workContextAccessor,
+ IContextAccessor contextAccessor,
ITaxRateService taxRateService,
CountryStateZipTaxSettings countryStateZipTaxSettings)
{
_translationService = translationService;
_cacheBase = cacheBase;
- _workContextAccessor = workContextAccessor;
+ _contextAccessor = contextAccessor;
_taxRateService = taxRateService;
_countryStateZipTaxSettings = countryStateZipTaxSettings;
}
@@ -74,7 +74,7 @@ public class CountryStateZipTaxProvider : ITaxProvider
});
});
- var storeId = _workContextAccessor.WorkContext.CurrentStore.Id;
+ var storeId = _contextAccessor.StoreContext.CurrentStore.Id;
var taxCategoryId = calculateTaxRequest.TaxCategoryId;
var countryId = calculateTaxRequest.Address.CountryId;
var stateProvinceId = calculateTaxRequest.Address.StateProvinceId;
diff --git a/src/Plugins/Theme.Modern/Content/css/home/home.css b/src/Plugins/Theme.Modern/Content/css/home/home.css
index 646ce7adb..6cb9b4feb 100644
--- a/src/Plugins/Theme.Modern/Content/css/home/home.css
+++ b/src/Plugins/Theme.Modern/Content/css/home/home.css
@@ -690,7 +690,7 @@
padding-right: 0;
}
.home-page.toggled .product-box-slide {
- padding-left: calc((100% - 1165x) / 2);
+ padding-left: calc((100% - 1165px) / 2);
padding-right: calc((100% - 1165px) / 2);
}
}
diff --git a/src/Plugins/Theme.Modern/Views/Modern/Blog/BlogPost.cshtml b/src/Plugins/Theme.Modern/Views/Modern/Blog/BlogPost.cshtml
index a2b361849..9e4f4eeb3 100644
--- a/src/Plugins/Theme.Modern/Views/Modern/Blog/BlogPost.cshtml
+++ b/src/Plugins/Theme.Modern/Views/Modern/Blog/BlogPost.cshtml
@@ -1,5 +1,5 @@
@model BlogPostModel
-@inject IWorkContextAccessor workContextAccessor
+@inject IContextAccessor contextAccessor
@inject IPageHeadBuilder pagebuilder
@{
Layout = "_TwoColumns";
diff --git a/src/Plugins/Theme.Modern/Views/Modern/Blog/List.cshtml b/src/Plugins/Theme.Modern/Views/Modern/Blog/List.cshtml
index 6eb1ac864..f8e636af5 100644
--- a/src/Plugins/Theme.Modern/Views/Modern/Blog/List.cshtml
+++ b/src/Plugins/Theme.Modern/Views/Modern/Blog/List.cshtml
@@ -1,5 +1,5 @@
@model BlogPostListModel
-@inject IWorkContextAccessor workContextAccessor
+@inject IContextAccessor contextAccessor
@inject IPageHeadBuilder pagebuilder
@{
Layout = "_TwoColumns";
diff --git a/src/Plugins/Theme.Modern/Views/Modern/Checkout/Completed.cshtml b/src/Plugins/Theme.Modern/Views/Modern/Checkout/Completed.cshtml
index 8edd1e756..5f6fd4eef 100644
--- a/src/Plugins/Theme.Modern/Views/Modern/Checkout/Completed.cshtml
+++ b/src/Plugins/Theme.Modern/Views/Modern/Checkout/Completed.cshtml
@@ -1,4 +1,4 @@
-@inject IWorkContextAccessor workContextAccessor
+@inject IContextAccessor contextAccessor
@model CheckoutCompletedModel
@{
diff --git a/src/Plugins/Theme.Modern/Views/Modern/Product/ProductLayout.Simple.cshtml b/src/Plugins/Theme.Modern/Views/Modern/Product/ProductLayout.Simple.cshtml
index dfc1aaf83..19817c0ae 100644
--- a/src/Plugins/Theme.Modern/Views/Modern/Product/ProductLayout.Simple.cshtml
+++ b/src/Plugins/Theme.Modern/Views/Modern/Product/ProductLayout.Simple.cshtml
@@ -1,6 +1,6 @@
@model ProductDetailsModel
@inject SeoSettings seoSettings
-@inject IWorkContextAccessor workContextAccessor
+@inject IContextAccessor contextAccessor
@inject IPageHeadBuilder pagebuilder
@{
diff --git a/src/Plugins/Theme.Modern/Views/Modern/Shared/Components/Menu/Default.cshtml b/src/Plugins/Theme.Modern/Views/Modern/Shared/Components/Menu/Default.cshtml
index 48341c9c2..461789b60 100644
--- a/src/Plugins/Theme.Modern/Views/Modern/Shared/Components/Menu/Default.cshtml
+++ b/src/Plugins/Theme.Modern/Views/Modern/Shared/Components/Menu/Default.cshtml
@@ -61,7 +61,14 @@
<span class="go-forward"></span>
</li>
}
-@if (Model.DisplaySearchMenu | Model.DisplayNewProductsMenu | Model.DisplayCustomerMenu | Model.DisplayBlogMenu | Model.DisplayContactUsMenu | Model.Pages.Any())
+@functions {
+ private bool ShouldDisplayMenu()
+ {
+ return Model.DisplaySearchMenu || Model.DisplayNewProductsMenu || Model.DisplayCustomerMenu || Model.DisplayBlogMenu || Model.DisplayContactUsMenu || Model.Pages.Any();
+ }
+}
+
+@if (ShouldDisplayMenu())
{
<li class="other-links">
<ul>
diff --git a/src/Plugins/Theme.Modern/Views/Modern/Shared/Components/SearchBox/Default.cshtml b/src/Plugins/Theme.Modern/Views/Modern/Shared/Components/SearchBox/Default.cshtml
index 45bb47e34..95eccc29c 100644
--- a/src/Plugins/Theme.Modern/Views/Modern/Shared/Components/SearchBox/Default.cshtml
+++ b/src/Plugins/Theme.Modern/Views/Modern/Shared/Components/SearchBox/Default.cshtml
@@ -1,9 +1,9 @@
@using Grand.Domain.Blogs
@model SearchBoxModel
@inject BlogSettings blogSettings
-@inject IWorkContextAccessor workContextAccessor
+@inject IContextAccessor contextAccessor
@{
- var lang = workContextAccessor.WorkContext.WorkingLanguage.LanguageCulture;
+ var lang = contextAccessor.WorkContext.WorkingLanguage.LanguageCulture;
}
<ul class="search-item">
<li>
diff --git a/src/Plugins/Theme.Modern/Views/Modern/Shared/Partials/Logo.cshtml b/src/Plugins/Theme.Modern/Views/Modern/Shared/Partials/Logo.cshtml
index 4dcc0164f..f3b90dacf 100644
--- a/src/Plugins/Theme.Modern/Views/Modern/Shared/Partials/Logo.cshtml
+++ b/src/Plugins/Theme.Modern/Views/Modern/Shared/Partials/Logo.cshtml
@@ -1,11 +1,11 @@
@using Grand.Business.Core.Interfaces.Storage
@inject StoreInformationSettings storeInformation
-@inject IWorkContextAccessor workContextAccessor
+@inject IContextAccessor contextAccessor
@inject IPictureService pictureService
@{
var urlLogo = await pictureService.GetPictureUrl(storeInformation.LogoPictureId);
}
<a class="navbar-brand store-logo" target="_self" href="@Url.RouteUrl("HomePage")">
- <img width="236" height="53" src="@urlLogo" alt="@workContextAccessor.WorkContext.CurrentStore.Name" />
+ <img width="236" height="53" src="@urlLogo" alt="@contextAccessor.StoreContext.CurrentStore.Name" />
<span class="sr-only">@Loc["Logo"]</span>
</a>
\ No newline at end of file
diff --git a/src/Plugins/Theme.Modern/Views/Modern/Shared/Partials/ShoppingCartLinks.cshtml b/src/Plugins/Theme.Modern/Views/Modern/Shared/Partials/ShoppingCartLinks.cshtml
index 8d4c2da8c..270629d2d 100644
--- a/src/Plugins/Theme.Modern/Views/Modern/Shared/Partials/ShoppingCartLinks.cshtml
+++ b/src/Plugins/Theme.Modern/Views/Modern/Shared/Partials/ShoppingCartLinks.cshtml
@@ -2,13 +2,16 @@
@using Grand.Business.Core.Interfaces.Common.Security
@using Grand.Domain.Permissions
-@inject IWorkContextAccessor workContextAccessor
+@inject IContextAccessor contextAccessor
@inject IPermissionService permissionService
@inject IShoppingCartService shoppingCartService
@inject ShoppingCartSettings shoppingCartSettings
@inject CatalogSettings catalogSettings
@{
+ var currentCustomer = contextAccessor.WorkContext.CurrentCustomer;
+ var currentStore = contextAccessor.StoreContext.CurrentStore;
+
var shoppingCartTypes = new List<ShoppingCartType>();
shoppingCartTypes.Add(ShoppingCartType.ShoppingCart);
shoppingCartTypes.Add(ShoppingCartType.Auctions);
@@ -18,16 +21,8 @@
var shoppingCartEnabled = await permissionService.Authorize(StandardPermission.EnableShoppingCart);
var wishlistEnabled = await permissionService.Authorize(StandardPermission.EnableWishlist);
var miniShoppingCartEnabled = shoppingCartSettings.MiniShoppingCartEnabled;
- var shoppingCartItems =
- workContextAccessor.WorkContext.CurrentCustomer.ShoppingCartItems.Any()
- ? (await shoppingCartService.GetShoppingCart(workContextAccessor.WorkContext.CurrentStore.Id, shoppingCartTypes.ToArray()))
- .Sum(x => x.Quantity)
- : 0;
-
- var wishlistItems = workContextAccessor.WorkContext.CurrentCustomer.ShoppingCartItems.Any()
- ? (await shoppingCartService.GetShoppingCart(workContextAccessor.WorkContext.CurrentStore.Id, ShoppingCartType.Wishlist))
- .Sum(x => x.Quantity)
- : 0;
+ var shoppingCartItems = currentCustomer.ShoppingCartItems.Any() ? (await shoppingCartService.GetShoppingCart(currentStore.Id, shoppingCartTypes.ToArray())).Sum(x => x.Quantity) : 0;
+ var wishlistItems = currentCustomer.ShoppingCartItems.Any() ? (await shoppingCartService.GetShoppingCart(currentStore.Id, ShoppingCartType.Wishlist)).Sum(x => x.Quantity) : 0;
}
@if (catalogSettings.CompareProductsEnabled)
{
diff --git a/src/Plugins/Widgets.FacebookPixel/Areas/Admin/Controllers/WidgetsFacebookPixelController.cs b/src/Plugins/Widgets.FacebookPixel/Areas/Admin/Controllers/WidgetsFacebookPixelController.cs
index a9ef544b0..722d7d169 100644
--- a/src/Plugins/Widgets.FacebookPixel/Areas/Admin/Controllers/WidgetsFacebookPixelController.cs
+++ b/src/Plugins/Widgets.FacebookPixel/Areas/Admin/Controllers/WidgetsFacebookPixelController.cs
@@ -1,12 +1,9 @@
using Grand.Business.Core.Interfaces.Common.Configuration;
using Grand.Business.Core.Interfaces.Common.Localization;
-using Grand.Business.Core.Interfaces.Common.Stores;
using Grand.Domain.Permissions;
-using Grand.Domain.Common;
-using Grand.Domain.Customers;
-using Grand.Infrastructure;
using Grand.Web.Common.Controllers;
using Grand.Web.Common.Filters;
+using Grand.Web.Common.Helpers;
using Grand.Web.Common.Security.Authorization;
using Microsoft.AspNetCore.Mvc;
using Widgets.FacebookPixel.Models;
@@ -17,40 +14,23 @@ namespace Widgets.FacebookPixel.Areas.Admin.Controllers;
public class WidgetsFacebookPixelController : BaseAdminPluginController
{
private readonly ISettingService _settingService;
- private readonly IStoreService _storeService;
private readonly ITranslationService _translationService;
- private readonly IWorkContextAccessor _workContextAccessor;
-
- public WidgetsFacebookPixelController(IWorkContextAccessor workContextAccessor,
- IStoreService storeService,
+ private readonly IAdminStoreService _adminStoreService;
+ public WidgetsFacebookPixelController(
ISettingService settingService,
- ITranslationService translationService)
+ ITranslationService translationService,
+ IAdminStoreService adminStoreService)
{
- _workContextAccessor = workContextAccessor;
- _storeService = storeService;
_settingService = settingService;
_translationService = translationService;
- }
-
- protected virtual async Task<string> GetActiveStore(IStoreService storeService, IWorkContext workContext)
- {
- var stores = await storeService.GetAllStores();
- if (stores.Count < 2)
- return stores.FirstOrDefault()!.Id;
-
- var storeId =
- workContext.CurrentCustomer.GetUserFieldFromEntity<string>(SystemCustomerFieldNames
- .AdminAreaStoreScopeConfiguration);
- var store = await storeService.GetStoreById(storeId);
-
- return store != null ? store.Id : "";
+ _adminStoreService = adminStoreService;
}
[AuthorizeAdmin]
public async Task<IActionResult> Configure()
{
//load settings for a chosen store scope
- var storeScope = await GetActiveStore(_storeService, _workContextAccessor.WorkContext);
+ var storeScope = await _adminStoreService.GetActiveStore();
var facebookPixelSettings = await _settingService.LoadSetting<FacebookPixelSettings>(storeScope);
var model = new ConfigurationModel {
PixelId = facebookPixelSettings.PixelId,
@@ -71,7 +51,7 @@ public class WidgetsFacebookPixelController : BaseAdminPluginController
public async Task<IActionResult> Configure(ConfigurationModel model)
{
//load settings for a chosen store scope
- var storeScope = await GetActiveStore(_storeService, _workContextAccessor.WorkContext);
+ var storeScope = await _adminStoreService.GetActiveStore();
var facebookPixelSettings = await _settingService.LoadSetting<FacebookPixelSettings>(storeScope);
facebookPixelSettings.PixelId = model.PixelId;
facebookPixelSettings.PixelScript = model.PixelScript;
diff --git a/src/Plugins/Widgets.FacebookPixel/Components/WidgetsFacebookPixelViewComponent.cs b/src/Plugins/Widgets.FacebookPixel/Components/WidgetsFacebookPixelViewComponent.cs
index 73d698c9f..b9565167f 100644
--- a/src/Plugins/Widgets.FacebookPixel/Components/WidgetsFacebookPixelViewComponent.cs
+++ b/src/Plugins/Widgets.FacebookPixel/Components/WidgetsFacebookPixelViewComponent.cs
@@ -14,16 +14,16 @@ public class WidgetsFacebookPixelViewComponent : ViewComponent
private readonly ICookiePreference _cookiePreference;
private readonly FacebookPixelSettings _facebookPixelSettings;
private readonly IOrderService _orderService;
- private readonly IWorkContextAccessor _workContextAccessor;
+ private readonly IContextAccessor _contextAccessor;
public WidgetsFacebookPixelViewComponent(
- IWorkContextAccessor workContextAccessor,
+ IContextAccessor contextAccessor,
IOrderService orderService,
ICookiePreference cookiePreference,
FacebookPixelSettings facebookPixelSettings
)
{
- _workContextAccessor = workContextAccessor;
+ _contextAccessor = contextAccessor;
_orderService = orderService;
_cookiePreference = cookiePreference;
_facebookPixelSettings = facebookPixelSettings;
@@ -33,7 +33,7 @@ public class WidgetsFacebookPixelViewComponent : ViewComponent
{
if (_facebookPixelSettings.AllowToDisableConsentCookie)
{
- var enabled = await _cookiePreference.IsEnable(_workContextAccessor.WorkContext.CurrentCustomer, _workContextAccessor.WorkContext.CurrentStore,
+ var enabled = await _cookiePreference.IsEnable(_contextAccessor.WorkContext.CurrentCustomer, _contextAccessor.StoreContext.CurrentStore,
FacebookPixelDefaults.ConsentCookieSystemName);
if ((enabled.HasValue && !enabled.Value) ||
(!enabled.HasValue && !_facebookPixelSettings.ConsentDefaultState))
@@ -75,7 +75,7 @@ public class WidgetsFacebookPixelViewComponent : ViewComponent
trackingScript = trackingScript.Replace("{QTY}", model.Quantity.ToString("N0"));
trackingScript =
trackingScript.Replace("{AMOUNT}", model.DecimalPrice.ToString("F2", CultureInfo.InvariantCulture));
- trackingScript = trackingScript.Replace("{CURRENCY}", _workContextAccessor.WorkContext.WorkingCurrency.CurrencyCode);
+ trackingScript = trackingScript.Replace("{CURRENCY}", _contextAccessor.WorkContext.WorkingCurrency.CurrencyCode);
return trackingScript;
}
diff --git a/src/Plugins/Widgets.GoogleAnalytics/Areas/Admin/Controllers/WidgetsGoogleAnalyticsController.cs b/src/Plugins/Widgets.GoogleAnalytics/Areas/Admin/Controllers/WidgetsGoogleAnalyticsController.cs
index fff93456d..f079b4ecd 100644
--- a/src/Plugins/Widgets.GoogleAnalytics/Areas/Admin/Controllers/WidgetsGoogleAnalyticsController.cs
+++ b/src/Plugins/Widgets.GoogleAnalytics/Areas/Admin/Controllers/WidgetsGoogleAnalyticsController.cs
@@ -1,11 +1,8 @@
using Grand.Business.Core.Interfaces.Common.Configuration;
using Grand.Business.Core.Interfaces.Common.Localization;
-using Grand.Business.Core.Interfaces.Common.Stores;
using Grand.Domain.Permissions;
-using Grand.Domain.Common;
-using Grand.Domain.Customers;
-using Grand.Infrastructure;
using Grand.Web.Common.Controllers;
+using Grand.Web.Common.Helpers;
using Grand.Web.Common.Security.Authorization;
using Microsoft.AspNetCore.Mvc;
using Widgets.GoogleAnalytics.Models;
@@ -16,39 +13,23 @@ namespace Widgets.GoogleAnalytics.Areas.Admin.Controllers;
public class WidgetsGoogleAnalyticsController : BaseAdminPluginController
{
private readonly ISettingService _settingService;
- private readonly IStoreService _storeService;
private readonly ITranslationService _translationService;
- private readonly IWorkContextAccessor _workContextAccessor;
+ private readonly IAdminStoreService _adminStoreService;
- public WidgetsGoogleAnalyticsController(IWorkContextAccessor workContextAccessor,
- IStoreService storeService,
+ public WidgetsGoogleAnalyticsController(
ISettingService settingService,
- ITranslationService translationService)
+ ITranslationService translationService,
+ IAdminStoreService adminStoreService)
{
- _workContextAccessor = workContextAccessor;
- _storeService = storeService;
_settingService = settingService;
_translationService = translationService;
- }
-
- protected virtual async Task<string> GetActiveStore(IStoreService storeService, IWorkContext workContext)
- {
- var stores = await storeService.GetAllStores();
- if (stores.Count < 2)
- return stores.FirstOrDefault()!.Id;
-
- var storeId =
- workContext.CurrentCustomer.GetUserFieldFromEntity<string>(SystemCustomerFieldNames
- .AdminAreaStoreScopeConfiguration);
- var store = await storeService.GetStoreById(storeId);
-
- return store != null ? store.Id : "";
+ _adminStoreService = adminStoreService;
}
public async Task<IActionResult> Configure()
{
//load settings for a chosen store scope
- var storeScope = await GetActiveStore(_storeService, _workContextAccessor.WorkContext);
+ var storeScope = await _adminStoreService.GetActiveStore();
var googleAnalyticsSettings = await _settingService.LoadSetting<GoogleAnalyticsEcommerceSettings>(storeScope);
var model = new ConfigurationModel {
GoogleId = googleAnalyticsSettings.GoogleId,
@@ -70,7 +51,7 @@ public class WidgetsGoogleAnalyticsController : BaseAdminPluginController
public async Task<IActionResult> Configure(ConfigurationModel model)
{
//load settings for a chosen store scope
- var storeScope = await GetActiveStore(_storeService, _workContextAccessor.WorkContext);
+ var storeScope = await _adminStoreService.GetActiveStore();
var googleAnalyticsSettings = await _settingService.LoadSetting<GoogleAnalyticsEcommerceSettings>(storeScope);
googleAnalyticsSettings.GoogleId = model.GoogleId;
googleAnalyticsSettings.TrackingScript = model.TrackingScript;
diff --git a/src/Plugins/Widgets.GoogleAnalytics/Components/WidgetsGoogleAnalyticsViewComponent.cs b/src/Plugins/Widgets.GoogleAnalytics/Components/WidgetsGoogleAnalyticsViewComponent.cs
index 7512c82d5..6cbbf69f8 100644
--- a/src/Plugins/Widgets.GoogleAnalytics/Components/WidgetsGoogleAnalyticsViewComponent.cs
+++ b/src/Plugins/Widgets.GoogleAnalytics/Components/WidgetsGoogleAnalyticsViewComponent.cs
@@ -20,15 +20,15 @@ public class WidgetsGoogleAnalyticsViewComponent : ViewComponent
private readonly GoogleAnalyticsEcommerceSettings _googleAnalyticsEcommerceSettings;
private readonly IHttpContextAccessor _httpContextAccessor;
private readonly ILogger<WidgetsGoogleAnalyticsViewComponent> _logger;
- private readonly IWorkContextAccessor _workContextAccessor;
+ private readonly IContextAccessor _contextAccessor;
- public WidgetsGoogleAnalyticsViewComponent(IWorkContextAccessor workContextAccessor,
+ public WidgetsGoogleAnalyticsViewComponent(IContextAccessor contextAccessor,
ILogger<WidgetsGoogleAnalyticsViewComponent> logger,
GoogleAnalyticsEcommerceSettings googleAnalyticsEcommerceSettings,
ICookiePreference cookiePreference,
IHttpContextAccessor httpContextAccessor)
{
- _workContextAccessor = workContextAccessor;
+ _contextAccessor = contextAccessor;
_logger = logger;
_googleAnalyticsEcommerceSettings = googleAnalyticsEcommerceSettings;
_cookiePreference = cookiePreference;
@@ -41,7 +41,7 @@ public class WidgetsGoogleAnalyticsViewComponent : ViewComponent
if (_googleAnalyticsEcommerceSettings.AllowToDisableConsentCookie)
{
- var enabled = await _cookiePreference.IsEnable(_workContextAccessor.WorkContext.CurrentCustomer, _workContextAccessor.WorkContext.CurrentStore,
+ var enabled = await _cookiePreference.IsEnable(_contextAccessor.WorkContext.CurrentCustomer, _contextAccessor.StoreContext.CurrentStore,
GoogleAnalyticDefaults.ConsentCookieSystemName);
if ((enabled.HasValue && !enabled.Value) ||
(!enabled.HasValue && !_googleAnalyticsEcommerceSettings.ConsentDefaultState))
@@ -80,8 +80,8 @@ public class WidgetsGoogleAnalyticsViewComponent : ViewComponent
private async Task<Order> GetLastOrder()
{
var orderService = _httpContextAccessor.HttpContext!.RequestServices.GetRequiredService<IOrderService>();
- var order = (await orderService.SearchOrders(_workContextAccessor.WorkContext.CurrentStore.Id,
- customerId: _workContextAccessor.WorkContext.CurrentCustomer.Id, pageSize: 1)).FirstOrDefault();
+ var order = (await orderService.SearchOrders(_contextAccessor.StoreContext.CurrentStore.Id,
+ customerId: _contextAccessor.WorkContext.CurrentCustomer.Id, pageSize: 1)).FirstOrDefault();
return order;
}
diff --git a/src/Plugins/Widgets.Slider/Components/WidgetSliderComponent.cs b/src/Plugins/Widgets.Slider/Components/WidgetSliderComponent.cs
index a3100a3e0..60d94048e 100644
--- a/src/Plugins/Widgets.Slider/Components/WidgetSliderComponent.cs
+++ b/src/Plugins/Widgets.Slider/Components/WidgetSliderComponent.cs
@@ -13,16 +13,16 @@ public class WidgetSliderComponent : ViewComponent
{
private readonly IPictureService _pictureService;
private readonly ISliderService _sliderService;
- private readonly IWorkContextAccessor _workContextAccessor;
+ private readonly IContextAccessor _contextAccessor;
public WidgetSliderComponent(
IPictureService pictureService,
ISliderService sliderService,
- IWorkContextAccessor workContextAccessor)
+ IContextAccessor contextAccessor)
{
_pictureService = pictureService;
_sliderService = sliderService;
- _workContextAccessor = workContextAccessor;
+ _contextAccessor = contextAccessor;
}
private async Task<string> GetPictureUrl(string pictureId)
@@ -44,8 +44,8 @@ public class WidgetSliderComponent : ViewComponent
model.Slide.Add(new PublicInfoModel.Slider {
Link = item.Link,
PictureUrl = await GetPictureUrl(item.PictureId),
- Name = item.GetTranslation(x => x.Name, _workContextAccessor.WorkContext.WorkingLanguage.Id),
- Description = item.GetTranslation(x => x.Description, _workContextAccessor.WorkContext.WorkingLanguage.Id),
+ Name = item.GetTranslation(x => x.Name, _contextAccessor.WorkContext.WorkingLanguage.Id),
+ Description = item.GetTranslation(x => x.Description, _contextAccessor.WorkContext.WorkingLanguage.Id),
FullWidth = item.FullWidth,
CssClass = i == 1 ? "active" : ""
});
diff --git a/src/Plugins/Widgets.Slider/Services/SliderService.cs b/src/Plugins/Widgets.Slider/Services/SliderService.cs
index d4ce6e5be..f39e7e923 100644
--- a/src/Plugins/Widgets.Slider/Services/SliderService.cs
+++ b/src/Plugins/Widgets.Slider/Services/SliderService.cs
@@ -9,11 +9,11 @@ namespace Widgets.Slider.Services;
public class SliderService : ISliderService
{
public SliderService(IRepository<PictureSlider> repositoryPictureSlider,
- IWorkContextAccessor workContextAccessor, IAclService aclService,
+ IContextAccessor contextAccessor, IAclService aclService,
ICacheBase cacheManager)
{
_repositoryPictureSlider = repositoryPictureSlider;
- _workContextAccessor = workContextAccessor;
+ _contextAccessor = contextAccessor;
_aclService = aclService;
_cacheBase = cacheManager;
}
@@ -48,7 +48,7 @@ public class SliderService : ISliderService
/// <returns>Picture Sliders</returns>
public virtual async Task<IList<PictureSlider>> GetPictureSliders(SliderType sliderType, string objectEntry = "")
{
- var cacheKey = string.Format(SLIDERS_MODEL_KEY, _workContextAccessor.WorkContext.CurrentStore.Id, sliderType.ToString(),
+ var cacheKey = string.Format(SLIDERS_MODEL_KEY, _contextAccessor.StoreContext.CurrentStore.Id, sliderType.ToString(),
objectEntry);
return await _cacheBase.GetAsync(cacheKey, async () =>
{
@@ -60,7 +60,7 @@ public class SliderService : ISliderService
query = query.Where(x => x.ObjectEntry == objectEntry);
var items = query.ToList();
- return await Task.FromResult(items.Where(c => _aclService.Authorize(c, _workContextAccessor.WorkContext.CurrentStore.Id))
+ return await Task.FromResult(items.Where(c => _aclService.Authorize(c, _contextAccessor.StoreContext.CurrentStore.Id))
.ToList());
});
}
@@ -122,7 +122,7 @@ public class SliderService : ISliderService
private readonly IRepository<PictureSlider> _repositoryPictureSlider;
private readonly IAclService _aclService;
- private readonly IWorkContextAccessor _workContextAccessor;
+ private readonly IContextAccessor _contextAccessor;
private readonly ICacheBase _cacheBase;
/// <summary>
diff --git a/src/Tests/Grand.Business.Authentication.Tests/Services/ExternalAuthenticationServiceTests.cs b/src/Tests/Grand.Business.Authentication.Tests/Services/ExternalAuthenticationServiceTests.cs
index c920a6ae5..9d6ba9974 100644
--- a/src/Tests/Grand.Business.Authentication.Tests/Services/ExternalAuthenticationServiceTests.cs
+++ b/src/Tests/Grand.Business.Authentication.Tests/Services/ExternalAuthenticationServiceTests.cs
@@ -6,6 +6,7 @@ using Grand.Business.Core.Utilities.Authentication;
using Grand.Data;
using Grand.Data.Tests.MongoDb;
using Grand.Domain.Customers;
+using Grand.Domain.Stores;
using Grand.Infrastructure;
using MediatR;
using Microsoft.VisualStudio.TestTools.UnitTesting;
@@ -25,7 +26,7 @@ public class ExternalAuthenticationServiceTests
private ExternalAuthenticationService _externalAuthenticationService;
private Mock<IGroupService> _groupServiceMock;
private Mock<IMediator> _mediatorMock;
- private Mock<IWorkContextAccessor> _workContextMock;
+ private Mock<IContextAccessor> _workContextMock;
[TestInitialize]
public void Init()
@@ -36,9 +37,9 @@ public class ExternalAuthenticationServiceTests
_customerManagerServiceMock = new Mock<ICustomerManagerService>();
_mediatorMock = new Mock<IMediator>();
_externalAuthenticationRecordRepository = new MongoDBRepositoryTest<ExternalAuthentication>();
- _workContextMock = new Mock<IWorkContextAccessor>();
+ _workContextMock = new Mock<IContextAccessor>();
_workContextMock.Setup(s => s.WorkContext.CurrentCustomer).Returns(new Customer());
-
+ _workContextMock.Setup(c => c.StoreContext.CurrentStore).Returns(() => new Store { Id = "" });
_externalAuthenticationProviders = new List<IExternalAuthenticationProvider>
{ new ExternalAuthenticationProviderTest() };
diff --git a/src/Tests/Grand.Business.Authentication.Tests/Services/TwoFactorAuthenticationServiceTests.cs b/src/Tests/Grand.Business.Authentication.Tests/Services/TwoFactorAuthenticationServiceTests.cs
index d24f3fa04..f87e2d460 100644
--- a/src/Tests/Grand.Business.Authentication.Tests/Services/TwoFactorAuthenticationServiceTests.cs
+++ b/src/Tests/Grand.Business.Authentication.Tests/Services/TwoFactorAuthenticationServiceTests.cs
@@ -17,12 +17,12 @@ public class TwoFactorAuthenticationServiceTests
private Mock<IEnumerable<ISMSVerificationService>> _sMsVerificationService;
private TwoFactorAuthenticationService _twoFactorAuthenticationService;
private Mock<ICustomerService> _customerServiceMock;
- private Mock<IWorkContextAccessor> _workContextMock;
+ private Mock<IContextAccessor> _workContextMock;
[TestInitialize]
public void Init()
{
- _workContextMock = new Mock<IWorkContextAccessor>();
+ _workContextMock = new Mock<IContextAccessor>();
_customerServiceMock = new Mock<ICustomerService>();
_sMsVerificationService = new Mock<IEnumerable<ISMSVerificationService>>();
_twoFactorAuthenticationService = new TwoFactorAuthenticationService(_workContextMock.Object,
@@ -33,7 +33,7 @@ public class TwoFactorAuthenticationServiceTests
public async Task GenerateCodeSetupTest_AppVerification()
{
//Arrange
- _workContextMock.Setup(c => c.WorkContext.CurrentStore).Returns(() => new Store { Id = "", Name = "test store" });
+ _workContextMock.Setup(c => c.StoreContext.CurrentStore).Returns(() => new Store { Id = "", Name = "test store" });
_workContextMock.Setup(c => c.WorkContext.CurrentCustomer).Returns(() => new Customer());
//Act
var result = await _twoFactorAuthenticationService.GenerateCodeSetup(Guid.NewGuid().ToString(),
@@ -48,7 +48,7 @@ public class TwoFactorAuthenticationServiceTests
public async Task GenerateCodeSetupTest_Email()
{
//Arrange
- _workContextMock.Setup(c => c.WorkContext.CurrentStore).Returns(() => new Store { Id = "", Name = "test store" });
+ _workContextMock.Setup(c => c.StoreContext.CurrentStore).Returns(() => new Store { Id = "", Name = "test store" });
_workContextMock.Setup(c => c.WorkContext.CurrentCustomer).Returns(() => new Customer());
//Act
var result = await _twoFactorAuthenticationService.GenerateCodeSetup(Guid.NewGuid().ToString(),
diff --git a/src/Tests/Grand.Business.Catalog.Tests/Services/Brands/BrandServiceTests.cs b/src/Tests/Grand.Business.Catalog.Tests/Services/Brands/BrandServiceTests.cs
index 5525386a1..392d2bb08 100644
--- a/src/Tests/Grand.Business.Catalog.Tests/Services/Brands/BrandServiceTests.cs
+++ b/src/Tests/Grand.Business.Catalog.Tests/Services/Brands/BrandServiceTests.cs
@@ -21,14 +21,14 @@ public class BrandServiceTests
private MemoryCacheBase _cacheBase;
private Mock<IMediator> _mediatorMock;
private IRepository<Brand> _repository;
- private Mock<IWorkContextAccessor> _workContextMock;
+ private Mock<IContextAccessor> _workContextMock;
[TestInitialize]
public void InitializeTests()
{
_repository = new MongoDBRepositoryTest<Brand>();
- _workContextMock = new Mock<IWorkContextAccessor>();
- _workContextMock.Setup(c => c.WorkContext.CurrentStore).Returns(() => new Store { Id = "" });
+ _workContextMock = new Mock<IContextAccessor>();
+ _workContextMock.Setup(c => c.StoreContext.CurrentStore).Returns(() => new Store { Id = "" });
_workContextMock.Setup(c => c.WorkContext.CurrentCustomer).Returns(() => new Customer());
_mediatorMock = new Mock<IMediator>();
_cacheBase = new MemoryCacheBase(MemoryCacheTest.Get(), _mediatorMock.Object,
diff --git a/src/Tests/Grand.Business.Catalog.Tests/Services/Categories/CategoryServiceDbTests.cs b/src/Tests/Grand.Business.Catalog.Tests/Services/Categories/CategoryServiceDbTests.cs
index d7231ef52..cbd13b513 100644
--- a/src/Tests/Grand.Business.Catalog.Tests/Services/Categories/CategoryServiceDbTests.cs
+++ b/src/Tests/Grand.Business.Catalog.Tests/Services/Categories/CategoryServiceDbTests.cs
@@ -26,14 +26,14 @@ public class CategoryServiceDbTests
private CategoryService _categoryService;
private Mock<IMediator> _mediatorMock;
private CatalogSettings _settings;
- private Mock<IWorkContextAccessor> _workContextMock;
+ private Mock<IContextAccessor> _workContextMock;
[TestInitialize]
public void InitializeTests()
{
_categoryRepository = new MongoDBRepositoryTest<Category>();
- _workContextMock = new Mock<IWorkContextAccessor>();
- _workContextMock.Setup(c => c.WorkContext.CurrentStore).Returns(() => new Store { Id = "" });
+ _workContextMock = new Mock<IContextAccessor>();
+ _workContextMock.Setup(c => c.StoreContext.CurrentStore).Returns(() => new Store { Id = "" });
_workContextMock.Setup(c => c.WorkContext.CurrentCustomer).Returns(() => new Customer());
_mediatorMock = new Mock<IMediator>();
_aclServiceMock = new AclService(new AccessControlConfig());
diff --git a/src/Tests/Grand.Business.Catalog.Tests/Services/Categories/CategoryServiceTests.cs b/src/Tests/Grand.Business.Catalog.Tests/Services/Categories/CategoryServiceTests.cs
index d0930fd5a..0f1d11174 100644
--- a/src/Tests/Grand.Business.Catalog.Tests/Services/Categories/CategoryServiceTests.cs
+++ b/src/Tests/Grand.Business.Catalog.Tests/Services/Categories/CategoryServiceTests.cs
@@ -28,7 +28,7 @@ public class CategoryServiceTests
private ProductCategoryService _productCategoryService;
private Mock<MongoRepository<Product>> _productRepositoryMock;
private CatalogSettings _settings;
- private Mock<IWorkContextAccessor> _workContextMock;
+ private Mock<IContextAccessor> _workContextMock;
[TestInitialize]
public void Init()
@@ -38,7 +38,7 @@ public class CategoryServiceTests
_casheManagerMock = new Mock<ICacheBase>();
_categoryRepositoryMock = new Mock<IRepository<Category>>();
_productRepositoryMock = new Mock<MongoRepository<Product>>(Mock.Of<IAuditInfoProvider>());
- _workContextMock = new Mock<IWorkContextAccessor>();
+ _workContextMock = new Mock<IContextAccessor>();
_mediatorMock = new Mock<IMediator>();
_aclServiceMock = new Mock<IAclService>();
_settings = new CatalogSettings();
@@ -98,7 +98,8 @@ public class CategoryServiceTests
{
var allCategory = GetMockCategoryList();
var category = new Category { Id = "6", ParentCategoryId = "3", Published = true };
- _workContextMock.Setup(c => c.WorkContext.CurrentStore).Returns(() => new Store { Id = "" });
+ _workContextMock.Setup(c => c.StoreContext.CurrentStore).Returns(() => new Store { Id = "" });
+ _workContextMock.Setup(c => c.WorkContext.CurrentCustomer).Returns(() => new Customer { Id = "" });
_aclServiceMock.Setup(a => a.Authorize(It.IsAny<Category>(), It.IsAny<Customer>())).Returns(() => true);
_aclServiceMock.Setup(a => a.Authorize(It.IsAny<Category>(), It.IsAny<string>())).Returns(() => true);
var result = _categoryService.GetCategoryBreadCrumb(category, allCategory);
@@ -112,7 +113,8 @@ public class CategoryServiceTests
{
var allCategory = GetMockCategoryList();
var category = new Category { Id = "6", ParentCategoryId = "1", Published = true };
- _workContextMock.Setup(c => c.WorkContext.CurrentStore).Returns(() => new Store { Id = "" });
+ _workContextMock.Setup(c => c.StoreContext.CurrentStore).Returns(() => new Store { Id = "" });
+ _workContextMock.Setup(c => c.WorkContext.CurrentCustomer).Returns(() => new Customer { Id = "" });
_aclServiceMock.Setup(a => a.Authorize(It.IsAny<Category>(), It.IsAny<Customer>())).Returns(() => true);
_aclServiceMock.Setup(a => a.Authorize(It.IsAny<Category>(), It.IsAny<string>())).Returns(() => true);
var result = _categoryService.GetCategoryBreadCrumb(category, allCategory);
diff --git a/src/Tests/Grand.Business.Catalog.Tests/Services/Categories/ProductCategoryServiceTests.cs b/src/Tests/Grand.Business.Catalog.Tests/Services/Categories/ProductCategoryServiceTests.cs
index d6e507c15..eb85556b6 100644
--- a/src/Tests/Grand.Business.Catalog.Tests/Services/Categories/ProductCategoryServiceTests.cs
+++ b/src/Tests/Grand.Business.Catalog.Tests/Services/Categories/ProductCategoryServiceTests.cs
@@ -22,14 +22,14 @@ public class ProductCategoryServiceTests
private Mock<IMediator> _mediatorMock;
private ProductCategoryService _productCategoryService;
private IRepository<Product> _repository;
- private Mock<IWorkContextAccessor> _workContextMock;
+ private Mock<IContextAccessor> _workContextMock;
[TestInitialize]
public void InitializeTests()
{
_repository = new MongoDBRepositoryTest<Product>();
- _workContextMock = new Mock<IWorkContextAccessor>();
- _workContextMock.Setup(c => c.WorkContext.CurrentStore).Returns(() => new Store { Id = "" });
+ _workContextMock = new Mock<IContextAccessor>();
+ _workContextMock.Setup(c => c.StoreContext.CurrentStore).Returns(() => new Store { Id = "" });
_workContextMock.Setup(c => c.WorkContext.CurrentCustomer).Returns(() => new Customer());
_mediatorMock = new Mock<IMediator>();
_cacheBase = new MemoryCacheBase(MemoryCacheTest.Get(), _mediatorMock.Object,
diff --git a/src/Tests/Grand.Business.Catalog.Tests/Services/Collections/CollectionServiceTests.cs b/src/Tests/Grand.Business.Catalog.Tests/Services/Collections/CollectionServiceTests.cs
index 431fd6abf..23d9da732 100644
--- a/src/Tests/Grand.Business.Catalog.Tests/Services/Collections/CollectionServiceTests.cs
+++ b/src/Tests/Grand.Business.Catalog.Tests/Services/Collections/CollectionServiceTests.cs
@@ -22,14 +22,14 @@ public class CollectionServiceTests
private Mock<IMediator> _mediatorMock;
private Mock<IRepository<Collection>> _repositoryMock;
private CatalogSettings _settings;
- private Mock<IWorkContextAccessor> _workContextMock;
+ private Mock<IContextAccessor> _workContextMock;
[TestInitialize]
public void Init()
{
_cacheMock = new Mock<ICacheBase>();
_repositoryMock = new Mock<IRepository<Collection>>();
- _workContextMock = new Mock<IWorkContextAccessor>();
+ _workContextMock = new Mock<IContextAccessor>();
_mediatorMock = new Mock<IMediator>();
_aclMock = new Mock<IAclService>();
_settings = new CatalogSettings();
diff --git a/src/Tests/Grand.Business.Catalog.Tests/Services/Collections/ProductCollectionServiceTests.cs b/src/Tests/Grand.Business.Catalog.Tests/Services/Collections/ProductCollectionServiceTests.cs
index 2fa0601b0..3fb95640f 100644
--- a/src/Tests/Grand.Business.Catalog.Tests/Services/Collections/ProductCollectionServiceTests.cs
+++ b/src/Tests/Grand.Business.Catalog.Tests/Services/Collections/ProductCollectionServiceTests.cs
@@ -22,14 +22,14 @@ public class ProductCollectionServiceTests
private Mock<IMediator> _mediatorMock;
private ProductCollectionService _productCollectionService;
private IRepository<Product> _repository;
- private Mock<IWorkContextAccessor> _workContextMock;
+ private Mock<IContextAccessor> _workContextMock;
[TestInitialize]
public void InitializeTests()
{
_repository = new MongoDBRepositoryTest<Product>();
- _workContextMock = new Mock<IWorkContextAccessor>();
- _workContextMock.Setup(c => c.WorkContext.CurrentStore).Returns(() => new Store { Id = "" });
+ _workContextMock = new Mock<IContextAccessor>();
+ _workContextMock.Setup(c => c.StoreContext.CurrentStore).Returns(() => new Store { Id = "" });
_workContextMock.Setup(c => c.WorkContext.CurrentCustomer).Returns(() => new Customer());
_mediatorMock = new Mock<IMediator>();
_cacheBase = new MemoryCacheBase(MemoryCacheTest.Get(), _mediatorMock.Object,
diff --git a/src/Tests/Grand.Business.Catalog.Tests/Services/Discounts/DiscountServiceTests.cs b/src/Tests/Grand.Business.Catalog.Tests/Services/Discounts/DiscountServiceTests.cs
index 808b0c1a9..be911b368 100644
--- a/src/Tests/Grand.Business.Catalog.Tests/Services/Discounts/DiscountServiceTests.cs
+++ b/src/Tests/Grand.Business.Catalog.Tests/Services/Discounts/DiscountServiceTests.cs
@@ -37,8 +37,8 @@ public class DiscountServiceTests
private GetDiscountAmountProviderHandler _getDiscountAmountProviderHandler;
private Mock<IMediator> _mediatorMock;
private IRepository<Discount> _repository;
- private Mock<ITranslationService> _translationServiceMock;
private Mock<IWorkContext> _workContextMock;
+ private Mock<IStoreContext> _storeContextMock;
private GetDiscountUsageHistoryQueryHandler handler;
[TestInitialize]
@@ -48,8 +48,8 @@ public class DiscountServiceTests
_discountCouponRepository = new MongoDBRepositoryTest<DiscountCoupon>();
_discountUsageHistoryRepository = new MongoDBRepositoryTest<DiscountUsageHistory>();
_workContextMock = new Mock<IWorkContext>();
- _translationServiceMock = new Mock<ITranslationService>();
- _workContextMock.Setup(c => c.CurrentStore).Returns(() => new Store { Id = "" });
+ _storeContextMock = new Mock<IStoreContext>();
+ _storeContextMock.Setup(c => c.CurrentStore).Returns(() => new Store { Id = "" });
_workContextMock.Setup(c => c.CurrentCustomer).Returns(() => new Customer());
_mediatorMock = new Mock<IMediator>();
_cacheBase = new MemoryCacheBase(MemoryCacheTest.Get(), _mediatorMock.Object,
diff --git a/src/Tests/Grand.Business.Catalog.Tests/Services/ExportImport/BrandImportDataObjectTests.cs b/src/Tests/Grand.Business.Catalog.Tests/Services/ExportImport/BrandImportDataObjectTests.cs
index 87b68bcbf..d654135bd 100644
--- a/src/Tests/Grand.Business.Catalog.Tests/Services/ExportImport/BrandImportDataObjectTests.cs
+++ b/src/Tests/Grand.Business.Catalog.Tests/Services/ExportImport/BrandImportDataObjectTests.cs
@@ -40,7 +40,7 @@ public class BrandImportDataObjectTests
private IRepository<Brand> _repository;
private Mock<ISlugService> _slugServiceMock;
- private Mock<IWorkContextAccessor> _workContextMock;
+ private Mock<IContextAccessor> _workContextMock;
private ISeNameService _seNameService;
[TestInitialize]
public void Init()
@@ -53,8 +53,8 @@ public class BrandImportDataObjectTests
_brandLayoutServiceMock = new Mock<IBrandLayoutService>();
_slugServiceMock = new Mock<ISlugService>();
_languageServiceMock = new Mock<ILanguageService>();
- _workContextMock = new Mock<IWorkContextAccessor>();
- _workContextMock.Setup(c => c.WorkContext.CurrentStore).Returns(() => new Store { Id = "" });
+ _workContextMock = new Mock<IContextAccessor>();
+ _workContextMock.Setup(c => c.StoreContext.CurrentStore).Returns(() => new Store { Id = "" });
_workContextMock.Setup(c => c.WorkContext.CurrentCustomer).Returns(() => new Customer());
_mediatorMock = new Mock<IMediator>();
diff --git a/src/Tests/Grand.Business.Catalog.Tests/Services/ExportImport/CategoryImportDataObjectTests.cs b/src/Tests/Grand.Business.Catalog.Tests/Services/ExportImport/CategoryImportDataObjectTests.cs
index b978410bc..115c5e1f1 100644
--- a/src/Tests/Grand.Business.Catalog.Tests/Services/ExportImport/CategoryImportDataObjectTests.cs
+++ b/src/Tests/Grand.Business.Catalog.Tests/Services/ExportImport/CategoryImportDataObjectTests.cs
@@ -41,7 +41,7 @@ public class CategoryImportDataObjectTests
private IRepository<Category> _repository;
private Mock<ISlugService> _slugServiceMock;
- private Mock<IWorkContextAccessor> _workContextMock;
+ private Mock<IContextAccessor> _workContextMock;
private ISeNameService _seNameService;
[TestInitialize]
public void Init()
@@ -54,8 +54,8 @@ public class CategoryImportDataObjectTests
_categoryLayoutServiceMock = new Mock<ICategoryLayoutService>();
_slugServiceMock = new Mock<ISlugService>();
_languageServiceMock = new Mock<ILanguageService>();
- _workContextMock = new Mock<IWorkContextAccessor>();
- _workContextMock.Setup(c => c.WorkContext.CurrentStore).Returns(() => new Store { Id = "" });
+ _workContextMock = new Mock<IContextAccessor>();
+ _workContextMock.Setup(c => c.StoreContext.CurrentStore).Returns(() => new Store { Id = "" });
_workContextMock.Setup(c => c.WorkContext.CurrentCustomer).Returns(() => new Customer());
_mediatorMock = new Mock<IMediator>();
diff --git a/src/Tests/Grand.Business.Catalog.Tests/Services/ExportImport/CollectionImportDataObjectTests.cs b/src/Tests/Grand.Business.Catalog.Tests/Services/ExportImport/CollectionImportDataObjectTests.cs
index 645a261cc..815a6079f 100644
--- a/src/Tests/Grand.Business.Catalog.Tests/Services/ExportImport/CollectionImportDataObjectTests.cs
+++ b/src/Tests/Grand.Business.Catalog.Tests/Services/ExportImport/CollectionImportDataObjectTests.cs
@@ -41,7 +41,7 @@ public class CollectionImportDataObjectTests
private IRepository<Collection> _repository;
private Mock<ISlugService> _slugServiceMock;
- private Mock<IWorkContextAccessor> _workContextMock;
+ private Mock<IContextAccessor> _workContextMock;
private ISeNameService _seNameService;
[TestInitialize]
public void Init()
@@ -54,8 +54,8 @@ public class CollectionImportDataObjectTests
_collectionLayoutServiceMock = new Mock<ICollectionLayoutService>();
_slugServiceMock = new Mock<ISlugService>();
_languageServiceMock = new Mock<ILanguageService>();
- _workContextMock = new Mock<IWorkContextAccessor>();
- _workContextMock.Setup(c => c.WorkContext.CurrentStore).Returns(() => new Store { Id = "" });
+ _workContextMock = new Mock<IContextAccessor>();
+ _workContextMock.Setup(c => c.StoreContext.CurrentStore).Returns(() => new Store { Id = "" });
_workContextMock.Setup(c => c.WorkContext.CurrentCustomer).Returns(() => new Customer());
_mediatorMock = new Mock<IMediator>();
diff --git a/src/Tests/Grand.Business.Catalog.Tests/Services/ExportImport/ProductImportDataObjectTests.cs b/src/Tests/Grand.Business.Catalog.Tests/Services/ExportImport/ProductImportDataObjectTests.cs
index 668365d8d..f121b3d56 100644
--- a/src/Tests/Grand.Business.Catalog.Tests/Services/ExportImport/ProductImportDataObjectTests.cs
+++ b/src/Tests/Grand.Business.Catalog.Tests/Services/ExportImport/ProductImportDataObjectTests.cs
@@ -59,7 +59,7 @@ public class ProductImportDataObjectTests
private Mock<ISlugService> _slugServiceMock;
private Mock<ITaxCategoryService> _taxServiceMock;
private Mock<IWarehouseService> _warehouseServiceMock;
- private Mock<IWorkContextAccessor> _workContextMock;
+ private Mock<IContextAccessor> _workContextMock;
private ISeNameService _seNameService;
[TestInitialize]
public void Init()
@@ -82,8 +82,8 @@ public class ProductImportDataObjectTests
_productCategoryServiceMock = new Mock<IProductCategoryService>();
_productCollectionServiceMock = new Mock<IProductCollectionService>();
- _workContextMock = new Mock<IWorkContextAccessor>();
- _workContextMock.Setup(c => c.WorkContext.CurrentStore).Returns(() => new Store { Id = "" });
+ _workContextMock = new Mock<IContextAccessor>();
+ _workContextMock.Setup(c => c.StoreContext.CurrentStore).Returns(() => new Store { Id = "" });
_workContextMock.Setup(c => c.WorkContext.CurrentCustomer).Returns(() => new Customer());
_mediatorMock = new Mock<IMediator>();
diff --git a/src/Tests/Grand.Business.Catalog.Tests/Services/Prices/PriceFormatterTests.cs b/src/Tests/Grand.Business.Catalog.Tests/Services/Prices/PriceFormatterTests.cs
index 1acc4ad27..0d9ccd9af 100644
--- a/src/Tests/Grand.Business.Catalog.Tests/Services/Prices/PriceFormatterTests.cs
+++ b/src/Tests/Grand.Business.Catalog.Tests/Services/Prices/PriceFormatterTests.cs
@@ -32,7 +32,7 @@ public class PriceFormatterTests
private TaxSettings _taxSettings;
private ITranslationService _translationService;
- private Mock<IWorkContextAccessor> tempWorkContext;
+ private Mock<IContextAccessor> tempWorkContext;
[TestInitialize]
public void TestInitialize()
@@ -44,7 +44,7 @@ public class PriceFormatterTests
_eventPublisher = eventPublisher.Object;
var cacheManager = new Mock<ICacheBase>();
- tempWorkContext = new Mock<IWorkContextAccessor>();
+ tempWorkContext = new Mock<IContextAccessor>();
_currencySettings = new CurrencySettings();
var currency01 = new Currency {
diff --git a/src/Tests/Grand.Business.Catalog.Tests/Services/Prices/PriceServiceTests.cs b/src/Tests/Grand.Business.Catalog.Tests/Services/Prices/PriceServiceTests.cs
index a7401b9b9..0d850682a 100644
--- a/src/Tests/Grand.Business.Catalog.Tests/Services/Prices/PriceServiceTests.cs
+++ b/src/Tests/Grand.Business.Catalog.Tests/Services/Prices/PriceServiceTests.cs
@@ -44,10 +44,10 @@ public class PriceServiceTests
private IProductService _productService;
private ShoppingCartSettings _shoppingCartSettings;
private Store _store;
- private IWorkContextAccessor _workContext;
+ private IContextAccessor _workContext;
private Mock<IDiscountService> tempDiscountServiceMock;
private Mock<IProductService> tempProductService;
- private Mock<IWorkContextAccessor> tempWorkContext;
+ private Mock<IContextAccessor> tempWorkContext;
[TestInitialize]
public void TestInitialize()
@@ -56,10 +56,10 @@ public class PriceServiceTests
DataSettingsManager.Initialize(settingsPath);
_store = new Store { Id = "1" };
- tempWorkContext = new Mock<IWorkContextAccessor>();
+ tempWorkContext = new Mock<IContextAccessor>();
{
tempWorkContext.Setup(instance => instance.WorkContext.WorkingCurrency).Returns(_currency);
- tempWorkContext.Setup(c => c.WorkContext.CurrentStore).Returns(_store);
+ tempWorkContext.Setup(c => c.StoreContext.CurrentStore).Returns(_store);
_workContext = tempWorkContext.Object;
}
diff --git a/src/Tests/Grand.Business.Catalog.Tests/Services/Products/AuctionServiceTests.cs b/src/Tests/Grand.Business.Catalog.Tests/Services/Products/AuctionServiceTests.cs
index 447056826..914f9cf63 100644
--- a/src/Tests/Grand.Business.Catalog.Tests/Services/Products/AuctionServiceTests.cs
+++ b/src/Tests/Grand.Business.Catalog.Tests/Services/Products/AuctionServiceTests.cs
@@ -9,7 +9,6 @@ using Grand.Infrastructure;
using Grand.Infrastructure.Caching;
using Grand.Infrastructure.Configuration;
using Grand.Infrastructure.Tests.Caching;
-using Grand.SharedKernel.Extensions;
using MediatR;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Moq;
@@ -25,6 +24,7 @@ public class AuctionServiceTests
private IRepository<Product> _productrepository;
private IRepository<Bid> _repository;
private Mock<IWorkContext> _workContextMock;
+ private Mock<IStoreContext> _storeContextMock;
[TestInitialize]
public void InitializeTests()
@@ -32,7 +32,8 @@ public class AuctionServiceTests
_repository = new MongoDBRepositoryTest<Bid>();
_productrepository = new MongoDBRepositoryTest<Product>();
_workContextMock = new Mock<IWorkContext>();
- _workContextMock.Setup(c => c.CurrentStore).Returns(() => new Store { Id = "" });
+ _storeContextMock = new Mock<IStoreContext>();
+ _storeContextMock.Setup(c => c.CurrentStore).Returns(() => new Store { Id = "" });
_workContextMock.Setup(c => c.CurrentCustomer).Returns(() => new Customer());
_mediatorMock = new Mock<IMediator>();
_cacheBase = new MemoryCacheBase(MemoryCacheTest.Get(), _mediatorMock.Object,
diff --git a/src/Tests/Grand.Business.Catalog.Tests/Services/Products/InventoryManageServiceTests.cs b/src/Tests/Grand.Business.Catalog.Tests/Services/Products/InventoryManageServiceTests.cs
index 46d9970c9..52592706c 100644
--- a/src/Tests/Grand.Business.Catalog.Tests/Services/Products/InventoryManageServiceTests.cs
+++ b/src/Tests/Grand.Business.Catalog.Tests/Services/Products/InventoryManageServiceTests.cs
@@ -29,6 +29,7 @@ public class InventoryManageServiceTests
private StockQuantityService _stockQuantityService;
private Mock<ITranslationService> _translationService;
private Mock<IWorkContext> _workContextMock;
+ private Mock<IStoreContext> _storeContextMock;
[TestInitialize]
public void Init()
@@ -36,8 +37,9 @@ public class InventoryManageServiceTests
_repository = new MongoDBRepositoryTest<Product>();
_repositoryInventoryJournal = new MongoDBRepositoryTest<InventoryJournal>();
_workContextMock = new Mock<IWorkContext>();
+ _storeContextMock = new Mock<IStoreContext>();
_translationService = new Mock<ITranslationService>();
- _workContextMock.Setup(c => c.CurrentStore).Returns(() => new Store { Id = "" });
+ _storeContextMock.Setup(c => c.CurrentStore).Returns(() => new Store { Id = "" });
_workContextMock.Setup(c => c.CurrentCustomer).Returns(() => new Customer());
_mediatorMock = new Mock<IMediator>();
_settings = new CatalogSettings();
diff --git a/src/Tests/Grand.Business.Catalog.Tests/Services/Products/ProductAttributeFormatterTests.cs b/src/Tests/Grand.Business.Catalog.Tests/Services/Products/ProductAttributeFormatterTests.cs
index 2082186e8..7ee5b1bed 100644
--- a/src/Tests/Grand.Business.Catalog.Tests/Services/Products/ProductAttributeFormatterTests.cs
+++ b/src/Tests/Grand.Business.Catalog.Tests/Services/Products/ProductAttributeFormatterTests.cs
@@ -30,13 +30,13 @@ public class ProductAttributeFormatterTests
private Mock<IProductService> _productServiceMock;
private Mock<ITaxService> _taxServiceMock;
private Mock<ITranslationService> _translationServiceMock;
- private Mock<IWorkContextAccessor> _workContextMock;
+ private Mock<IContextAccessor> _workContextMock;
[TestInitialize]
public void InitializeTests()
{
- _workContextMock = new Mock<IWorkContextAccessor>();
- _workContextMock.Setup(c => c.WorkContext.CurrentStore).Returns(() => new Store { Id = "" });
+ _workContextMock = new Mock<IContextAccessor>();
+ _workContextMock.Setup(c => c.StoreContext.CurrentStore).Returns(() => new Store { Id = "" });
_workContextMock.Setup(c => c.WorkContext.CurrentCustomer).Returns(() => new Customer());
_productAttributeServiceMock = new Mock<IProductAttributeService>();
_productAttributeServiceMock.Setup(x => x.GetProductAttributeById(It.IsAny<string>()))
diff --git a/src/Tests/Grand.Business.Catalog.Tests/Services/Products/ProductServiceTests.cs b/src/Tests/Grand.Business.Catalog.Tests/Services/Products/ProductServiceTests.cs
index 553deaff1..7adf2d6b5 100644
--- a/src/Tests/Grand.Business.Catalog.Tests/Services/Products/ProductServiceTests.cs
+++ b/src/Tests/Grand.Business.Catalog.Tests/Services/Products/ProductServiceTests.cs
@@ -27,14 +27,14 @@ public class ProductServiceTests
private Mock<IMediator> _mediatorMock;
private IRepository<Product> _productRepository;
private ProductService _productService;
- private Mock<IWorkContextAccessor> _workContextMock;
+ private Mock<IContextAccessor> _workContextMock;
[TestInitialize]
public void InitializeTests()
{
_productRepository = new MongoDBRepositoryTest<Product>();
- _workContextMock = new Mock<IWorkContextAccessor>();
- _workContextMock.Setup(c => c.WorkContext.CurrentStore).Returns(() => new Store { Id = "" });
+ _workContextMock = new Mock<IContextAccessor>();
+ _workContextMock.Setup(c => c.StoreContext.CurrentStore).Returns(() => new Store { Id = "" });
_workContextMock.Setup(c => c.WorkContext.CurrentCustomer).Returns(() => new Customer());
_mediatorMock = new Mock<IMediator>();
diff --git a/src/Tests/Grand.Business.Catalog.Tests/Services/Tax/TaxServiceTests.cs b/src/Tests/Grand.Business.Catalog.Tests/Services/Tax/TaxServiceTests.cs
index 0eb3ff876..dc99c8dc1 100644
--- a/src/Tests/Grand.Business.Catalog.Tests/Services/Tax/TaxServiceTests.cs
+++ b/src/Tests/Grand.Business.Catalog.Tests/Services/Tax/TaxServiceTests.cs
@@ -29,7 +29,7 @@ public class TaxServiceTests
private TaxSettings _taxSettings;
private IVatService _vatService;
- private IWorkContextAccessor _workContext;
+ private IContextAccessor _workContext;
[TestInitialize]
public void TestInitialize()
diff --git a/src/Tests/Grand.Business.Checkout.Tests/Events/ShoppingCart/CustomerLoggedInEventHandlerTests.cs b/src/Tests/Grand.Business.Checkout.Tests/Events/ShoppingCart/CustomerLoggedInEventHandlerTests.cs
index 903013348..1fd906e09 100644
--- a/src/Tests/Grand.Business.Checkout.Tests/Events/ShoppingCart/CustomerLoggedInEventHandlerTests.cs
+++ b/src/Tests/Grand.Business.Checkout.Tests/Events/ShoppingCart/CustomerLoggedInEventHandlerTests.cs
@@ -13,13 +13,13 @@ public class CustomerLoggedInEventHandlerTests
{
private CustomerLoggedInEventHandler _customerLoggedInEventHandler;
private Mock<IShoppingCartService> _shoppingCartServiceMock;
- private Mock<IWorkContextAccessor> _workContextMock;
+ private Mock<IContextAccessor> _workContextMock;
[TestInitialize]
public void Init()
{
_shoppingCartServiceMock = new Mock<IShoppingCartService>();
- _workContextMock = new Mock<IWorkContextAccessor>();
+ _workContextMock = new Mock<IContextAccessor>();
_workContextMock.Setup(s => s.WorkContext.CurrentCustomer).Returns(new Customer());
_customerLoggedInEventHandler =
diff --git a/src/Tests/Grand.Business.Checkout.Tests/Services/CheckoutAttributes/CheckoutAttributeParserTests.cs b/src/Tests/Grand.Business.Checkout.Tests/Services/CheckoutAttributes/CheckoutAttributeParserTests.cs
index ad2df3131..b3745854f 100644
--- a/src/Tests/Grand.Business.Checkout.Tests/Services/CheckoutAttributes/CheckoutAttributeParserTests.cs
+++ b/src/Tests/Grand.Business.Checkout.Tests/Services/CheckoutAttributes/CheckoutAttributeParserTests.cs
@@ -23,7 +23,7 @@ public class CheckoutAttributeParserTests
private IRepository<CheckoutAttribute> _checkoutAttributeRepo;
private ICheckoutAttributeService _checkoutAttributeService;
private IMediator _eventPublisher;
- private Mock<IWorkContextAccessor> _workContextMock;
+ private Mock<IContextAccessor> _workContextMock;
private CheckoutAttribute ca1, ca2, ca3;
private Mock<ICacheBase> cacheManager;
@@ -119,7 +119,7 @@ public class CheckoutAttributeParserTests
}
cacheManager = new Mock<ICacheBase>();
- _workContextMock = new Mock<IWorkContextAccessor>();
+ _workContextMock = new Mock<IContextAccessor>();
_checkoutAttributeService = new CheckoutAttributeService(cacheManager.Object, _checkoutAttributeRepo,
_eventPublisher, _workContextMock.Object, new AccessControlConfig());
diff --git a/src/Tests/Grand.Business.Checkout.Tests/Services/CheckoutAttributes/CheckoutAttributeServiceTests.cs b/src/Tests/Grand.Business.Checkout.Tests/Services/CheckoutAttributes/CheckoutAttributeServiceTests.cs
index f43d7dae2..ad4b9a02d 100644
--- a/src/Tests/Grand.Business.Checkout.Tests/Services/CheckoutAttributes/CheckoutAttributeServiceTests.cs
+++ b/src/Tests/Grand.Business.Checkout.Tests/Services/CheckoutAttributes/CheckoutAttributeServiceTests.cs
@@ -19,7 +19,7 @@ public class CheckoutAttributeServiceTests
private Mock<IMediator> _mediatorMock;
private Mock<IRepository<CheckoutAttribute>> _repositoryMock;
private ICheckoutAttributeService _service;
- private Mock<IWorkContextAccessor> _workContextMock;
+ private Mock<IContextAccessor> _workContextMock;
[TestInitialize]
public void Init()
@@ -27,7 +27,7 @@ public class CheckoutAttributeServiceTests
_cacheMock = new Mock<ICacheBase>();
_repositoryMock = new Mock<IRepository<CheckoutAttribute>>();
_mediatorMock = new Mock<IMediator>();
- _workContextMock = new Mock<IWorkContextAccessor>();
+ _workContextMock = new Mock<IContextAccessor>();
_service = new CheckoutAttributeService(_cacheMock.Object, _repositoryMock.Object, _mediatorMock.Object,
_workContextMock.Object, new AccessControlConfig());
}
diff --git a/src/Tests/Grand.Business.Checkout.Tests/Services/Orders/OrderCalculationServiceTests.cs b/src/Tests/Grand.Business.Checkout.Tests/Services/Orders/OrderCalculationServiceTests.cs
index 4f074c55e..b5f388971 100644
--- a/src/Tests/Grand.Business.Checkout.Tests/Services/Orders/OrderCalculationServiceTests.cs
+++ b/src/Tests/Grand.Business.Checkout.Tests/Services/Orders/OrderCalculationServiceTests.cs
@@ -46,12 +46,12 @@ public class OrderCalculationServiceTests
private Mock<ITaxService> _taxServiceMock;
private TaxSettings _taxSettings;
- private Mock<IWorkContextAccessor> _workContextMock;
+ private Mock<IContextAccessor> _workContextMock;
[TestInitialize]
public void Init()
{
- _workContextMock = new Mock<IWorkContextAccessor>();
+ _workContextMock = new Mock<IContextAccessor>();
_pricingServiceMock = new Mock<IPricingService>();
_taxServiceMock = new Mock<ITaxService>();
_shippingServiceMock = new Mock<IShippingService>();
@@ -69,7 +69,7 @@ public class OrderCalculationServiceTests
_shoppingCartSettings = new ShoppingCartSettings();
_catalogSettings = new CatalogSettings();
_discountValidationService = new Mock<IDiscountValidationService>();
- _workContextMock.Setup(c => c.WorkContext.CurrentStore).Returns(() => new Store { Id = "", Name = "test store" });
+ _workContextMock.Setup(c => c.StoreContext.CurrentStore).Returns(() => new Store { Id = "", Name = "test store" });
var customer = new Customer();
customer.Groups.Add("1");
_workContextMock.Setup(c => c.WorkContext.CurrentCustomer).Returns(() => customer);
diff --git a/src/Tests/Grand.Business.Checkout.Tests/Services/Orders/ShoppingCartServiceTests.cs b/src/Tests/Grand.Business.Checkout.Tests/Services/Orders/ShoppingCartServiceTests.cs
index 15936454b..9c8f4d7fb 100644
--- a/src/Tests/Grand.Business.Checkout.Tests/Services/Orders/ShoppingCartServiceTests.cs
+++ b/src/Tests/Grand.Business.Checkout.Tests/Services/Orders/ShoppingCartServiceTests.cs
@@ -27,19 +27,19 @@ public class ShoppingCartServiceTests
private ShoppingCartService _shoppingCartService;
private ShoppingCartSettings _shoppingCartSettings;
private Mock<IShoppingCartValidator> _shoppingCartValidatorMock;
- private Mock<IWorkContextAccessor> _workContextMock;
+ private Mock<IContextAccessor> _workContextMock;
[TestInitialize]
public void Init()
{
- _workContextMock = new Mock<IWorkContextAccessor>();
+ _workContextMock = new Mock<IContextAccessor>();
_productServiceMock = new Mock<IProductService>();
_shoppingCartSettings = new ShoppingCartSettings();
_customerServiceMock = new Mock<ICustomerService>();
_mediatorMock = new Mock<IMediator>();
_shoppingCartValidatorMock = new Mock<IShoppingCartValidator>();
- _workContextMock.Setup(c => c.WorkContext.CurrentStore).Returns(() => new Store { Id = "", Name = "test store" });
+ _workContextMock.Setup(c => c.StoreContext.CurrentStore).Returns(() => new Store { Id = "", Name = "test store" });
var customer = new Customer();
customer.Groups.Add("1");
_workContextMock.Setup(c => c.WorkContext.CurrentCustomer).Returns(() => customer);
diff --git a/src/Tests/Grand.Business.Cms.Tests/Services/KnowledgebaseServiceTests.cs b/src/Tests/Grand.Business.Cms.Tests/Services/KnowledgebaseServiceTests.cs
index d7790e612..558737df6 100644
--- a/src/Tests/Grand.Business.Cms.Tests/Services/KnowledgebaseServiceTests.cs
+++ b/src/Tests/Grand.Business.Cms.Tests/Services/KnowledgebaseServiceTests.cs
@@ -25,7 +25,7 @@ public class KnowledgebaseServiceTests
private IRepository<KnowledgebaseArticleComment> _repositoryKnowledgebaseArticleComment;
private IRepository<KnowledgebaseCategory> _repositoryKnowledgebaseCategory;
- private Mock<IWorkContextAccessor> _workContextMock;
+ private Mock<IContextAccessor> _workContextMock;
[TestInitialize]
public void Init()
@@ -35,9 +35,9 @@ public class KnowledgebaseServiceTests
_repositoryKnowledgebaseArticleComment = new MongoDBRepositoryTest<KnowledgebaseArticleComment>();
_mediatorMock = new Mock<IMediator>();
- _workContextMock = new Mock<IWorkContextAccessor>();
+ _workContextMock = new Mock<IContextAccessor>();
- _workContextMock.Setup(c => c.WorkContext.CurrentStore).Returns(() => new Store { Id = "", Name = "test store" });
+ _workContextMock.Setup(c => c.StoreContext.CurrentStore).Returns(() => new Store { Id = "", Name = "test store" });
_workContextMock.Setup(c => c.WorkContext.CurrentCustomer).Returns(() => new Customer());
_cacheBase = new MemoryCacheBase(MemoryCacheTest.Get(), _mediatorMock.Object,
diff --git a/src/Tests/Grand.Business.Cms.Tests/Services/NewsServiceTests.cs b/src/Tests/Grand.Business.Cms.Tests/Services/NewsServiceTests.cs
index fd6029846..fc3cf2889 100644
--- a/src/Tests/Grand.Business.Cms.Tests/Services/NewsServiceTests.cs
+++ b/src/Tests/Grand.Business.Cms.Tests/Services/NewsServiceTests.cs
@@ -19,7 +19,7 @@ public class NewsServiceTests
private NewsService _newsService;
private IRepository<NewsItem> _repository;
- private Mock<IWorkContextAccessor> _workContextMock;
+ private Mock<IContextAccessor> _workContextMock;
[TestInitialize]
public void Init()
@@ -27,9 +27,9 @@ public class NewsServiceTests
_repository = new MongoDBRepositoryTest<NewsItem>();
_mediatorMock = new Mock<IMediator>();
- _workContextMock = new Mock<IWorkContextAccessor>();
+ _workContextMock = new Mock<IContextAccessor>();
- _workContextMock.Setup(c => c.WorkContext.CurrentStore).Returns(() => new Store { Id = "", Name = "test store" });
+ _workContextMock.Setup(c => c.StoreContext.CurrentStore).Returns(() => new Store { Id = "", Name = "test store" });
_workContextMock.Setup(c => c.WorkContext.CurrentCustomer).Returns(() => new Customer());
_newsService = new NewsService(_repository, _mediatorMock.Object, _workContextMock.Object,
diff --git a/src/Tests/Grand.Business.Cms.Tests/Services/PageLayoutServiceTests.cs b/src/Tests/Grand.Business.Cms.Tests/Services/PageLayoutServiceTests.cs
index 414f3fa59..b174ba0b5 100644
--- a/src/Tests/Grand.Business.Cms.Tests/Services/PageLayoutServiceTests.cs
+++ b/src/Tests/Grand.Business.Cms.Tests/Services/PageLayoutServiceTests.cs
@@ -23,6 +23,7 @@ public class PageLayoutServiceTests
private IRepository<PageLayout> _repository;
private Mock<IWorkContext> _workContextMock;
+ private Mock<IStoreContext> _storeContextMock;
[TestInitialize]
public void Init()
@@ -31,11 +32,11 @@ public class PageLayoutServiceTests
_mediatorMock = new Mock<IMediator>();
_workContextMock = new Mock<IWorkContext>();
-
+ _storeContextMock = new Mock<IStoreContext>();
_cacheBase = new MemoryCacheBase(MemoryCacheTest.Get(), _mediatorMock.Object,
new CacheConfig { DefaultCacheTimeMinutes = 1 });
- _workContextMock.Setup(c => c.CurrentStore).Returns(() => new Store { Id = "", Name = "test store" });
+ _storeContextMock.Setup(c => c.CurrentStore).Returns(() => new Store { Id = "", Name = "test store" });
_workContextMock.Setup(c => c.CurrentCustomer).Returns(() => new Customer());
_pageLayoutService = new PageLayoutService(_repository, _cacheBase, _mediatorMock.Object);
diff --git a/src/Tests/Grand.Business.Cms.Tests/Services/PageServiceTests.cs b/src/Tests/Grand.Business.Cms.Tests/Services/PageServiceTests.cs
index 5bdd08bff..e2abc9e9e 100644
--- a/src/Tests/Grand.Business.Cms.Tests/Services/PageServiceTests.cs
+++ b/src/Tests/Grand.Business.Cms.Tests/Services/PageServiceTests.cs
@@ -25,7 +25,7 @@ public class PageServiceTests
private PageService _pageService;
private IRepository<Page> _repository;
- private Mock<IWorkContextAccessor> _workContextMock;
+ private Mock<IContextAccessor> _workContextMock;
[TestInitialize]
public void Init()
@@ -33,14 +33,14 @@ public class PageServiceTests
_repository = new MongoDBRepositoryTest<Page>();
_mediatorMock = new Mock<IMediator>();
- _workContextMock = new Mock<IWorkContextAccessor>();
+ _workContextMock = new Mock<IContextAccessor>();
_cacheBase = new MemoryCacheBase(MemoryCacheTest.Get(), _mediatorMock.Object,
new CacheConfig { DefaultCacheTimeMinutes = 1 });
_aclService = new AclService(new AccessControlConfig());
- _workContextMock.Setup(c => c.WorkContext.CurrentStore).Returns(() => new Store { Id = "", Name = "test store" });
+ _workContextMock.Setup(c => c.StoreContext.CurrentStore).Returns(() => new Store { Id = "", Name = "test store" });
_workContextMock.Setup(c => c.WorkContext.CurrentCustomer).Returns(() => new Customer());
_pageService = new PageService(_repository, _workContextMock.Object, _aclService, _mediatorMock.Object,
diff --git a/src/Tests/Grand.Business.Cms.Tests/Services/RobotsTxtServiceTests.cs b/src/Tests/Grand.Business.Cms.Tests/Services/RobotsTxtServiceTests.cs
index 2ff1bd6cf..a4d4c02d8 100644
--- a/src/Tests/Grand.Business.Cms.Tests/Services/RobotsTxtServiceTests.cs
+++ b/src/Tests/Grand.Business.Cms.Tests/Services/RobotsTxtServiceTests.cs
@@ -23,6 +23,7 @@ public class RobotsTxtServiceTests
private IRepository<RobotsTxt> _repository;
private RobotsTxtService _robotsTxtService;
private Mock<IWorkContext> _workContextMock;
+ private Mock<IStoreContext> _storeContextMock;
[TestInitialize]
public void Init()
@@ -31,11 +32,11 @@ public class RobotsTxtServiceTests
_mediatorMock = new Mock<IMediator>();
_workContextMock = new Mock<IWorkContext>();
-
+ _storeContextMock = new Mock<IStoreContext>();
_cacheBase = new MemoryCacheBase(MemoryCacheTest.Get(), _mediatorMock.Object,
new CacheConfig { DefaultCacheTimeMinutes = 1 });
- _workContextMock.Setup(c => c.CurrentStore).Returns(() => new Store { Id = "", Name = "test store" });
+ _storeContextMock.Setup(c => c.CurrentStore).Returns(() => new Store { Id = "", Name = "test store" });
_workContextMock.Setup(c => c.CurrentCustomer).Returns(() => new Customer());
_robotsTxtService = new RobotsTxtService(_repository, _mediatorMock.Object, _cacheBase);
diff --git a/src/Tests/Grand.Business.Common.Tests/Services/Localization/TranslationServiceTests.cs b/src/Tests/Grand.Business.Common.Tests/Services/Localization/TranslationServiceTests.cs
index 612e8f7a9..1b125d686 100644
--- a/src/Tests/Grand.Business.Common.Tests/Services/Localization/TranslationServiceTests.cs
+++ b/src/Tests/Grand.Business.Common.Tests/Services/Localization/TranslationServiceTests.cs
@@ -18,7 +18,7 @@ public class TranslationServiceTests
private IRepository<TranslationResource> _repository;
private TranslationService _translationService;
- private Mock<IWorkContextAccessor> _workContextMock;
+ private Mock<IContextAccessor> _workContextMock;
[TestInitialize]
public void Init()
@@ -26,8 +26,8 @@ public class TranslationServiceTests
_repository = new MongoDBRepositoryTest<TranslationResource>();
_mediatorMock = new Mock<IMediator>();
- _workContextMock = new Mock<IWorkContextAccessor>();
- _workContextMock.Setup(c => c.WorkContext.CurrentStore).Returns(() => new Store());
+ _workContextMock = new Mock<IContextAccessor>();
+ _workContextMock.Setup(c => c.StoreContext.CurrentStore).Returns(() => new Store());
_workContextMock.Setup(c => c.WorkContext.CurrentCustomer).Returns(() => new Customer());
_workContextMock.Setup(c => c.WorkContext.WorkingLanguage).Returns(() => new Language { Id = "1" });
diff --git a/src/Tests/Grand.Business.Common.Tests/Services/Security/PermissionServiceTests.cs b/src/Tests/Grand.Business.Common.Tests/Services/Security/PermissionServiceTests.cs
index c73ba6dae..9fcec5f23 100644
--- a/src/Tests/Grand.Business.Common.Tests/Services/Security/PermissionServiceTests.cs
+++ b/src/Tests/Grand.Business.Common.Tests/Services/Security/PermissionServiceTests.cs
@@ -18,14 +18,14 @@ public class PermissionServiceTests
private Mock<IRepository<PermissionAction>> _permissionActionRepositoryMock;
private Mock<IRepository<Permission>> _permissionRepositoryMock;
private PermissionService _service;
- private Mock<IWorkContextAccessor> _workContextMock;
+ private Mock<IContextAccessor> _workContextMock;
[TestInitialize]
public void Init()
{
_permissionRepositoryMock = new Mock<IRepository<Permission>>();
_permissionActionRepositoryMock = new Mock<IRepository<PermissionAction>>();
- _workContextMock = new Mock<IWorkContextAccessor>();
+ _workContextMock = new Mock<IContextAccessor>();
_groupServiceMock = new Mock<IGroupService>();
_cacheMock = new Mock<ICacheBase>();
_service = new PermissionService(_permissionRepositoryMock.Object, _permissionActionRepositoryMock.Object,
diff --git a/src/Tests/Grand.Business.Common.Tests/Services/Stores/StoreServiceTests.cs b/src/Tests/Grand.Business.Common.Tests/Services/Stores/StoreServiceTests.cs
index 31b5a0ba3..48df1e7b0 100644
--- a/src/Tests/Grand.Business.Common.Tests/Services/Stores/StoreServiceTests.cs
+++ b/src/Tests/Grand.Business.Common.Tests/Services/Stores/StoreServiceTests.cs
@@ -63,4 +63,60 @@ public class StoreServiceTests
.Returns(Task.FromResult(new List<Store> { new() }));
Assert.ThrowsExceptionAsync<Exception>(async () => await _service.DeleteStore(new Store()));
}
+
+ [TestMethod]
+ public async Task GetStoreByHost_MatchingHost_ReturnsMatchingStore()
+ {
+ // Arrange
+ var store1 = new Store { Url = "http://store1.com" };
+ store1.Domains = new List<DomainHost>
+ {
+ new DomainHost { HostName = "store1.com", Url = "http://store1.com", Primary = true }
+ };
+
+ var store2 = new Store { Url = "http://store2.com" };
+ store2.Domains = new List<DomainHost>
+ {
+ new DomainHost { HostName = "store2.com", Url = "http://store2.com", Primary = true }
+ };
+
+ var stores = new List<Store> { store1, store2 };
+
+ _cacheMock.Setup(c => c.GetAsync(It.IsAny<string>(), It.IsAny<Func<Task<List<Store>>>>()))
+ .Returns(Task.FromResult(stores));
+
+ // Act
+ var result = await _service.GetStoreByHost("store1.com");
+
+ // Assert
+ Assert.AreEqual(store1, result);
+ }
+
+ [TestMethod]
+ public async Task GetStoreByHost_NoMatchingHost_ReturnsNullStore()
+ {
+ // Arrange
+ var store1 = new Store { Url = "http://store1.com" };
+ store1.Domains = new List<DomainHost>
+ {
+ new DomainHost { HostName = "store1.com", Url = "http://store1.com", Primary = true }
+ };
+
+ var store2 = new Store { Url = "http://store2.com" };
+ store2.Domains = new List<DomainHost>
+ {
+ new DomainHost { HostName = "store2.com", Url = "http://store2.com", Primary = true }
+ };
+
+ var stores = new List<Store> { store1, store2 };
+
+ _cacheMock.Setup(c => c.GetAsync(It.IsAny<string>(), It.IsAny<Func<Task<List<Store>>>>()))
+ .Returns(Task.FromResult(stores));
+
+ // Act - host not found in any DomainHost
+ var result = await _service.GetStoreByHost("nonexisting.com");
+
+ // Assert - returns first store
+ Assert.AreEqual(null, result);
+ }
}
\ No newline at end of file
diff --git a/src/Tests/Grand.Business.Customers.Tests/Extensions/AffiliateExtensionsTests.cs b/src/Tests/Grand.Business.Customers.Tests/Extensions/AffiliateExtensionsTests.cs
index 76bb5fa14..d742ee00b 100644
--- a/src/Tests/Grand.Business.Customers.Tests/Extensions/AffiliateExtensionsTests.cs
+++ b/src/Tests/Grand.Business.Customers.Tests/Extensions/AffiliateExtensionsTests.cs
@@ -17,11 +17,13 @@ public class AffiliateExtensionsTests
private readonly string _expectedFormat = _fakeStoreUrl + "?{0}={1}";
private Mock<IAffiliateService> _affiliateServiceMock;
private Mock<IWorkContext> _workContextMock;
+ private Mock<IStoreContext> _storeContextMock;
[TestInitialize]
public void TestInitialize()
{
_workContextMock = new Mock<IWorkContext>();
+ _storeContextMock = new Mock<IStoreContext>();
_affiliateServiceMock = new Mock<IAffiliateService>();
}
@@ -84,7 +86,7 @@ public class AffiliateExtensionsTests
var affiliate = new Affiliate {
Id = id
};
- _workContextMock.Setup(c => c.CurrentStore).Returns(new Store { Url = _fakeStoreUrl });
+ _storeContextMock.Setup(c => c.CurrentStore).Returns(new Store { Url = _fakeStoreUrl });
Assert.AreEqual(string.Format(_expectedFormat, "affiliateid", id), affiliate.GenerateUrl("http://localhost/"));
//_webHelperMock.Verify(c => c.ModifyQueryString(It.IsAny<string>(), It.IsAny<string>(), It.IsAny<string>()), Times.Once);
}
@@ -96,7 +98,7 @@ public class AffiliateExtensionsTests
var affiliate = new Affiliate {
FriendlyUrlName = friendlyUrl
};
- _workContextMock.Setup(c => c.CurrentStore).Returns(new Store { Url = _fakeStoreUrl });
+ _storeContextMock.Setup(c => c.CurrentStore).Returns(new Store { Url = _fakeStoreUrl });
Assert.AreEqual(string.Format(_expectedFormat, "affiliate", friendlyUrl),
affiliate.GenerateUrl("http://localhost/"));
}
diff --git a/src/Tests/Grand.Business.Marketing.Tests/Services/Campaigns/CampaignServiceTests.cs b/src/Tests/Grand.Business.Marketing.Tests/Services/Campaigns/CampaignServiceTests.cs
index aeead4633..3041d9f3c 100644
--- a/src/Tests/Grand.Business.Marketing.Tests/Services/Campaigns/CampaignServiceTests.cs
+++ b/src/Tests/Grand.Business.Marketing.Tests/Services/Campaigns/CampaignServiceTests.cs
@@ -29,7 +29,7 @@ public class CampaignServiceTests
private IRepository<NewsLetterSubscription> _newsLetterSubscriptionRepository;
private Mock<IQueuedEmailService> _queuedEmailServiceMock;
private Mock<IStoreService> _storeServiceMock;
- private Mock<IWorkContextAccessor> _workContextMock;
+ private Mock<IContextAccessor> _workContextMock;
[TestInitialize]
public void Init()
@@ -43,7 +43,7 @@ public class CampaignServiceTests
_queuedEmailServiceMock = new Mock<IQueuedEmailService>();
_storeServiceMock = new Mock<IStoreService>();
_languageServiceMock = new Mock<ILanguageService>();
- _workContextMock = new Mock<IWorkContextAccessor>();
+ _workContextMock = new Mock<IContextAccessor>();
_campaignService = new CampaignService(_campaignRepository, _campaignHistoryRepository,
_newsLetterSubscriptionRepository, _customerRepository,
_emailSenderMock.Object, _queuedEmailServiceMock.Object, _storeServiceMock.Object, _mediatorMock.Object,
diff --git a/src/Tests/Grand.Business.Marketing.Tests/Services/Contacts/ContactAttributeParserTests.cs b/src/Tests/Grand.Business.Marketing.Tests/Services/Contacts/ContactAttributeParserTests.cs
index 98fb189f4..bc4f60938 100644
--- a/src/Tests/Grand.Business.Marketing.Tests/Services/Contacts/ContactAttributeParserTests.cs
+++ b/src/Tests/Grand.Business.Marketing.Tests/Services/Contacts/ContactAttributeParserTests.cs
@@ -18,14 +18,14 @@ public class ContactAttributeParserTests
private List<ContactAttribute> _contactAtr;
private Mock<IContactAttributeService> _contactAttributeServiceMock;
private ContactAttributeParser _parser;
- private Mock<IWorkContextAccessor> _workContextMock;
+ private Mock<IContextAccessor> _workContextMock;
private List<CustomAttribute> customAtr;
[TestInitialize]
public void Init()
{
_contactAttributeServiceMock = new Mock<IContactAttributeService>();
- _workContextMock = new Mock<IWorkContextAccessor>();
+ _workContextMock = new Mock<IContextAccessor>();
var _translationServiceMock = new Mock<ITranslationService>();
{
_translationServiceMock.Setup(x => x.GetResource(It.IsAny<string>())).Returns("Warning{0}");
diff --git a/src/Tests/Grand.Business.Marketing.Tests/Services/Contacts/ContactAttributeServiceTests.cs b/src/Tests/Grand.Business.Marketing.Tests/Services/Contacts/ContactAttributeServiceTests.cs
index c384ed429..7f38cb21d 100644
--- a/src/Tests/Grand.Business.Marketing.Tests/Services/Contacts/ContactAttributeServiceTests.cs
+++ b/src/Tests/Grand.Business.Marketing.Tests/Services/Contacts/ContactAttributeServiceTests.cs
@@ -21,15 +21,15 @@ public class ContactAttributeServiceTests
private ContactAttributeService _contactAttributeService;
private Mock<IMediator> _mediatorMock;
private IRepository<ContactAttribute> _repository;
- private Mock<IWorkContextAccessor> _workContextMock;
+ private Mock<IContextAccessor> _workContextMock;
[TestInitialize]
public void Init()
{
_repository = new MongoDBRepositoryTest<ContactAttribute>();
_mediatorMock = new Mock<IMediator>();
- _workContextMock = new Mock<IWorkContextAccessor>();
- _workContextMock.Setup(c => c.WorkContext.CurrentStore).Returns(() => new Store { Id = "" });
+ _workContextMock = new Mock<IContextAccessor>();
+ _workContextMock.Setup(c => c.StoreContext.CurrentStore).Returns(() => new Store { Id = "" });
_workContextMock.Setup(c => c.WorkContext.CurrentCustomer).Returns(() => new Customer());
var accessControlConfig = new AccessControlConfig();
_cacheBase = new MemoryCacheBase(MemoryCacheTest.Get(), _mediatorMock.Object,
diff --git a/src/Tests/Grand.Business.Marketing.Tests/Services/Customers/CustomerCoordinatesServiceTests.cs b/src/Tests/Grand.Business.Marketing.Tests/Services/Customers/CustomerCoordinatesServiceTests.cs
index f2fc01701..d2fed8f51 100644
--- a/src/Tests/Grand.Business.Marketing.Tests/Services/Customers/CustomerCoordinatesServiceTests.cs
+++ b/src/Tests/Grand.Business.Marketing.Tests/Services/Customers/CustomerCoordinatesServiceTests.cs
@@ -18,15 +18,15 @@ public class CustomerCoordinatesServiceTests
private CustomerCoordinatesService _customerCoordinatesService;
private Mock<IMediator> _mediatorMock;
private IRepository<Customer> _repository;
- private Mock<IWorkContextAccessor> _workContextMock;
+ private Mock<IContextAccessor> _workContextMock;
[TestInitialize]
public void Init()
{
_repository = new MongoDBRepositoryTest<Customer>();
_mediatorMock = new Mock<IMediator>();
- _workContextMock = new Mock<IWorkContextAccessor>();
- _workContextMock.Setup(c => c.WorkContext.CurrentStore).Returns(() => new Store { Id = "" });
+ _workContextMock = new Mock<IContextAccessor>();
+ _workContextMock.Setup(c => c.StoreContext.CurrentStore).Returns(() => new Store { Id = "" });
_customer = new Customer();
_workContextMock.Setup(c => c.WorkContext.CurrentCustomer).Returns(() => _customer);
diff --git a/src/Tests/Grand.Business.Marketing.Tests/Services/PushNotifications/PushNotificationsServiceTests.cs b/src/Tests/Grand.Business.Marketing.Tests/Services/PushNotifications/PushNotificationsServiceTests.cs
index 7bd799e1b..b901d452d 100644
--- a/src/Tests/Grand.Business.Marketing.Tests/Services/PushNotifications/PushNotificationsServiceTests.cs
+++ b/src/Tests/Grand.Business.Marketing.Tests/Services/PushNotifications/PushNotificationsServiceTests.cs
@@ -111,7 +111,7 @@ public class PushNotificationsServiceTests
await _pushNotificationsService.InsertPushReceiver(new PushRegistration { Allowed = true });
//Act
- var result = await _pushNotificationsService.GetPushReceivers();
+ var result = await _pushNotificationsService.GetAllowedPushReceivers();
//Assert
Assert.AreEqual(2, result.Count);
@@ -178,7 +178,7 @@ public class PushNotificationsServiceTests
await _repositoryPushRegistration.InsertAsync(new PushRegistration { Allowed = true });
//Act
- var result = await _pushNotificationsService.GetPushReceivers();
+ var result = await _pushNotificationsService.GetAllowedPushReceivers();
//Assert
Assert.AreEqual(3, result.Count);
diff --git a/src/Tests/Grand.Business.Messages.Tests/Services/MessageProviderServiceTest.cs b/src/Tests/Grand.Business.Messages.Tests/Services/MessageProviderServiceTest.cs
index e264c666d..cc9a025f4 100644
--- a/src/Tests/Grand.Business.Messages.Tests/Services/MessageProviderServiceTest.cs
+++ b/src/Tests/Grand.Business.Messages.Tests/Services/MessageProviderServiceTest.cs
@@ -32,7 +32,7 @@ public class MessageProviderServiceTest
private Mock<IMessageTokenProvider> _messageTokenProviderMock;
private Product _product;
private Mock<IQueuedEmailService> _queuedEmailServiceMock;
- private Mock<IWorkContextAccessor> _workContextAccessorMock;
+ private Mock<IContextAccessor> _contextAccessorMock;
private Mock<IStoreService> _storeServiceMock;
[TestInitialize]
@@ -62,8 +62,8 @@ public class MessageProviderServiceTest
.Returns(Task.FromResult(new Store { Url = "https://localhost:44350/" }));
_storeServiceMock.Setup(x => x.GetAllStores()).Returns(Task.FromResult(new List<Store>() as IList<Store>));
- _workContextAccessorMock = new Mock<IWorkContextAccessor>();
- _workContextAccessorMock.Setup(x => x.WorkContext.CurrentHost).Returns(new DomainHost { Url = "https://localhost:44350/" });
+ _contextAccessorMock = new Mock<IContextAccessor>();
+ _contextAccessorMock.Setup(x => x.StoreContext.CurrentHost).Returns(new DomainHost { Url = "https://localhost:44350/" });
_mediatorMock = new Mock<IMediator>();
_mediatorMock.Setup(x => x.Send(It.IsAny<GetCustomerByIdQuery>(), default))
.Returns(Task.FromResult(new Customer { Email = "[email protected]" }));
@@ -72,7 +72,7 @@ public class MessageProviderServiceTest
_commonSetting = new Mock<CommonSettings>();
_messageService = new MessageProviderService(
- _workContextAccessorMock.Object,
+ _contextAccessorMock.Object,
_messageTemplateServiceMock.Object,
_queuedEmailServiceMock.Object,
_languageServiceMock.Object,
diff --git a/src/Tests/Grand.Modules.Tests/Services/Migrations/MigrationProcessTest.cs b/src/Tests/Grand.Modules.Tests/Services/Migrations/MigrationProcessTest.cs
deleted file mode 100644
index e395dac28..000000000
--- a/src/Tests/Grand.Modules.Tests/Services/Migrations/MigrationProcessTest.cs
+++ /dev/null
@@ -1,42 +0,0 @@
-using Grand.Data;
-using Grand.Domain;
-using Grand.Domain.Common;
-using Grand.Module.Migration.Migrations;
-using Microsoft.Extensions.Logging;
-using Microsoft.VisualStudio.TestTools.UnitTesting;
-using Moq;
-
-namespace Grand.Modules.Tests.Services.Migrations;
-
-[TestClass]
-public class MigrationProcessTest
-{
- private Mock<IDatabaseContext> _dbContext;
- private Mock<ILogger<MigrationProcess>> _loggerMock;
- private Mock<IRepository<MigrationDb>> _repository;
- private Mock<IRepository<GrandNodeVersion>> _repositoryVersion;
- private MigrationProcess _service;
- private IServiceProvider _serviceProvider;
-
- [TestInitialize]
- public void Init()
- {
- var serviceProvider = new Mock<IServiceProvider>();
- _serviceProvider = serviceProvider.Object;
-
- _repository = new Mock<IRepository<MigrationDb>>();
- _repositoryVersion = new Mock<IRepository<GrandNodeVersion>>();
- _dbContext = new Mock<IDatabaseContext>();
- _loggerMock = new Mock<ILogger<MigrationProcess>>();
- _service = new MigrationProcess(_dbContext.Object, _serviceProvider, _loggerMock.Object, _repository.Object, _repositoryVersion.Object);
- }
- //TODO
- /*
- [TestMethod]
- public void RunMigrationProcess_CheckInsertMigrationDb()
- {
- _service.RunMigrationProcess();
- _repository.Verify(c => c.Insert(It.IsAny<MigrationDb>()), Times.AtLeastOnce);
- }
- */
-}
\ No newline at end of file
diff --git a/src/Tests/Grand.Web.Common.Tests/AuthorizeMenuAttributeTests.cs b/src/Tests/Grand.Web.Common.Tests/AuthorizeMenuAttributeTests.cs
index 531588cfd..88eb626af 100644
--- a/src/Tests/Grand.Web.Common.Tests/AuthorizeMenuAttributeTests.cs
+++ b/src/Tests/Grand.Web.Common.Tests/AuthorizeMenuAttributeTests.cs
@@ -24,7 +24,7 @@ public class AuthorizeMenuAttributeTests
private Mock<IAdminSiteMapService> _mockAdminSiteMapService;
private AuthorizationFilterContext _mockFilterContext;
private Mock<IPermissionService> _mockPermissionService;
- private Mock<IWorkContextAccessor> _mockWorkContext;
+ private Mock<IContextAccessor> _mockWorkContext;
private SecurityConfig _securityConfig;
[TestInitialize]
@@ -35,7 +35,7 @@ public class AuthorizeMenuAttributeTests
var settings = DataSettingsManager.Instance.LoadSettings();
_mockPermissionService = new Mock<IPermissionService>();
_mockAdminSiteMapService = new Mock<IAdminSiteMapService>();
- _mockWorkContext = new Mock<IWorkContextAccessor>();
+ _mockWorkContext = new Mock<IContextAccessor>();
_mockWorkContext.Setup(s => s.WorkContext.CurrentCustomer).Returns(new Customer());
_securityConfig = new SecurityConfig();
diff --git a/src/Tests/Grand.Web.Common.Tests/Grand.Web.Common.Tests.csproj b/src/Tests/Grand.Web.Common.Tests/Grand.Web.Common.Tests.csproj
index b556b39a1..82aa90c93 100644
--- a/src/Tests/Grand.Web.Common.Tests/Grand.Web.Common.Tests.csproj
+++ b/src/Tests/Grand.Web.Common.Tests/Grand.Web.Common.Tests.csproj
@@ -26,7 +26,4 @@
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
</ItemGroup>
- <ItemGroup>
- <Folder Include="Services\" />
- </ItemGroup>
</Project>
diff --git a/src/Tests/Grand.Web.Common.Tests/Services/Admin/AdminStoreServiceTests.cs b/src/Tests/Grand.Web.Common.Tests/Services/Admin/AdminStoreServiceTests.cs
new file mode 100644
index 000000000..668baff93
--- /dev/null
+++ b/src/Tests/Grand.Web.Common.Tests/Services/Admin/AdminStoreServiceTests.cs
@@ -0,0 +1,86 @@
+using Grand.Business.Core.Interfaces.Common.Stores;
+using Grand.Domain.Common;
+using Grand.Domain.Customers;
+using Grand.Domain.Stores;
+using Grand.Infrastructure;
+using Grand.Web.Common.Helpers;
+using Microsoft.VisualStudio.TestTools.UnitTesting;
+using Moq;
+
+namespace Grand.Web.Common.Tests.Services.Admin;
+
+[TestClass]
+public class AdminStoreServiceTests
+{
+ private Mock<IStoreService> _storeServiceMock;
+ private Mock<IContextAccessor> _contextAccessorMock;
+ private AdminStoreService _adminStoreService;
+
+ [TestInitialize]
+ public void Init()
+ {
+ _storeServiceMock = new Mock<IStoreService>();
+ _contextAccessorMock = new Mock<IContextAccessor>();
+ _adminStoreService = new AdminStoreService(_storeServiceMock.Object, _contextAccessorMock.Object);
+ }
+
+ [TestMethod]
+ public async Task GetActiveStore_ShouldReturnSingleStoreId_WhenOnlyOneStoreExists()
+ {
+ // Arrange
+ var store = new Store { Id = "store1" };
+ _storeServiceMock.Setup(s => s.GetAllStores()).ReturnsAsync(new List<Store> { store });
+
+ // Act
+ var result = await _adminStoreService.GetActiveStore();
+
+ // Assert
+ Assert.AreEqual("store1", result);
+ }
+
+ [TestMethod]
+ public async Task GetActiveStore_ShouldReturnStoreIdFromContext_WhenMultipleStoresExist()
+ {
+ // Arrange
+ var stores = new List<Store> { new Store { Id = "store1" }, new Store { Id = "store2" } };
+ var customer = new Customer { CustomerGuid = Guid.NewGuid() };
+ customer.UserFields.Add(new UserField() {
+ Key = SystemCustomerFieldNames.AdminAreaStoreScopeConfiguration,
+ Value = "store2",
+ StoreId = ""
+ });
+
+ _storeServiceMock.Setup(s => s.GetAllStores()).ReturnsAsync(stores);
+ _contextAccessorMock.Setup(c => c.WorkContext.CurrentCustomer).Returns(customer);
+ _storeServiceMock.Setup(s => s.GetStoreById("store2")).ReturnsAsync(new Store { Id = "store2" });
+
+ // Act
+ var result = await _adminStoreService.GetActiveStore();
+
+ // Assert
+ Assert.AreEqual("store2", result);
+ }
+
+ [TestMethod]
+ public async Task GetActiveStore_ShouldReturnEmptyString_WhenStoreFromContextDoesNotExist()
+ {
+ // Arrange
+ var stores = new List<Store> { new Store { Id = "store1" }, new Store { Id = "store2" } };
+ _storeServiceMock.Setup(s => s.GetAllStores()).ReturnsAsync(stores);
+
+ var customer = new Customer { CustomerGuid = Guid.NewGuid() };
+ customer.UserFields.Add(new UserField() {
+ Key = SystemCustomerFieldNames.AdminAreaStoreScopeConfiguration,
+ Value = "store3",
+ StoreId = ""
+ });
+ _contextAccessorMock.Setup(c => c.WorkContext.CurrentCustomer).Returns(customer);
+ _storeServiceMock.Setup(s => s.GetStoreById("store3")).ReturnsAsync((Store)null);
+
+ // Act
+ var result = await _adminStoreService.GetActiveStore();
+
+ // Assert
+ Assert.AreEqual(string.Empty, result);
+ }
+}
\ No newline at end of file
diff --git a/src/Web/Grand.Web.Admin/Areas/Admin/Views/Home/Index.cshtml b/src/Web/Grand.Web.Admin/Areas/Admin/Views/Home/Index.cshtml
index ca79c0e23..acb6eedf7 100644
--- a/src/Web/Grand.Web.Admin/Areas/Admin/Views/Home/Index.cshtml
+++ b/src/Web/Grand.Web.Admin/Areas/Admin/Views/Home/Index.cshtml
@@ -10,18 +10,18 @@
@inject ICustomerService customerService
@inject IOrderReportService orderReportService
@inject IPriceFormatter priceFormatter
-@inject IWorkContextAccessor workContextAccessor
+@inject IContextAccessor contextAccessor
@inject ICurrencyService currencyService
@inject IGroupService groupService
@{
//page title
ViewBag.Title = Loc["Admin.Dashboard"];
- var isAdminAccess = await groupService.IsAdmin(workContextAccessor.WorkContext.CurrentCustomer);
+ var isAdminAccess = await groupService.IsAdmin(contextAccessor.WorkContext.CurrentCustomer);
var canAccessReports = await permissionService.Authorize(StandardPermission.ManageReports);
var canManageOrders = await permissionService.Authorize(StandardPermission.ManageOrders);
- var customersOnline = (await customerService.GetOnlineCustomers(DateTime.UtcNow.AddMinutes(-customerSettings.OnlineCustomerMinutes), null, workContextAccessor.WorkContext.CurrentCustomer.StaffStoreId, workContextAccessor.WorkContext.CurrentCustomer.SeId, 1, 1)).TotalCount;
- var customersShoppingCart = await customerService.GetCountOnlineShoppingCart(DateTime.UtcNow.AddMinutes(-customerSettings.OnlineShoppingCartMinutes), workContextAccessor.WorkContext.CurrentCustomer.StaffStoreId, workContextAccessor.WorkContext.CurrentCustomer.SeId);
- var ordersToday = await orderReportService.GetOrderPeriodReport(0, workContextAccessor.WorkContext.CurrentCustomer.StaffStoreId, workContextAccessor.WorkContext.CurrentCustomer.SeId);
+ var customersOnline = (await customerService.GetOnlineCustomers(DateTime.UtcNow.AddMinutes(-customerSettings.OnlineCustomerMinutes), null, contextAccessor.WorkContext.CurrentCustomer.StaffStoreId, contextAccessor.WorkContext.CurrentCustomer.SeId, 1, 1)).TotalCount;
+ var customersShoppingCart = await customerService.GetCountOnlineShoppingCart(DateTime.UtcNow.AddMinutes(-customerSettings.OnlineShoppingCartMinutes), contextAccessor.WorkContext.CurrentCustomer.StaffStoreId, contextAccessor.WorkContext.CurrentCustomer.SeId);
+ var ordersToday = await orderReportService.GetOrderPeriodReport(0, contextAccessor.WorkContext.CurrentCustomer.StaffStoreId, contextAccessor.WorkContext.CurrentCustomer.SeId);
var ordersAmount = priceFormatter.FormatPrice(ordersToday.Amount, await currencyService.GetPrimaryStoreCurrency());
}
diff --git a/src/Web/Grand.Web.Admin/Areas/Admin/Views/Shared/Partials/HeadAdmin.cshtml b/src/Web/Grand.Web.Admin/Areas/Admin/Views/Shared/Partials/HeadAdmin.cshtml
index 7d8942c87..d1864e790 100644
--- a/src/Web/Grand.Web.Admin/Areas/Admin/Views/Shared/Partials/HeadAdmin.cshtml
+++ b/src/Web/Grand.Web.Admin/Areas/Admin/Views/Shared/Partials/HeadAdmin.cshtml
@@ -1,13 +1,12 @@
@using Grand.Domain.Localization
@using Constants = Grand.SharedUIResources.Constants
@inject LanguageSettings languageSettings
-@inject IWorkContextAccessor workContextAccessor
+@inject IContextAccessor contextAccessor
<script>
const wwwrootpath = '@(Constants.WwwRoot)';
</script>
@{
- var supportRtl = workContextAccessor.WorkContext.WorkingLanguage.Rtl &&
- !languageSettings.IgnoreRtlPropertyForAdminArea;
+ var supportRtl = contextAccessor.WorkContext.WorkingLanguage.Rtl && !languageSettings.IgnoreRtlPropertyForAdminArea;
var kendoVersion = "2021.3.914";
<link rel="stylesheet" type="text/css" href="@(Constants.WwwRoot)/administration/bootstrap/css/daterangepicker.min.css"/>
diff --git a/src/Web/Grand.Web.Admin/Areas/Admin/Views/Shared/_AdminLayout.cshtml b/src/Web/Grand.Web.Admin/Areas/Admin/Views/Shared/_AdminLayout.cshtml
index 7f0c322a7..bf0cb9a25 100644
--- a/src/Web/Grand.Web.Admin/Areas/Admin/Views/Shared/_AdminLayout.cshtml
+++ b/src/Web/Grand.Web.Admin/Areas/Admin/Views/Shared/_AdminLayout.cshtml
@@ -4,16 +4,16 @@
@using Grand.Domain.Permissions
@using Grand.Domain.Customers
@using Grand.Domain.Localization
-@inject IWorkContextAccessor workContextAccessor
+@inject IContextAccessor contextAccessor
@inject IPermissionService permissionService
@inject CustomerSettings customerSettings
@inject LanguageSettings languageSettings
@inject IGroupService groupService
@{
- var currentCustomer = workContextAccessor.WorkContext.CurrentCustomer;
+ var currentCustomer = contextAccessor.WorkContext.CurrentCustomer;
var usernamesEnabled = customerSettings.UsernamesEnabled;
var currentVersion = GrandVersion.FullVersion;
- var supportRtl = workContextAccessor.WorkContext.WorkingLanguage.Rtl &&
+ var supportRtl = contextAccessor.WorkContext.WorkingLanguage.Rtl &&
!languageSettings.IgnoreRtlPropertyForAdminArea;
//page title
diff --git a/src/Web/Grand.Web.Admin/Areas/Admin/Views/VendorReview/Edit.cshtml b/src/Web/Grand.Web.Admin/Areas/Admin/Views/VendorReview/Edit.cshtml
index cbd713b9e..a806d40aa 100644
--- a/src/Web/Grand.Web.Admin/Areas/Admin/Views/VendorReview/Edit.cshtml
+++ b/src/Web/Grand.Web.Admin/Areas/Admin/Views/VendorReview/Edit.cshtml
@@ -1,5 +1,5 @@
@model VendorReviewModel
-@inject IWorkContextAccessor workContextAccessor
+@inject IContextAccessor contextAccessor
@{
//page title
ViewBag.Title = Loc["Admin.VendorReviews.EditVendorReviewDetails"];
diff --git a/src/Web/Grand.Web.Admin/Areas/Admin/Views/VendorReview/Partials/CreateOrUpdate.cshtml b/src/Web/Grand.Web.Admin/Areas/Admin/Views/VendorReview/Partials/CreateOrUpdate.cshtml
index 41f49b666..cbf22ec91 100644
--- a/src/Web/Grand.Web.Admin/Areas/Admin/Views/VendorReview/Partials/CreateOrUpdate.cshtml
+++ b/src/Web/Grand.Web.Admin/Areas/Admin/Views/VendorReview/Partials/CreateOrUpdate.cshtml
@@ -1,5 +1,5 @@
@model VendorReviewModel
-@inject IWorkContextAccessor workContextAccessor
+@inject IContextAccessor contextAccessor
@Html.ValidationSummary(false)
<input asp-for="Id" type="hidden"/>
<div class="form-horizontal">
diff --git a/src/Web/Grand.Web.Admin/Components/AdminLanguageSelector.cs b/src/Web/Grand.Web.Admin/Components/AdminLanguageSelector.cs
index a4071cda6..222286b3a 100644
--- a/src/Web/Grand.Web.Admin/Components/AdminLanguageSelector.cs
+++ b/src/Web/Grand.Web.Admin/Components/AdminLanguageSelector.cs
@@ -10,24 +10,24 @@ namespace Grand.Web.Admin.Components;
public class AdminLanguageSelectorViewComponent : BaseAdminViewComponent
{
private readonly ILanguageService _languageService;
- private readonly IWorkContextAccessor _workContextAccessor;
+ private readonly IContextAccessor _contextAccessor;
public AdminLanguageSelectorViewComponent(
- IWorkContextAccessor workContextAccessor,
+ IContextAccessor contextAccessor,
ILanguageService languageService)
{
- _workContextAccessor = workContextAccessor;
+ _contextAccessor = contextAccessor;
_languageService = languageService;
}
public async Task<IViewComponentResult> InvokeAsync()
{
var model = new LanguageSelectorModel {
- CurrentLanguage = _workContextAccessor.WorkContext.WorkingLanguage.ToModel(),
+ CurrentLanguage = _contextAccessor.WorkContext.WorkingLanguage.ToModel(),
AvailableLanguages = (await _languageService
.GetAllLanguages(
true,
- _workContextAccessor.WorkContext.CurrentStore.Id))
+ _contextAccessor.StoreContext.CurrentStore.Id))
.Select(x => x.ToModel())
.ToList()
};
diff --git a/src/Web/Grand.Web.Admin/Components/AdminWidget.cs b/src/Web/Grand.Web.Admin/Components/AdminWidget.cs
index 908998531..a8fcafb6d 100644
--- a/src/Web/Grand.Web.Admin/Components/AdminWidget.cs
+++ b/src/Web/Grand.Web.Admin/Components/AdminWidget.cs
@@ -10,10 +10,10 @@ public class AdminWidgetViewComponent : BaseAdminViewComponent
{
#region Constructors
- public AdminWidgetViewComponent(IWidgetService widgetService, IWorkContextAccessor workContextAccessor)
+ public AdminWidgetViewComponent(IWidgetService widgetService, IContextAccessor contextAccessor)
{
_widgetService = widgetService;
- _workContextAccessor = workContextAccessor;
+ _contextAccessor = contextAccessor;
}
#endregion
@@ -24,8 +24,8 @@ public class AdminWidgetViewComponent : BaseAdminViewComponent
{
var model = new List<AdminWidgetModel>();
- var widgets = await _widgetService.LoadActiveWidgetsByWidgetZone(widgetZone, _workContextAccessor.WorkContext.CurrentStore.Id,
- _workContextAccessor.WorkContext.CurrentCustomer);
+ var widgets = await _widgetService.LoadActiveWidgetsByWidgetZone(widgetZone, _contextAccessor.StoreContext.CurrentStore.Id,
+ _contextAccessor.WorkContext.CurrentCustomer);
foreach (var item in widgets)
{
var viewComponentName = await item.GetPublicViewComponentName(widgetZone);
@@ -50,7 +50,7 @@ public class AdminWidgetViewComponent : BaseAdminViewComponent
#region Fields
private readonly IWidgetService _widgetService;
- private readonly IWorkContextAccessor _workContextAccessor;
+ private readonly IContextAccessor _contextAccessor;
#endregion
}
\ No newline at end of file
diff --git a/src/Web/Grand.Web.Admin/Components/LatestOrder.cs b/src/Web/Grand.Web.Admin/Components/LatestOrder.cs
index 33dfca307..71137ef31 100644
--- a/src/Web/Grand.Web.Admin/Components/LatestOrder.cs
+++ b/src/Web/Grand.Web.Admin/Components/LatestOrder.cs
@@ -1,6 +1,5 @@
using Grand.Business.Core.Interfaces.Common.Security;
using Grand.Domain.Permissions;
-using Grand.Infrastructure;
using Grand.Web.Common.Components;
using Microsoft.AspNetCore.Mvc;
@@ -9,12 +8,10 @@ namespace Grand.Web.Admin.Components;
public class LatestOrderViewComponent : BaseAdminViewComponent
{
private readonly IPermissionService _permissionService;
- private readonly IWorkContextAccessor _workContextAccessor;
- public LatestOrderViewComponent(IPermissionService permissionService, IWorkContextAccessor workContextAccessor)
+ public LatestOrderViewComponent(IPermissionService permissionService)
{
_permissionService = permissionService;
- _workContextAccessor = workContextAccessor;
}
public async Task<IViewComponentResult> InvokeAsync()
diff --git a/src/Web/Grand.Web.Admin/Components/StoreScope.cs b/src/Web/Grand.Web.Admin/Components/StoreScope.cs
index 78122f52a..0468e82ef 100644
--- a/src/Web/Grand.Web.Admin/Components/StoreScope.cs
+++ b/src/Web/Grand.Web.Admin/Components/StoreScope.cs
@@ -1,11 +1,9 @@
using Grand.Business.Core.Interfaces.Common.Directory;
using Grand.Business.Core.Interfaces.Common.Stores;
-using Grand.Domain.Common;
-using Grand.Domain.Customers;
-using Grand.Domain.Stores;
using Grand.Infrastructure;
using Grand.Web.Admin.Models.Settings;
using Grand.Web.Common.Components;
+using Grand.Web.Common.Helpers;
using Grand.Web.Common.Models;
using Microsoft.AspNetCore.Mvc;
@@ -13,12 +11,27 @@ namespace Grand.Web.Admin.Components;
public class StoreScopeViewComponent : BaseAdminViewComponent
{
+
+ #region Fields
+
+ private readonly IStoreService _storeService;
+ private readonly IContextAccessor _contextAccessor;
+ private readonly IGroupService _groupService;
+ private readonly IAdminStoreService _adminStoreService;
+
+ #endregion
+
#region Constructors
- public StoreScopeViewComponent(IStoreService storeService, IWorkContextAccessor workContextAccessor, IGroupService groupService)
+ public StoreScopeViewComponent(
+ IStoreService storeService,
+ IAdminStoreService adminStoreService,
+ IGroupService groupService,
+ IContextAccessor contextAccessor)
{
+ _adminStoreService = adminStoreService;
_storeService = storeService;
- _workContextAccessor = workContextAccessor;
+ _contextAccessor = contextAccessor;
_groupService = groupService;
}
@@ -32,8 +45,8 @@ public class StoreScopeViewComponent : BaseAdminViewComponent
if (allStores.Count < 2)
return Content("");
- if (await _groupService.IsStaff(_workContextAccessor.WorkContext.CurrentCustomer))
- allStores = allStores.Where(x => x.Id == _workContextAccessor.WorkContext.CurrentCustomer.StaffStoreId).ToList();
+ if (await _groupService.IsStaff(_contextAccessor.WorkContext.CurrentCustomer))
+ allStores = allStores.Where(x => x.Id == _contextAccessor.WorkContext.CurrentCustomer.StaffStoreId).ToList();
var model = new StoreScopeModel();
foreach (var s in allStores)
@@ -41,35 +54,9 @@ public class StoreScopeViewComponent : BaseAdminViewComponent
Id = s.Id,
Name = s.Shortcut
});
- model.StoreId = await GetActiveStore(allStores);
- return View(model);
- }
-
- #endregion
-
- #region Methods
- private async Task<string> GetActiveStore(ICollection<Store> stores)
- {
- //ensure that we have 2 (or more) stores
- if (stores.Count < 2)
- return stores.FirstOrDefault()!.Id;
-
- var storeId =
- _workContextAccessor.WorkContext.CurrentCustomer.GetUserFieldFromEntity<string>(SystemCustomerFieldNames
- .AdminAreaStoreScopeConfiguration);
- var store = await _storeService.GetStoreById(storeId);
-
- return store != null ? store.Id : "";
+ model.StoreId = await _adminStoreService.GetActiveStore();
+ return View(model);
}
-
- #endregion
-
- #region Fields
-
- private readonly IStoreService _storeService;
- private readonly IWorkContextAccessor _workContextAccessor;
- private readonly IGroupService _groupService;
-
#endregion
}
\ No newline at end of file
diff --git a/src/Web/Grand.Web.Admin/Controllers/BaseAdminController.cs b/src/Web/Grand.Web.Admin/Controllers/BaseAdminController.cs
index adb8eba5c..58512af12 100644
--- a/src/Web/Grand.Web.Admin/Controllers/BaseAdminController.cs
+++ b/src/Web/Grand.Web.Admin/Controllers/BaseAdminController.cs
@@ -55,7 +55,7 @@ public abstract class BaseAdminController : BaseController
protected async Task<string> GetActiveStore()
{
var storeService = HttpContext.RequestServices.GetRequiredService<IStoreService>();
- var workContext = HttpContext.RequestServices.GetRequiredService<IWorkContextAccessor>().WorkContext;
+ var workContext = HttpContext.RequestServices.GetRequiredService<IContextAccessor>().WorkContext;
var groupService = HttpContext.RequestServices.GetRequiredService<IGroupService>();
var stores = await storeService.GetAllStores();
diff --git a/src/Web/Grand.Web.Admin/Controllers/BlogController.cs b/src/Web/Grand.Web.Admin/Controllers/BlogController.cs
index 51ac36ffa..88ff7e391 100644
--- a/src/Web/Grand.Web.Admin/Controllers/BlogController.cs
+++ b/src/Web/Grand.Web.Admin/Controllers/BlogController.cs
@@ -30,7 +30,7 @@ public class BlogController : BaseAdminController
ILanguageService languageService,
ITranslationService translationService,
IStoreService storeService,
- IWorkContextAccessor workContextAccessor,
+ IContextAccessor contextAccessor,
IGroupService groupService,
IDateTimeService dateTimeService,
IPictureViewModelService pictureViewModelService,
@@ -41,7 +41,7 @@ public class BlogController : BaseAdminController
_languageService = languageService;
_translationService = translationService;
_storeService = storeService;
- _workContextAccessor = workContextAccessor;
+ _contextAccessor = contextAccessor;
_groupService = groupService;
_dateTimeService = dateTimeService;
_pictureViewModelService = pictureViewModelService;
@@ -57,7 +57,7 @@ public class BlogController : BaseAdminController
private readonly ILanguageService _languageService;
private readonly ITranslationService _translationService;
private readonly IStoreService _storeService;
- private readonly IWorkContextAccessor _workContextAccessor;
+ private readonly IContextAccessor _contextAccessor;
private readonly IGroupService _groupService;
private readonly IDateTimeService _dateTimeService;
private readonly IPictureViewModelService _pictureViewModelService;
@@ -110,8 +110,8 @@ public class BlogController : BaseAdminController
{
if (ModelState.IsValid)
{
- if (await _groupService.IsStaff(_workContextAccessor.WorkContext.CurrentCustomer))
- model.Stores = [_workContextAccessor.WorkContext.CurrentCustomer.StaffStoreId];
+ if (await _groupService.IsStaff(_contextAccessor.WorkContext.CurrentCustomer))
+ model.Stores = [_contextAccessor.WorkContext.CurrentCustomer.StaffStoreId];
var blogPost = await _blogViewModelService.InsertBlogPostModel(model);
Success(_translationService.GetResource("Admin.Content.Blog.BlogPosts.Added"));
return continueEditing ? RedirectToAction("Edit", new { id = blogPost.Id }) : RedirectToAction("List");
@@ -131,17 +131,17 @@ public class BlogController : BaseAdminController
//No blog post found with the specified id
return RedirectToAction("List");
- if (await _groupService.IsStaff(_workContextAccessor.WorkContext.CurrentCustomer))
+ if (await _groupService.IsStaff(_contextAccessor.WorkContext.CurrentCustomer))
{
if (!blogPost.LimitedToStores || (blogPost.LimitedToStores &&
- blogPost.Stores.Contains(_workContextAccessor.WorkContext.CurrentCustomer.StaffStoreId) &&
+ blogPost.Stores.Contains(_contextAccessor.WorkContext.CurrentCustomer.StaffStoreId) &&
blogPost.Stores.Count > 1))
{
Warning(_translationService.GetResource("Admin.Content.Blog.BlogPosts.Permissions"));
}
else
{
- if (!blogPost.AccessToEntityByStore(_workContextAccessor.WorkContext.CurrentCustomer.StaffStoreId))
+ if (!blogPost.AccessToEntityByStore(_contextAccessor.WorkContext.CurrentCustomer.StaffStoreId))
return RedirectToAction("List");
}
}
@@ -172,14 +172,14 @@ public class BlogController : BaseAdminController
//No blog post found with the specified id
return RedirectToAction("List");
- if (await _groupService.IsStaff(_workContextAccessor.WorkContext.CurrentCustomer))
- if (!blogPost.AccessToEntityByStore(_workContextAccessor.WorkContext.CurrentCustomer.StaffStoreId))
+ if (await _groupService.IsStaff(_contextAccessor.WorkContext.CurrentCustomer))
+ if (!blogPost.AccessToEntityByStore(_contextAccessor.WorkContext.CurrentCustomer.StaffStoreId))
return RedirectToAction("Edit", new { id = blogPost.Id });
if (ModelState.IsValid)
{
- if (await _groupService.IsStaff(_workContextAccessor.WorkContext.CurrentCustomer))
- model.Stores = [_workContextAccessor.WorkContext.CurrentCustomer.StaffStoreId];
+ if (await _groupService.IsStaff(_contextAccessor.WorkContext.CurrentCustomer))
+ model.Stores = [_contextAccessor.WorkContext.CurrentCustomer.StaffStoreId];
blogPost = await _blogViewModelService.UpdateBlogPostModel(model, blogPost);
@@ -221,8 +221,8 @@ public class BlogController : BaseAdminController
//No blog post found with the specified id
return RedirectToAction("List");
- if (await _groupService.IsStaff(_workContextAccessor.WorkContext.CurrentCustomer))
- if (!blogPost.AccessToEntityByStore(_workContextAccessor.WorkContext.CurrentCustomer.StaffStoreId))
+ if (await _groupService.IsStaff(_contextAccessor.WorkContext.CurrentCustomer))
+ if (!blogPost.AccessToEntityByStore(_contextAccessor.WorkContext.CurrentCustomer.StaffStoreId))
return RedirectToAction("Edit", new { id = blogPost.Id });
if (ModelState.IsValid)
@@ -294,7 +294,7 @@ public class BlogController : BaseAdminController
[HttpPost]
public async Task<IActionResult> CategoryList(DataSourceRequest command)
{
- var categories = await _blogService.GetAllBlogCategories(_workContextAccessor.WorkContext.CurrentCustomer.StaffStoreId);
+ var categories = await _blogService.GetAllBlogCategories(_contextAccessor.WorkContext.CurrentCustomer.StaffStoreId);
var gridModel = new DataSourceResult {
Data = categories,
Total = categories.Count
@@ -320,8 +320,8 @@ public class BlogController : BaseAdminController
{
if (ModelState.IsValid)
{
- if (await _groupService.IsStaff(_workContextAccessor.WorkContext.CurrentCustomer))
- model.Stores = [_workContextAccessor.WorkContext.CurrentCustomer.StaffStoreId];
+ if (await _groupService.IsStaff(_contextAccessor.WorkContext.CurrentCustomer))
+ model.Stores = [_contextAccessor.WorkContext.CurrentCustomer.StaffStoreId];
var blogCategory = model.ToEntity();
blogCategory.SeName = SeoExtensions.GetSeName(
@@ -351,18 +351,18 @@ public class BlogController : BaseAdminController
//No blog post found with the specified id
return RedirectToAction("CategoryList");
- if (await _groupService.IsStaff(_workContextAccessor.WorkContext.CurrentCustomer))
+ if (await _groupService.IsStaff(_contextAccessor.WorkContext.CurrentCustomer))
{
if (!blogCategory.LimitedToStores || (blogCategory.LimitedToStores &&
blogCategory.Stores.Contains(
- _workContextAccessor.WorkContext.CurrentCustomer.StaffStoreId) &&
+ _contextAccessor.WorkContext.CurrentCustomer.StaffStoreId) &&
blogCategory.Stores.Count > 1))
{
Warning(_translationService.GetResource("Admin.Content.Blog.BlogCategory.Permissions"));
}
else
{
- if (!blogCategory.AccessToEntityByStore(_workContextAccessor.WorkContext.CurrentCustomer.StaffStoreId))
+ if (!blogCategory.AccessToEntityByStore(_contextAccessor.WorkContext.CurrentCustomer.StaffStoreId))
return RedirectToAction("List");
}
}
@@ -387,14 +387,14 @@ public class BlogController : BaseAdminController
//No blog post found with the specified id
return RedirectToAction("CategoryList");
- if (await _groupService.IsStaff(_workContextAccessor.WorkContext.CurrentCustomer))
- if (!blogCategory.AccessToEntityByStore(_workContextAccessor.WorkContext.CurrentCustomer.StaffStoreId))
+ if (await _groupService.IsStaff(_contextAccessor.WorkContext.CurrentCustomer))
+ if (!blogCategory.AccessToEntityByStore(_contextAccessor.WorkContext.CurrentCustomer.StaffStoreId))
return RedirectToAction("CategoryEdit", new { id = blogCategory.Id });
if (ModelState.IsValid)
{
- if (await _groupService.IsStaff(_workContextAccessor.WorkContext.CurrentCustomer))
- model.Stores = [_workContextAccessor.WorkContext.CurrentCustomer.StaffStoreId];
+ if (await _groupService.IsStaff(_contextAccessor.WorkContext.CurrentCustomer))
+ model.Stores = [_contextAccessor.WorkContext.CurrentCustomer.StaffStoreId];
blogCategory = model.ToEntity(blogCategory);
blogCategory.SeName = SeoExtensions.GetSeName(
@@ -435,8 +435,8 @@ public class BlogController : BaseAdminController
//No blog post found with the specified id
return RedirectToAction("CategoryList");
- if (await _groupService.IsStaff(_workContextAccessor.WorkContext.CurrentCustomer))
- if (!blogcategory.AccessToEntityByStore(_workContextAccessor.WorkContext.CurrentCustomer.StaffStoreId))
+ if (await _groupService.IsStaff(_contextAccessor.WorkContext.CurrentCustomer))
+ if (!blogcategory.AccessToEntityByStore(_contextAccessor.WorkContext.CurrentCustomer.StaffStoreId))
return RedirectToAction("CategoryEdit", new { id = blogcategory.Id });
if (ModelState.IsValid)
@@ -487,8 +487,8 @@ public class BlogController : BaseAdminController
if (blogCategory == null)
return ErrorForKendoGridJson("blogCategory no exists");
- if (await _groupService.IsStaff(_workContextAccessor.WorkContext.CurrentCustomer))
- if (!blogCategory.AccessToEntityByStore(_workContextAccessor.WorkContext.CurrentCustomer.StaffStoreId))
+ if (await _groupService.IsStaff(_contextAccessor.WorkContext.CurrentCustomer))
+ if (!blogCategory.AccessToEntityByStore(_contextAccessor.WorkContext.CurrentCustomer.StaffStoreId))
return ErrorForKendoGridJson("blogCategory no permission");
if (ModelState.IsValid)
@@ -511,7 +511,7 @@ public class BlogController : BaseAdminController
{
var model = new AddBlogPostCategoryModel();
//stores
- var storeId = _workContextAccessor.WorkContext.CurrentCustomer.StaffStoreId;
+ var storeId = _contextAccessor.WorkContext.CurrentCustomer.StaffStoreId;
model.AvailableStores.Add(new SelectListItem
{ Text = _translationService.GetResource("Admin.Common.All"), Value = " " });
@@ -528,8 +528,8 @@ public class BlogController : BaseAdminController
{
var gridModel = new DataSourceResult();
- if (await _groupService.IsStaff(_workContextAccessor.WorkContext.CurrentCustomer))
- model.SearchStoreId = _workContextAccessor.WorkContext.CurrentCustomer.StaffStoreId;
+ if (await _groupService.IsStaff(_contextAccessor.WorkContext.CurrentCustomer))
+ model.SearchStoreId = _contextAccessor.WorkContext.CurrentCustomer.StaffStoreId;
var posts = await _blogService.GetAllBlogPosts(model.SearchStoreId, blogPostName: model.SearchBlogTitle,
pageIndex: command.Page - 1, pageSize: command.PageSize);
@@ -593,8 +593,8 @@ public class BlogController : BaseAdminController
throw new ArgumentException("No comment found with the specified id");
var blogPost = await _blogService.GetBlogPostById(comment.BlogPostId);
- if (await _groupService.IsStaff(_workContextAccessor.WorkContext.CurrentCustomer))
- if (!blogPost.AccessToEntityByStore(_workContextAccessor.WorkContext.CurrentCustomer.StaffStoreId))
+ if (await _groupService.IsStaff(_contextAccessor.WorkContext.CurrentCustomer))
+ if (!blogPost.AccessToEntityByStore(_contextAccessor.WorkContext.CurrentCustomer.StaffStoreId))
return ErrorForKendoGridJson("blogPost no permission");
if (ModelState.IsValid)
diff --git a/src/Web/Grand.Web.Admin/Controllers/BrandController.cs b/src/Web/Grand.Web.Admin/Controllers/BrandController.cs
index 0a3272add..a857a8eb3 100644
--- a/src/Web/Grand.Web.Admin/Controllers/BrandController.cs
+++ b/src/Web/Grand.Web.Admin/Controllers/BrandController.cs
@@ -30,7 +30,7 @@ public class BrandController : BaseAdminController
public BrandController(
IBrandViewModelService brandViewModelService,
IBrandService brandService,
- IWorkContextAccessor workContextAccessor,
+ IContextAccessor contextAccessor,
IStoreService storeService,
ILanguageService languageService,
ITranslationService translationService,
@@ -39,7 +39,7 @@ public class BrandController : BaseAdminController
{
_brandViewModelService = brandViewModelService;
_brandService = brandService;
- _workContextAccessor = workContextAccessor;
+ _contextAccessor = contextAccessor;
_storeService = storeService;
_languageService = languageService;
_translationService = translationService;
@@ -54,8 +54,8 @@ public class BrandController : BaseAdminController
protected async Task<(bool allow, string message)> CheckAccessToBrand(Brand brand)
{
if (brand == null) return (false, "Brand not exists");
- if (await _groupService.IsStaff(_workContextAccessor.WorkContext.CurrentCustomer))
- if (!(!brand.LimitedToStores || (brand.Stores.Contains(_workContextAccessor.WorkContext.CurrentCustomer.StaffStoreId) &&
+ if (await _groupService.IsStaff(_contextAccessor.WorkContext.CurrentCustomer))
+ if (!(!brand.LimitedToStores || (brand.Stores.Contains(_contextAccessor.WorkContext.CurrentCustomer.StaffStoreId) &&
brand.LimitedToStores)))
return (false, "This is not your collection");
return (true, null);
@@ -67,7 +67,7 @@ public class BrandController : BaseAdminController
private readonly IBrandViewModelService _brandViewModelService;
private readonly IBrandService _brandService;
- private readonly IWorkContextAccessor _workContextAccessor;
+ private readonly IContextAccessor _contextAccessor;
private readonly IStoreService _storeService;
private readonly ILanguageService _languageService;
private readonly ITranslationService _translationService;
@@ -85,7 +85,7 @@ public class BrandController : BaseAdminController
public async Task<IActionResult> List()
{
- var storeId = _workContextAccessor.WorkContext.CurrentCustomer.StaffStoreId;
+ var storeId = _contextAccessor.WorkContext.CurrentCustomer.StaffStoreId;
var model = new BrandListModel();
model.AvailableStores.Add(new SelectListItem
{ Text = _translationService.GetResource("Admin.Common.All"), Value = "" });
@@ -100,8 +100,8 @@ public class BrandController : BaseAdminController
[HttpPost]
public async Task<IActionResult> List(DataSourceRequest command, BrandListModel model)
{
- if (await _groupService.IsStaff(_workContextAccessor.WorkContext.CurrentCustomer))
- model.SearchStoreId = _workContextAccessor.WorkContext.CurrentCustomer.StaffStoreId;
+ if (await _groupService.IsStaff(_contextAccessor.WorkContext.CurrentCustomer))
+ model.SearchStoreId = _contextAccessor.WorkContext.CurrentCustomer.StaffStoreId;
var brands = await _brandService.GetAllBrands(model.SearchBrandName,
model.SearchStoreId, command.Page - 1, command.PageSize, true);
var gridModel = new DataSourceResult {
@@ -144,8 +144,8 @@ public class BrandController : BaseAdminController
{
if (ModelState.IsValid)
{
- if (await _groupService.IsStaff(_workContextAccessor.WorkContext.CurrentCustomer))
- model.Stores = [_workContextAccessor.WorkContext.CurrentCustomer.StaffStoreId];
+ if (await _groupService.IsStaff(_contextAccessor.WorkContext.CurrentCustomer))
+ model.Stores = [_contextAccessor.WorkContext.CurrentCustomer.StaffStoreId];
var collection = await _brandViewModelService.InsertBrandModel(model);
Success(_translationService.GetResource("Admin.Catalog.Brands.Added"));
@@ -171,17 +171,17 @@ public class BrandController : BaseAdminController
//No collection found with the specified id
return RedirectToAction("List");
- if (await _groupService.IsStaff(_workContextAccessor.WorkContext.CurrentCustomer))
+ if (await _groupService.IsStaff(_contextAccessor.WorkContext.CurrentCustomer))
{
if (!brand.LimitedToStores || (brand.LimitedToStores &&
- brand.Stores.Contains(_workContextAccessor.WorkContext.CurrentCustomer.StaffStoreId) &&
+ brand.Stores.Contains(_contextAccessor.WorkContext.CurrentCustomer.StaffStoreId) &&
brand.Stores.Count > 1))
{
Warning(_translationService.GetResource("Admin.Catalog.Brands.Permissions"));
}
else
{
- if (!brand.AccessToEntityByStore(_workContextAccessor.WorkContext.CurrentCustomer.StaffStoreId))
+ if (!brand.AccessToEntityByStore(_contextAccessor.WorkContext.CurrentCustomer.StaffStoreId))
return RedirectToAction("List");
}
}
@@ -218,13 +218,13 @@ public class BrandController : BaseAdminController
//No collection found with the specified id
return RedirectToAction("List");
- if (await _groupService.IsStaff(_workContextAccessor.WorkContext.CurrentCustomer))
- if (!brand.AccessToEntityByStore(_workContextAccessor.WorkContext.CurrentCustomer.StaffStoreId))
+ if (await _groupService.IsStaff(_contextAccessor.WorkContext.CurrentCustomer))
+ if (!brand.AccessToEntityByStore(_contextAccessor.WorkContext.CurrentCustomer.StaffStoreId))
return RedirectToAction("Edit", new { id = brand.Id });
if (ModelState.IsValid)
{
- if (await _groupService.IsStaff(_workContextAccessor.WorkContext.CurrentCustomer))
- model.Stores = [_workContextAccessor.WorkContext.CurrentCustomer.StaffStoreId];
+ if (await _groupService.IsStaff(_contextAccessor.WorkContext.CurrentCustomer))
+ model.Stores = [_contextAccessor.WorkContext.CurrentCustomer.StaffStoreId];
brand = await _brandViewModelService.UpdateBrandModel(brand, model);
Success(_translationService.GetResource("Admin.Catalog.Brands.Updated"));
@@ -260,8 +260,8 @@ public class BrandController : BaseAdminController
//No collection found with the specified id
return RedirectToAction("List");
- if (await _groupService.IsStaff(_workContextAccessor.WorkContext.CurrentCustomer))
- if (!brand.AccessToEntityByStore(_workContextAccessor.WorkContext.CurrentCustomer.StaffStoreId))
+ if (await _groupService.IsStaff(_contextAccessor.WorkContext.CurrentCustomer))
+ if (!brand.AccessToEntityByStore(_contextAccessor.WorkContext.CurrentCustomer.StaffStoreId))
return RedirectToAction("Edit", new { id = brand.Id });
if (ModelState.IsValid)
@@ -338,7 +338,7 @@ public class BrandController : BaseAdminController
try
{
var bytes = await exportManager.Export(await _brandService.GetAllBrands(showHidden: true,
- storeId: _workContextAccessor.WorkContext.CurrentCustomer.StaffStoreId));
+ storeId: _contextAccessor.WorkContext.CurrentCustomer.StaffStoreId));
return File(bytes, "text/xls", "brands.xlsx");
}
catch (Exception exc)
diff --git a/src/Web/Grand.Web.Admin/Controllers/CampaignController.cs b/src/Web/Grand.Web.Admin/Controllers/CampaignController.cs
index 3bd80afb8..4058c1d04 100644
--- a/src/Web/Grand.Web.Admin/Controllers/CampaignController.cs
+++ b/src/Web/Grand.Web.Admin/Controllers/CampaignController.cs
@@ -27,13 +27,13 @@ public class CampaignController : BaseAdminController
private readonly INewsLetterSubscriptionService _newsLetterSubscriptionService;
private readonly IStoreService _storeService;
private readonly ITranslationService _translationService;
- private readonly IWorkContextAccessor _workContextAccessor;
+ private readonly IContextAccessor _contextAccessor;
public CampaignController(ICampaignService campaignService, ICampaignViewModelService campaignViewModelService,
IEmailAccountService emailAccountService,
INewsLetterSubscriptionService newsLetterSubscriptionService,
ITranslationService translationService,
- IWorkContextAccessor workContextAccessor,
+ IContextAccessor contextAccessor,
IStoreService storeService,
EmailAccountSettings emailAccountSettings)
{
@@ -43,7 +43,7 @@ public class CampaignController : BaseAdminController
_emailAccountSettings = emailAccountSettings;
_newsLetterSubscriptionService = newsLetterSubscriptionService;
_translationService = translationService;
- _workContextAccessor = workContextAccessor;
+ _contextAccessor = contextAccessor;
_storeService = storeService;
}
@@ -206,7 +206,7 @@ public class CampaignController : BaseAdminController
var subscription =
await _newsLetterSubscriptionService.GetNewsLetterSubscriptionByEmailAndStoreId(model.TestEmail,
- _workContextAccessor.WorkContext.CurrentStore.Id);
+ _contextAccessor.StoreContext.CurrentStore.Id);
if (subscription != null)
{
//there's a subscription. use it
diff --git a/src/Web/Grand.Web.Admin/Controllers/CategoryController.cs b/src/Web/Grand.Web.Admin/Controllers/CategoryController.cs
index 337673ea7..c3b468a15 100644
--- a/src/Web/Grand.Web.Admin/Controllers/CategoryController.cs
+++ b/src/Web/Grand.Web.Admin/Controllers/CategoryController.cs
@@ -30,7 +30,7 @@ public class CategoryController : BaseAdminController
ICategoryViewModelService categoryViewModelService,
ILanguageService languageService,
ITranslationService translationService,
- IWorkContextAccessor workContextAccessor,
+ IContextAccessor contextAccessor,
IGroupService groupService,
IPictureViewModelService pictureViewModelService)
{
@@ -38,7 +38,7 @@ public class CategoryController : BaseAdminController
_categoryViewModelService = categoryViewModelService;
_languageService = languageService;
_translationService = translationService;
- _workContextAccessor = workContextAccessor;
+ _contextAccessor = contextAccessor;
_groupService = groupService;
_pictureViewModelService = pictureViewModelService;
}
@@ -50,8 +50,8 @@ public class CategoryController : BaseAdminController
protected async Task<(bool allow, string message)> CheckAccessToCategory(Category category)
{
if (category == null) return (false, "Category not exists");
- if (await _groupService.IsStaff(_workContextAccessor.WorkContext.CurrentCustomer))
- if (!(!category.LimitedToStores || (category.Stores.Contains(_workContextAccessor.WorkContext.CurrentCustomer.StaffStoreId) &&
+ if (await _groupService.IsStaff(_contextAccessor.WorkContext.CurrentCustomer))
+ if (!(!category.LimitedToStores || (category.Stores.Contains(_contextAccessor.WorkContext.CurrentCustomer.StaffStoreId) &&
category.LimitedToStores)))
return (false, "This is not your category");
return (true, null);
@@ -65,7 +65,7 @@ public class CategoryController : BaseAdminController
private readonly ICategoryViewModelService _categoryViewModelService;
private readonly ILanguageService _languageService;
private readonly ITranslationService _translationService;
- private readonly IWorkContextAccessor _workContextAccessor;
+ private readonly IContextAccessor _contextAccessor;
private readonly IGroupService _groupService;
private readonly IPictureViewModelService _pictureViewModelService;
@@ -80,7 +80,7 @@ public class CategoryController : BaseAdminController
public async Task<IActionResult> List()
{
- var model = await _categoryViewModelService.PrepareCategoryListModel(_workContextAccessor.WorkContext.CurrentCustomer.StaffStoreId);
+ var model = await _categoryViewModelService.PrepareCategoryListModel(_contextAccessor.WorkContext.CurrentCustomer.StaffStoreId);
return View(model);
}
@@ -88,8 +88,8 @@ public class CategoryController : BaseAdminController
[HttpPost]
public async Task<IActionResult> List(DataSourceRequest command, CategoryListModel model)
{
- if (await _groupService.IsStaff(_workContextAccessor.WorkContext.CurrentCustomer))
- model.SearchStoreId = _workContextAccessor.WorkContext.CurrentCustomer.StaffStoreId;
+ if (await _groupService.IsStaff(_contextAccessor.WorkContext.CurrentCustomer))
+ model.SearchStoreId = _contextAccessor.WorkContext.CurrentCustomer.StaffStoreId;
var categories =
await _categoryViewModelService.PrepareCategoryListModel(model, command.Page, command.PageSize);
@@ -107,7 +107,7 @@ public class CategoryController : BaseAdminController
[PermissionAuthorizeAction(PermissionActionName.Create)]
public async Task<IActionResult> Create()
{
- var model = await _categoryViewModelService.PrepareCategoryModel(_workContextAccessor.WorkContext.CurrentCustomer.StaffStoreId);
+ var model = await _categoryViewModelService.PrepareCategoryModel(_contextAccessor.WorkContext.CurrentCustomer.StaffStoreId);
//locales
await AddLocales(_languageService, model.Locales);
@@ -121,8 +121,8 @@ public class CategoryController : BaseAdminController
{
if (ModelState.IsValid)
{
- if (await _groupService.IsStaff(_workContextAccessor.WorkContext.CurrentCustomer))
- model.Stores = [_workContextAccessor.WorkContext.CurrentCustomer.StaffStoreId];
+ if (await _groupService.IsStaff(_contextAccessor.WorkContext.CurrentCustomer))
+ model.Stores = [_contextAccessor.WorkContext.CurrentCustomer.StaffStoreId];
var category = await _categoryViewModelService.InsertCategoryModel(model);
Success(_translationService.GetResource("Admin.Catalog.Categories.Added"));
@@ -131,7 +131,7 @@ public class CategoryController : BaseAdminController
//If we got this far, something failed, redisplay form
model = await _categoryViewModelService.PrepareCategoryModel(model, null,
- _workContextAccessor.WorkContext.CurrentCustomer.StaffStoreId);
+ _contextAccessor.WorkContext.CurrentCustomer.StaffStoreId);
return View(model);
}
@@ -144,17 +144,17 @@ public class CategoryController : BaseAdminController
//No category found with the specified id
return RedirectToAction("List");
- if (await _groupService.IsStaff(_workContextAccessor.WorkContext.CurrentCustomer))
+ if (await _groupService.IsStaff(_contextAccessor.WorkContext.CurrentCustomer))
{
if (!category.LimitedToStores || (category.LimitedToStores &&
- category.Stores.Contains(_workContextAccessor.WorkContext.CurrentCustomer.StaffStoreId) &&
+ category.Stores.Contains(_contextAccessor.WorkContext.CurrentCustomer.StaffStoreId) &&
category.Stores.Count > 1))
{
Warning(_translationService.GetResource("Admin.Catalog.Categories.Permissions"));
}
else
{
- if (!category.AccessToEntityByStore(_workContextAccessor.WorkContext.CurrentCustomer.StaffStoreId))
+ if (!category.AccessToEntityByStore(_contextAccessor.WorkContext.CurrentCustomer.StaffStoreId))
return RedirectToAction("List");
}
}
@@ -173,7 +173,7 @@ public class CategoryController : BaseAdminController
locale.Flag = category.GetTranslation(x => x.Flag, languageId, false);
});
model = await _categoryViewModelService.PrepareCategoryModel(model, category,
- _workContextAccessor.WorkContext.CurrentCustomer.StaffStoreId);
+ _contextAccessor.WorkContext.CurrentCustomer.StaffStoreId);
return View(model);
}
@@ -188,14 +188,14 @@ public class CategoryController : BaseAdminController
//No category found with the specified id
return RedirectToAction("List");
- if (await _groupService.IsStaff(_workContextAccessor.WorkContext.CurrentCustomer))
- if (!category.AccessToEntityByStore(_workContextAccessor.WorkContext.CurrentCustomer.StaffStoreId))
+ if (await _groupService.IsStaff(_contextAccessor.WorkContext.CurrentCustomer))
+ if (!category.AccessToEntityByStore(_contextAccessor.WorkContext.CurrentCustomer.StaffStoreId))
return RedirectToAction("Edit", new { id = category.Id });
if (ModelState.IsValid)
{
- if (await _groupService.IsStaff(_workContextAccessor.WorkContext.CurrentCustomer))
- model.Stores = [_workContextAccessor.WorkContext.CurrentCustomer.StaffStoreId];
+ if (await _groupService.IsStaff(_contextAccessor.WorkContext.CurrentCustomer))
+ model.Stores = [_contextAccessor.WorkContext.CurrentCustomer.StaffStoreId];
category = await _categoryViewModelService.UpdateCategoryModel(category, model);
@@ -213,7 +213,7 @@ public class CategoryController : BaseAdminController
//If we got this far, something failed, redisplay form
model = await _categoryViewModelService.PrepareCategoryModel(model, category,
- _workContextAccessor.WorkContext.CurrentCustomer.StaffStoreId);
+ _contextAccessor.WorkContext.CurrentCustomer.StaffStoreId);
return View(model);
}
@@ -227,8 +227,8 @@ public class CategoryController : BaseAdminController
//No category found with the specified id
return RedirectToAction("List");
- if (await _groupService.IsStaff(_workContextAccessor.WorkContext.CurrentCustomer))
- if (!category.AccessToEntityByStore(_workContextAccessor.WorkContext.CurrentCustomer.StaffStoreId))
+ if (await _groupService.IsStaff(_contextAccessor.WorkContext.CurrentCustomer))
+ if (!category.AccessToEntityByStore(_contextAccessor.WorkContext.CurrentCustomer.StaffStoreId))
return RedirectToAction("Edit", new { id = category.Id });
if (ModelState.IsValid)
@@ -298,7 +298,7 @@ public class CategoryController : BaseAdminController
try
{
var bytes = await exportManager.Export(await _categoryService.GetAllCategories(showHidden: true,
- storeId: _workContextAccessor.WorkContext.CurrentCustomer.StaffStoreId));
+ storeId: _contextAccessor.WorkContext.CurrentCustomer.StaffStoreId));
return File(bytes, "text/xls", "categories.xlsx");
}
catch (Exception exc)
@@ -385,7 +385,7 @@ public class CategoryController : BaseAdminController
[PermissionAuthorizeAction(PermissionActionName.Edit)]
public async Task<IActionResult> ProductAddPopup(string categoryId)
{
- var model = await _categoryViewModelService.PrepareAddCategoryProductModel(_workContextAccessor.WorkContext.CurrentCustomer
+ var model = await _categoryViewModelService.PrepareAddCategoryProductModel(_contextAccessor.WorkContext.CurrentCustomer
.StaffStoreId);
model.CategoryId = categoryId;
return View(model);
@@ -397,8 +397,8 @@ public class CategoryController : BaseAdminController
CategoryModel.AddCategoryProductModel model)
{
var gridModel = new DataSourceResult();
- if (await _groupService.IsStaff(_workContextAccessor.WorkContext.CurrentCustomer))
- model.SearchStoreId = _workContextAccessor.WorkContext.CurrentCustomer.StaffStoreId;
+ if (await _groupService.IsStaff(_contextAccessor.WorkContext.CurrentCustomer))
+ model.SearchStoreId = _contextAccessor.WorkContext.CurrentCustomer.StaffStoreId;
var products = await _categoryViewModelService.PrepareProductModel(model, command.Page, command.PageSize);
gridModel.Data = products.products.ToList();
gridModel.Total = products.totalCount;
diff --git a/src/Web/Grand.Web.Admin/Controllers/CollectionController.cs b/src/Web/Grand.Web.Admin/Controllers/CollectionController.cs
index 72962d428..9ec5a45aa 100644
--- a/src/Web/Grand.Web.Admin/Controllers/CollectionController.cs
+++ b/src/Web/Grand.Web.Admin/Controllers/CollectionController.cs
@@ -30,7 +30,7 @@ public class CollectionController : BaseAdminController
public CollectionController(
ICollectionViewModelService collectionViewModelService,
ICollectionService collectionService,
- IWorkContextAccessor workContextAccessor,
+ IContextAccessor contextAccessor,
IStoreService storeService,
ILanguageService languageService,
ITranslationService translationService,
@@ -39,7 +39,7 @@ public class CollectionController : BaseAdminController
{
_collectionViewModelService = collectionViewModelService;
_collectionService = collectionService;
- _workContextAccessor = workContextAccessor;
+ _contextAccessor = contextAccessor;
_storeService = storeService;
_languageService = languageService;
_translationService = translationService;
@@ -54,9 +54,9 @@ public class CollectionController : BaseAdminController
protected async Task<(bool allow, string message)> CheckAccessToCollection(Collection collection)
{
if (collection == null) return (false, "Collection not exists");
- if (await _groupService.IsStaff(_workContextAccessor.WorkContext.CurrentCustomer))
+ if (await _groupService.IsStaff(_contextAccessor.WorkContext.CurrentCustomer))
if (!(!collection.LimitedToStores ||
- (collection.Stores.Contains(_workContextAccessor.WorkContext.CurrentCustomer.StaffStoreId) &&
+ (collection.Stores.Contains(_contextAccessor.WorkContext.CurrentCustomer.StaffStoreId) &&
collection.LimitedToStores)))
return (false, "This is not your collection");
return (true, null);
@@ -68,7 +68,7 @@ public class CollectionController : BaseAdminController
private readonly ICollectionViewModelService _collectionViewModelService;
private readonly ICollectionService _collectionService;
- private readonly IWorkContextAccessor _workContextAccessor;
+ private readonly IContextAccessor _contextAccessor;
private readonly IStoreService _storeService;
private readonly ILanguageService _languageService;
private readonly ITranslationService _translationService;
@@ -86,7 +86,7 @@ public class CollectionController : BaseAdminController
public async Task<IActionResult> List()
{
- var storeId = _workContextAccessor.WorkContext.CurrentCustomer.StaffStoreId;
+ var storeId = _contextAccessor.WorkContext.CurrentCustomer.StaffStoreId;
var model = new CollectionListModel();
model.AvailableStores.Add(new SelectListItem
{ Text = _translationService.GetResource("Admin.Common.All"), Value = "" });
@@ -101,8 +101,8 @@ public class CollectionController : BaseAdminController
[HttpPost]
public async Task<IActionResult> List(DataSourceRequest command, CollectionListModel model)
{
- if (await _groupService.IsStaff(_workContextAccessor.WorkContext.CurrentCustomer))
- model.SearchStoreId = _workContextAccessor.WorkContext.CurrentCustomer.StaffStoreId;
+ if (await _groupService.IsStaff(_contextAccessor.WorkContext.CurrentCustomer))
+ model.SearchStoreId = _contextAccessor.WorkContext.CurrentCustomer.StaffStoreId;
var collections = await _collectionService.GetAllCollections(model.SearchCollectionName,
model.SearchStoreId, command.Page - 1, command.PageSize, true);
var gridModel = new DataSourceResult {
@@ -145,8 +145,8 @@ public class CollectionController : BaseAdminController
{
if (ModelState.IsValid)
{
- if (await _groupService.IsStaff(_workContextAccessor.WorkContext.CurrentCustomer))
- model.Stores = [_workContextAccessor.WorkContext.CurrentCustomer.StaffStoreId];
+ if (await _groupService.IsStaff(_contextAccessor.WorkContext.CurrentCustomer))
+ model.Stores = [_contextAccessor.WorkContext.CurrentCustomer.StaffStoreId];
var collection = await _collectionViewModelService.InsertCollectionModel(model);
Success(_translationService.GetResource("Admin.Catalog.Collections.Added"));
@@ -172,17 +172,17 @@ public class CollectionController : BaseAdminController
//No collection found with the specified id
return RedirectToAction("List");
- if (await _groupService.IsStaff(_workContextAccessor.WorkContext.CurrentCustomer))
+ if (await _groupService.IsStaff(_contextAccessor.WorkContext.CurrentCustomer))
{
if (!collection.LimitedToStores || (collection.LimitedToStores &&
- collection.Stores.Contains(_workContextAccessor.WorkContext.CurrentCustomer.StaffStoreId) &&
+ collection.Stores.Contains(_contextAccessor.WorkContext.CurrentCustomer.StaffStoreId) &&
collection.Stores.Count > 1))
{
Warning(_translationService.GetResource("Admin.Catalog.Collections.Permissions"));
}
else
{
- if (!collection.AccessToEntityByStore(_workContextAccessor.WorkContext.CurrentCustomer.StaffStoreId))
+ if (!collection.AccessToEntityByStore(_contextAccessor.WorkContext.CurrentCustomer.StaffStoreId))
return RedirectToAction("List");
}
}
@@ -219,13 +219,13 @@ public class CollectionController : BaseAdminController
//No collection found with the specified id
return RedirectToAction("List");
- if (await _groupService.IsStaff(_workContextAccessor.WorkContext.CurrentCustomer))
- if (!collection.AccessToEntityByStore(_workContextAccessor.WorkContext.CurrentCustomer.StaffStoreId))
+ if (await _groupService.IsStaff(_contextAccessor.WorkContext.CurrentCustomer))
+ if (!collection.AccessToEntityByStore(_contextAccessor.WorkContext.CurrentCustomer.StaffStoreId))
return RedirectToAction("Edit", new { id = collection.Id });
if (ModelState.IsValid)
{
- if (await _groupService.IsStaff(_workContextAccessor.WorkContext.CurrentCustomer))
- model.Stores = [_workContextAccessor.WorkContext.CurrentCustomer.StaffStoreId];
+ if (await _groupService.IsStaff(_contextAccessor.WorkContext.CurrentCustomer))
+ model.Stores = [_contextAccessor.WorkContext.CurrentCustomer.StaffStoreId];
collection = await _collectionViewModelService.UpdateCollectionModel(collection, model);
Success(_translationService.GetResource("Admin.Catalog.Collections.Updated"));
@@ -261,8 +261,8 @@ public class CollectionController : BaseAdminController
//No collection found with the specified id
return RedirectToAction("List");
- if (await _groupService.IsStaff(_workContextAccessor.WorkContext.CurrentCustomer))
- if (!collection.AccessToEntityByStore(_workContextAccessor.WorkContext.CurrentCustomer.StaffStoreId))
+ if (await _groupService.IsStaff(_contextAccessor.WorkContext.CurrentCustomer))
+ if (!collection.AccessToEntityByStore(_contextAccessor.WorkContext.CurrentCustomer.StaffStoreId))
return RedirectToAction("Edit", new { id = collection.Id });
if (ModelState.IsValid)
@@ -339,7 +339,7 @@ public class CollectionController : BaseAdminController
try
{
var bytes = await exportManager.Export(await _collectionService.GetAllCollections(showHidden: true,
- storeId: _workContextAccessor.WorkContext.CurrentCustomer.StaffStoreId));
+ storeId: _contextAccessor.WorkContext.CurrentCustomer.StaffStoreId));
return File(bytes, "text/xls", "collections.xlsx");
}
catch (Exception exc)
@@ -390,7 +390,7 @@ public class CollectionController : BaseAdminController
return ErrorForKendoGridJson(permission.message);
var (collectionProductModels, totalCount) =
- await _collectionViewModelService.PrepareCollectionProductModel(collectionId, _workContextAccessor.WorkContext.CurrentStore.Id,
+ await _collectionViewModelService.PrepareCollectionProductModel(collectionId, _contextAccessor.StoreContext.CurrentStore.Id,
command.Page, command.PageSize);
var gridModel = new DataSourceResult {
@@ -429,7 +429,7 @@ public class CollectionController : BaseAdminController
[PermissionAuthorizeAction(PermissionActionName.Edit)]
public async Task<IActionResult> ProductAddPopup(string collectionId)
{
- var model = await _collectionViewModelService.PrepareAddCollectionProductModel(_workContextAccessor.WorkContext.CurrentCustomer
+ var model = await _collectionViewModelService.PrepareAddCollectionProductModel(_contextAccessor.WorkContext.CurrentCustomer
.StaffStoreId);
model.CollectionId = collectionId;
return View(model);
@@ -440,8 +440,8 @@ public class CollectionController : BaseAdminController
public async Task<IActionResult> ProductAddPopupList(DataSourceRequest command,
CollectionModel.AddCollectionProductModel model)
{
- if (await _groupService.IsStaff(_workContextAccessor.WorkContext.CurrentCustomer))
- model.SearchStoreId = _workContextAccessor.WorkContext.CurrentCustomer.StaffStoreId;
+ if (await _groupService.IsStaff(_contextAccessor.WorkContext.CurrentCustomer))
+ model.SearchStoreId = _contextAccessor.WorkContext.CurrentCustomer.StaffStoreId;
var products = await _collectionViewModelService.PrepareProductModel(model, command.Page, command.PageSize);
var gridModel = new DataSourceResult {
Data = products.products.ToList(),
diff --git a/src/Web/Grand.Web.Admin/Controllers/CourseController.cs b/src/Web/Grand.Web.Admin/Controllers/CourseController.cs
index e0640ae01..f2f4d262f 100644
--- a/src/Web/Grand.Web.Admin/Controllers/CourseController.cs
+++ b/src/Web/Grand.Web.Admin/Controllers/CourseController.cs
@@ -30,7 +30,7 @@ public class CourseController : BaseAdminController
private readonly ILanguageService _languageService;
private readonly ITranslationService _translationService;
- private readonly IWorkContextAccessor _workContextAccessor;
+ private readonly IContextAccessor _contextAccessor;
public CourseController(
ITranslationService translationService,
@@ -39,7 +39,7 @@ public class CourseController : BaseAdminController
ICourseSubjectService courseSubjectService,
ICourseLessonService courseLessonService,
ICourseViewModelService courseViewModelService,
- IWorkContextAccessor workContextAccessor,
+ IContextAccessor contextAccessor,
ILanguageService languageService,
IGroupService groupService)
{
@@ -49,7 +49,7 @@ public class CourseController : BaseAdminController
_courseSubjectService = courseSubjectService;
_courseLessonService = courseLessonService;
_courseViewModelService = courseViewModelService;
- _workContextAccessor = workContextAccessor;
+ _contextAccessor = contextAccessor;
_languageService = languageService;
_groupService = groupService;
}
@@ -154,8 +154,8 @@ public class CourseController : BaseAdminController
{
if (ModelState.IsValid)
{
- if (await _groupService.IsStaff(_workContextAccessor.WorkContext.CurrentCustomer))
- model.Stores = [_workContextAccessor.WorkContext.CurrentCustomer.StaffStoreId];
+ if (await _groupService.IsStaff(_contextAccessor.WorkContext.CurrentCustomer))
+ model.Stores = [_contextAccessor.WorkContext.CurrentCustomer.StaffStoreId];
var course = await _courseViewModelService.InsertCourseModel(model);
Success(_translationService.GetResource("Admin.Courses.Course.Added"));
@@ -176,17 +176,17 @@ public class CourseController : BaseAdminController
//No course found with the specified id
return RedirectToAction("List");
- if (await _groupService.IsStaff(_workContextAccessor.WorkContext.CurrentCustomer))
+ if (await _groupService.IsStaff(_contextAccessor.WorkContext.CurrentCustomer))
{
if (!course.LimitedToStores || (course.LimitedToStores &&
- course.Stores.Contains(_workContextAccessor.WorkContext.CurrentCustomer.StaffStoreId) &&
+ course.Stores.Contains(_contextAccessor.WorkContext.CurrentCustomer.StaffStoreId) &&
course.Stores.Count > 1))
{
Warning(_translationService.GetResource("Admin.Courses.Course.Permissions"));
}
else
{
- if (!course.AccessToEntityByStore(_workContextAccessor.WorkContext.CurrentCustomer.StaffStoreId))
+ if (!course.AccessToEntityByStore(_contextAccessor.WorkContext.CurrentCustomer.StaffStoreId))
return RedirectToAction("List");
}
}
@@ -219,14 +219,14 @@ public class CourseController : BaseAdminController
//No course found with the specified id
return RedirectToAction("List");
- if (await _groupService.IsStaff(_workContextAccessor.WorkContext.CurrentCustomer))
- if (!course.AccessToEntityByStore(_workContextAccessor.WorkContext.CurrentCustomer.StaffStoreId))
+ if (await _groupService.IsStaff(_contextAccessor.WorkContext.CurrentCustomer))
+ if (!course.AccessToEntityByStore(_contextAccessor.WorkContext.CurrentCustomer.StaffStoreId))
return RedirectToAction("Edit", new { id = course.Id });
if (ModelState.IsValid)
{
- if (await _groupService.IsStaff(_workContextAccessor.WorkContext.CurrentCustomer))
- model.Stores = [_workContextAccessor.WorkContext.CurrentCustomer.StaffStoreId];
+ if (await _groupService.IsStaff(_contextAccessor.WorkContext.CurrentCustomer))
+ model.Stores = [_contextAccessor.WorkContext.CurrentCustomer.StaffStoreId];
course = await _courseViewModelService.UpdateCourseModel(course, model);
@@ -257,8 +257,8 @@ public class CourseController : BaseAdminController
//No course found with the specified id
return RedirectToAction("List");
- if (await _groupService.IsStaff(_workContextAccessor.WorkContext.CurrentCustomer))
- if (!course.AccessToEntityByStore(_workContextAccessor.WorkContext.CurrentCustomer.StaffStoreId))
+ if (await _groupService.IsStaff(_contextAccessor.WorkContext.CurrentCustomer))
+ if (!course.AccessToEntityByStore(_contextAccessor.WorkContext.CurrentCustomer.StaffStoreId))
return RedirectToAction("Edit", new { id = course.Id });
if (ModelState.IsValid)
@@ -393,17 +393,17 @@ public class CourseController : BaseAdminController
//No course found with the specified id
return RedirectToAction("List");
- if (await _groupService.IsStaff(_workContextAccessor.WorkContext.CurrentCustomer))
+ if (await _groupService.IsStaff(_contextAccessor.WorkContext.CurrentCustomer))
{
if (!course.LimitedToStores || (course.LimitedToStores &&
- course.Stores.Contains(_workContextAccessor.WorkContext.CurrentCustomer.StaffStoreId) &&
+ course.Stores.Contains(_contextAccessor.WorkContext.CurrentCustomer.StaffStoreId) &&
course.Stores.Count > 1))
{
Warning(_translationService.GetResource("Admin.Courses.Course.Permissions"));
}
else
{
- if (!course.AccessToEntityByStore(_workContextAccessor.WorkContext.CurrentCustomer.StaffStoreId))
+ if (!course.AccessToEntityByStore(_contextAccessor.WorkContext.CurrentCustomer.StaffStoreId))
return RedirectToAction("List");
}
}
@@ -423,17 +423,17 @@ public class CourseController : BaseAdminController
//No course found with the specified id
return RedirectToAction("List");
- if (await _groupService.IsStaff(_workContextAccessor.WorkContext.CurrentCustomer))
+ if (await _groupService.IsStaff(_contextAccessor.WorkContext.CurrentCustomer))
{
if (!course.LimitedToStores || (course.LimitedToStores &&
- course.Stores.Contains(_workContextAccessor.WorkContext.CurrentCustomer.StaffStoreId) &&
+ course.Stores.Contains(_contextAccessor.WorkContext.CurrentCustomer.StaffStoreId) &&
course.Stores.Count > 1))
{
Warning(_translationService.GetResource("Admin.Courses.Course.Permissions"));
}
else
{
- if (!course.AccessToEntityByStore(_workContextAccessor.WorkContext.CurrentCustomer.StaffStoreId))
+ if (!course.AccessToEntityByStore(_contextAccessor.WorkContext.CurrentCustomer.StaffStoreId))
return RedirectToAction("List");
}
}
@@ -467,17 +467,17 @@ public class CourseController : BaseAdminController
//No course found with the specified id
return RedirectToAction("List");
- if (await _groupService.IsStaff(_workContextAccessor.WorkContext.CurrentCustomer))
+ if (await _groupService.IsStaff(_contextAccessor.WorkContext.CurrentCustomer))
{
if (!course.LimitedToStores || (course.LimitedToStores &&
- course.Stores.Contains(_workContextAccessor.WorkContext.CurrentCustomer.StaffStoreId) &&
+ course.Stores.Contains(_contextAccessor.WorkContext.CurrentCustomer.StaffStoreId) &&
course.Stores.Count > 1))
{
Warning(_translationService.GetResource("Admin.Courses.Course.Permissions"));
}
else
{
- if (!course.AccessToEntityByStore(_workContextAccessor.WorkContext.CurrentCustomer.StaffStoreId))
+ if (!course.AccessToEntityByStore(_contextAccessor.WorkContext.CurrentCustomer.StaffStoreId))
return RedirectToAction("List");
}
}
@@ -502,8 +502,8 @@ public class CourseController : BaseAdminController
//No category found with the specified id
return RedirectToAction("List");
- if (await _groupService.IsStaff(_workContextAccessor.WorkContext.CurrentCustomer))
- if (!course.AccessToEntityByStore(_workContextAccessor.WorkContext.CurrentCustomer.StaffStoreId))
+ if (await _groupService.IsStaff(_contextAccessor.WorkContext.CurrentCustomer))
+ if (!course.AccessToEntityByStore(_contextAccessor.WorkContext.CurrentCustomer.StaffStoreId))
return RedirectToAction("Edit", new { id = course.Id });
if (ModelState.IsValid)
{
@@ -540,8 +540,8 @@ public class CourseController : BaseAdminController
//No category found with the specified id
return RedirectToAction("List");
- if (await _groupService.IsStaff(_workContextAccessor.WorkContext.CurrentCustomer))
- if (!course.AccessToEntityByStore(_workContextAccessor.WorkContext.CurrentCustomer.StaffStoreId))
+ if (await _groupService.IsStaff(_contextAccessor.WorkContext.CurrentCustomer))
+ if (!course.AccessToEntityByStore(_contextAccessor.WorkContext.CurrentCustomer.StaffStoreId))
return RedirectToAction("Edit", new { id = course.Id });
await _courseViewModelService.DeleteCourseLesson(lesson);
Success(_translationService.GetResource("Admin.Courses.Course.Lesson.Deleted"));
diff --git a/src/Web/Grand.Web.Admin/Controllers/CustomerController.cs b/src/Web/Grand.Web.Admin/Controllers/CustomerController.cs
index f092998a2..8ad48cd27 100644
--- a/src/Web/Grand.Web.Admin/Controllers/CustomerController.cs
+++ b/src/Web/Grand.Web.Admin/Controllers/CustomerController.cs
@@ -41,7 +41,7 @@ public class CustomerController : BaseAdminController
ICustomerViewModelService customerViewModelService,
ICustomerManagerService customerManagerService,
ITranslationService translationService,
- IWorkContextAccessor workContextAccessor,
+ IContextAccessor contextAccessor,
IGroupService groupService,
IExportManager<Customer> exportManager,
ICustomerAttributeParser customerAttributeParser,
@@ -59,7 +59,7 @@ public class CustomerController : BaseAdminController
_customerViewModelService = customerViewModelService;
_customerManagerService = customerManagerService;
_translationService = translationService;
- _workContextAccessor = workContextAccessor;
+ _contextAccessor = contextAccessor;
_groupService = groupService;
_exportManager = exportManager;
_customerAttributeParser = customerAttributeParser;
@@ -143,8 +143,8 @@ public class CustomerController : BaseAdminController
protected virtual async Task<bool> CheckSalesManager(Customer customer)
{
- return await _groupService.IsSalesManager(_workContextAccessor.WorkContext.CurrentCustomer)
- && _workContextAccessor.WorkContext.CurrentCustomer.SeId != customer.SeId;
+ return await _groupService.IsSalesManager(_contextAccessor.WorkContext.CurrentCustomer)
+ && _contextAccessor.WorkContext.CurrentCustomer.SeId != customer.SeId;
}
#region Message contact form
@@ -192,7 +192,7 @@ public class CustomerController : BaseAdminController
private readonly ICustomerViewModelService _customerViewModelService;
private readonly ICustomerManagerService _customerManagerService;
private readonly ITranslationService _translationService;
- private readonly IWorkContextAccessor _workContextAccessor;
+ private readonly IContextAccessor _contextAccessor;
private readonly IExportManager<Customer> _exportManager;
private readonly ICustomerAttributeParser _customerAttributeParser;
private readonly ICustomerAttributeService _customerAttributeService;
@@ -387,7 +387,7 @@ public class CustomerController : BaseAdminController
//No customer found with the specified id
return RedirectToAction("List");
- if (customer.Id == _workContextAccessor.WorkContext.CurrentCustomer.Id)
+ if (customer.Id == _contextAccessor.WorkContext.CurrentCustomer.Id)
{
Error(_translationService.GetResource("Admin.Customers.Customers.NoSelfDelete"));
return RedirectToAction("List");
@@ -435,13 +435,13 @@ public class CustomerController : BaseAdminController
return RedirectToAction("Edit", customer.Id);
}
- if (!await _groupService.IsAdmin(_workContextAccessor.WorkContext.CurrentCustomer) && await _groupService.IsAdmin(customer))
+ if (!await _groupService.IsAdmin(_contextAccessor.WorkContext.CurrentCustomer) && await _groupService.IsAdmin(customer))
{
Error("A non-admin user cannot impersonate as an administrator");
return RedirectToAction("Edit", customer.Id);
}
- await _customerService.UpdateUserField(_workContextAccessor.WorkContext.CurrentCustomer,
+ await _customerService.UpdateUserField(_contextAccessor.WorkContext.CurrentCustomer,
SystemCustomerFieldNames.ImpersonatedCustomerId, customer.Id);
return RedirectToAction("Index", "Home", new { area = "" });
@@ -456,8 +456,8 @@ public class CustomerController : BaseAdminController
//No customer found with the specified id
return RedirectToAction("List");
- await _messageProviderService.SendCustomerWelcomeMessage(customer, _workContextAccessor.WorkContext.CurrentStore,
- _workContextAccessor.WorkContext.WorkingLanguage.Id);
+ await _messageProviderService.SendCustomerWelcomeMessage(customer, _contextAccessor.StoreContext.CurrentStore,
+ _contextAccessor.WorkContext.WorkingLanguage.Id);
Success(_translationService.GetResource("Admin.Customers.Customers.SendWelcomeMessage.Success"));
@@ -476,8 +476,8 @@ public class CustomerController : BaseAdminController
//email validation message
await _customerService.UpdateUserField(customer, SystemCustomerFieldNames.AccountActivationToken,
Guid.NewGuid().ToString());
- await _messageProviderService.SendCustomerEmailValidationMessage(customer, _workContextAccessor.WorkContext.CurrentStore,
- _workContextAccessor.WorkContext.WorkingLanguage.Id);
+ await _messageProviderService.SendCustomerEmailValidationMessage(customer, _contextAccessor.StoreContext.CurrentStore,
+ _contextAccessor.WorkContext.WorkingLanguage.Id);
Success(_translationService.GetResource("Admin.Customers.Customers.ReSendActivationMessage.Success"));
@@ -696,8 +696,8 @@ public class CustomerController : BaseAdminController
var model = new OrderListModel {
CustomerId = customerId
};
- if (await _groupService.IsStaff(_workContextAccessor.WorkContext.CurrentCustomer))
- model.StoreId = _workContextAccessor.WorkContext.CurrentCustomer.StaffStoreId;
+ if (await _groupService.IsStaff(_contextAccessor.WorkContext.CurrentCustomer))
+ model.StoreId = _contextAccessor.WorkContext.CurrentCustomer.StaffStoreId;
var (orderModels, totalCount) =
await orderViewModelService.PrepareOrderModel(model, command.Page, command.PageSize);
@@ -723,8 +723,8 @@ public class CustomerController : BaseAdminController
if (order == null)
throw new ArgumentException("No order found with the specified id");
- if (await _groupService.IsStaff(_workContextAccessor.WorkContext.CurrentCustomer) &&
- order.StoreId != _workContextAccessor.WorkContext.CurrentCustomer.StaffStoreId)
+ if (await _groupService.IsStaff(_contextAccessor.WorkContext.CurrentCustomer) &&
+ order.StoreId != _contextAccessor.WorkContext.CurrentCustomer.StaffStoreId)
return Json(new DataSourceResult {
Data = null,
Total = 0
@@ -968,7 +968,7 @@ public class CustomerController : BaseAdminController
public async Task<IActionResult> ExportExcelAll(CustomerListModel model)
{
var salesEmployeeId =
- await _groupService.IsSalesManager(_workContextAccessor.WorkContext.CurrentCustomer) ? _workContextAccessor.WorkContext.CurrentCustomer.SeId : "";
+ await _groupService.IsSalesManager(_contextAccessor.WorkContext.CurrentCustomer) ? _contextAccessor.WorkContext.CurrentCustomer.SeId : "";
var customers = await _customerService.GetAllCustomers(
customerGroupIds: model.SearchCustomerGroupIds.ToArray(),
diff --git a/src/Web/Grand.Web.Admin/Controllers/CustomerGroupController.cs b/src/Web/Grand.Web.Admin/Controllers/CustomerGroupController.cs
index 0ed5f31bd..ddb19bf64 100644
--- a/src/Web/Grand.Web.Admin/Controllers/CustomerGroupController.cs
+++ b/src/Web/Grand.Web.Admin/Controllers/CustomerGroupController.cs
@@ -25,14 +25,14 @@ public class CustomerGroupController : BaseAdminController
IGroupService groupService,
ITranslationService translationService,
IPermissionService permissionService,
- IWorkContextAccessor workContextAccessor,
+ IContextAccessor contextAccessor,
ICustomerGroupProductService customerGroupProductService)
{
_customerGroupViewModelService = customerGroupViewModelService;
_groupService = groupService;
_translationService = translationService;
_permissionService = permissionService;
- _workContextAccessor = workContextAccessor;
+ _contextAccessor = contextAccessor;
_customerGroupProductService = customerGroupProductService;
}
@@ -44,7 +44,7 @@ public class CustomerGroupController : BaseAdminController
private readonly IGroupService _groupService;
private readonly ITranslationService _translationService;
private readonly IPermissionService _permissionService;
- private readonly IWorkContextAccessor _workContextAccessor;
+ private readonly IContextAccessor _contextAccessor;
private readonly ICustomerGroupProductService _customerGroupProductService;
#endregion
@@ -263,7 +263,7 @@ public class CustomerGroupController : BaseAdminController
foreach (var pr in permissionRecords)
model.Add(new CustomerGroupPermissionModel {
Id = pr.Id,
- Name = _translationService.GetResource(pr.GetTranslationPermissionName(), _workContextAccessor.WorkContext.WorkingLanguage.Id),
+ Name = _translationService.GetResource(pr.GetTranslationPermissionName(), _contextAccessor.WorkContext.WorkingLanguage.Id),
SystemName = pr.SystemName,
Actions = pr.Actions.ToList(),
Access = pr.CustomerGroups.Contains(customerGroupId)
diff --git a/src/Web/Grand.Web.Admin/Controllers/DiscountController.cs b/src/Web/Grand.Web.Admin/Controllers/DiscountController.cs
index 22f0f993e..d2287c206 100644
--- a/src/Web/Grand.Web.Admin/Controllers/DiscountController.cs
+++ b/src/Web/Grand.Web.Admin/Controllers/DiscountController.cs
@@ -33,7 +33,7 @@ public class DiscountController : BaseAdminController
IDiscountViewModelService discountViewModelService,
IDiscountService discountService,
ITranslationService translationService,
- IWorkContextAccessor workContextAccessor,
+ IContextAccessor contextAccessor,
IDateTimeService dateTimeService,
IGroupService groupService,
IDiscountProviderLoader discountProviderLoader,
@@ -42,7 +42,7 @@ public class DiscountController : BaseAdminController
_discountViewModelService = discountViewModelService;
_discountService = discountService;
_translationService = translationService;
- _workContextAccessor = workContextAccessor;
+ _contextAccessor = contextAccessor;
_dateTimeService = dateTimeService;
_groupService = groupService;
_discountProviderLoader = discountProviderLoader;
@@ -56,7 +56,7 @@ public class DiscountController : BaseAdminController
private readonly IDiscountViewModelService _discountViewModelService;
private readonly IDiscountService _discountService;
private readonly ITranslationService _translationService;
- private readonly IWorkContextAccessor _workContextAccessor;
+ private readonly IContextAccessor _contextAccessor;
private readonly IDateTimeService _dateTimeService;
private readonly IGroupService _groupService;
private readonly IDiscountProviderLoader _discountProviderLoader;
@@ -110,8 +110,8 @@ public class DiscountController : BaseAdminController
{
if (ModelState.IsValid)
{
- if (await _groupService.IsStaff(_workContextAccessor.WorkContext.CurrentCustomer))
- model.Stores = [_workContextAccessor.WorkContext.CurrentCustomer.StaffStoreId];
+ if (await _groupService.IsStaff(_contextAccessor.WorkContext.CurrentCustomer))
+ model.Stores = [_contextAccessor.WorkContext.CurrentCustomer.StaffStoreId];
var discount = await _discountViewModelService.InsertDiscountModel(model);
Success(_translationService.GetResource("admin.marketing.discounts.Added"));
@@ -133,17 +133,17 @@ public class DiscountController : BaseAdminController
//No discount found with the specified id
return RedirectToAction("List");
- if (await _groupService.IsStaff(_workContextAccessor.WorkContext.CurrentCustomer))
+ if (await _groupService.IsStaff(_contextAccessor.WorkContext.CurrentCustomer))
{
if (!discount.LimitedToStores || (discount.LimitedToStores &&
- discount.Stores.Contains(_workContextAccessor.WorkContext.CurrentCustomer.StaffStoreId) &&
+ discount.Stores.Contains(_contextAccessor.WorkContext.CurrentCustomer.StaffStoreId) &&
discount.Stores.Count > 1))
{
Warning(_translationService.GetResource("admin.marketing.discounts.Permissions"));
}
else
{
- if (!discount.AccessToEntityByStore(_workContextAccessor.WorkContext.CurrentCustomer.StaffStoreId))
+ if (!discount.AccessToEntityByStore(_contextAccessor.WorkContext.CurrentCustomer.StaffStoreId))
return RedirectToAction("List");
}
}
@@ -164,14 +164,14 @@ public class DiscountController : BaseAdminController
//No discount found with the specified id
return RedirectToAction("List");
- if (await _groupService.IsStaff(_workContextAccessor.WorkContext.CurrentCustomer))
- if (!discount.AccessToEntityByStore(_workContextAccessor.WorkContext.CurrentCustomer.StaffStoreId))
+ if (await _groupService.IsStaff(_contextAccessor.WorkContext.CurrentCustomer))
+ if (!discount.AccessToEntityByStore(_contextAccessor.WorkContext.CurrentCustomer.StaffStoreId))
return RedirectToAction("Edit", new { id = discount.Id });
if (ModelState.IsValid)
{
- if (await _groupService.IsStaff(_workContextAccessor.WorkContext.CurrentCustomer))
- model.Stores = [_workContextAccessor.WorkContext.CurrentCustomer.StaffStoreId];
+ if (await _groupService.IsStaff(_contextAccessor.WorkContext.CurrentCustomer))
+ model.Stores = [_contextAccessor.WorkContext.CurrentCustomer.StaffStoreId];
discount = await _discountViewModelService.UpdateDiscountModel(discount, model);
Success(_translationService.GetResource("admin.marketing.discounts.Updated"));
@@ -201,8 +201,8 @@ public class DiscountController : BaseAdminController
//No discount found with the specified id
return RedirectToAction("List");
- if (await _groupService.IsStaff(_workContextAccessor.WorkContext.CurrentCustomer))
- if (!discount.AccessToEntityByStore(_workContextAccessor.WorkContext.CurrentCustomer.StaffStoreId))
+ if (await _groupService.IsStaff(_contextAccessor.WorkContext.CurrentCustomer))
+ if (!discount.AccessToEntityByStore(_contextAccessor.WorkContext.CurrentCustomer.StaffStoreId))
return RedirectToAction("Edit", new { id = discount.Id });
var usageHistory = await _mediator.Send(new GetDiscountUsageHistoryQuery { DiscountId = discount.Id });
@@ -603,7 +603,7 @@ public class DiscountController : BaseAdminController
DiscountModel.AddBrandToDiscountModel model, [FromServices] IBrandService brandService)
{
var brands = await brandService.GetAllBrands(model.SearchBrandName,
- _workContextAccessor.WorkContext.CurrentCustomer.StaffStoreId, command.Page - 1, command.PageSize, true);
+ _contextAccessor.WorkContext.CurrentCustomer.StaffStoreId, command.Page - 1, command.PageSize, true);
var gridModel = new DataSourceResult {
Data = brands.Select(x => x.ToModel()),
diff --git a/src/Web/Grand.Web.Admin/Controllers/DownloadController.cs b/src/Web/Grand.Web.Admin/Controllers/DownloadController.cs
index e77616e8a..acd62df08 100644
--- a/src/Web/Grand.Web.Admin/Controllers/DownloadController.cs
+++ b/src/Web/Grand.Web.Admin/Controllers/DownloadController.cs
@@ -13,12 +13,12 @@ namespace Grand.Web.Admin.Controllers;
public class DownloadController : BaseAdminController
{
private readonly IDownloadService _downloadService;
- private readonly IWorkContextAccessor _workContextAccessor;
+ private readonly IContextAccessor _contextAccessor;
- public DownloadController(IDownloadService downloadService, IWorkContextAccessor workContextAccessor)
+ public DownloadController(IDownloadService downloadService, IContextAccessor contextAccessor)
{
_downloadService = downloadService;
- _workContextAccessor = workContextAccessor;
+ _contextAccessor = contextAccessor;
}
public async Task<IActionResult> DownloadFile(Guid downloadGuid)
@@ -64,7 +64,6 @@ public class DownloadController : BaseAdminController
return Json(new { downloadId = download.Id, success = true });
}
- [DisableRequestSizeLimit]
[HttpPost]
//do not validate request token (XSRF)
[IgnoreAntiforgeryToken]
@@ -98,7 +97,7 @@ public class DownloadController : BaseAdminController
var download = new Download {
DownloadGuid = Guid.NewGuid(),
- CustomerId = _workContextAccessor.WorkContext.CurrentCustomer.Id,
+ CustomerId = _contextAccessor.WorkContext.CurrentCustomer.Id,
UseDownloadUrl = false,
DownloadUrl = "",
DownloadBinary = fileBinary,
diff --git a/src/Web/Grand.Web.Admin/Controllers/HomeController.cs b/src/Web/Grand.Web.Admin/Controllers/HomeController.cs
index 0493afa79..221544cfe 100644
--- a/src/Web/Grand.Web.Admin/Controllers/HomeController.cs
+++ b/src/Web/Grand.Web.Admin/Controllers/HomeController.cs
@@ -25,7 +25,7 @@ public class HomeController : BaseAdminController
ITranslationService translationService,
IStoreService storeService,
ICustomerService customerService,
- IWorkContextAccessor workContextAccessor,
+ IContextAccessor contextAccessor,
IGroupService groupService,
IOrderReportService orderReportService,
IProductsReportService productsReportService,
@@ -36,7 +36,7 @@ public class HomeController : BaseAdminController
_translationService = translationService;
_storeService = storeService;
_customerService = customerService;
- _workContextAccessor = workContextAccessor;
+ _contextAccessor = contextAccessor;
_groupService = groupService;
_orderReportService = orderReportService;
_productsReportService = productsReportService;
@@ -54,8 +54,8 @@ public class HomeController : BaseAdminController
var model = new DashboardActivityModel();
var storeId = string.Empty;
- if (await _groupService.IsStaff(_workContextAccessor.WorkContext.CurrentCustomer))
- storeId = _workContextAccessor.WorkContext.CurrentCustomer.StaffStoreId;
+ if (await _groupService.IsStaff(_contextAccessor.WorkContext.CurrentCustomer))
+ storeId = _contextAccessor.WorkContext.CurrentCustomer.StaffStoreId;
model.OrdersPending =
(await _orderReportService.GetOrderAverageReportLine(storeId, os: (int)OrderStatusSystem.Pending))
@@ -86,7 +86,7 @@ public class HomeController : BaseAdminController
private readonly ITranslationService _translationService;
private readonly IStoreService _storeService;
private readonly ICustomerService _customerService;
- private readonly IWorkContextAccessor _workContextAccessor;
+ private readonly IContextAccessor _contextAccessor;
private readonly IGroupService _groupService;
private readonly IOrderReportService _orderReportService;
private readonly IProductsReportService _productsReportService;
@@ -121,8 +121,8 @@ public class HomeController : BaseAdminController
{
var language = await languageService.GetLanguageById(langid);
if (language != null)
- await _customerService.UpdateUserField(_workContextAccessor.WorkContext.CurrentCustomer, SystemCustomerFieldNames.LanguageId,
- language.Id, _workContextAccessor.WorkContext.CurrentStore.Id);
+ await _customerService.UpdateUserField(_contextAccessor.WorkContext.CurrentCustomer, SystemCustomerFieldNames.LanguageId,
+ language.Id, _contextAccessor.StoreContext.CurrentStore.Id);
//home page
if (string.IsNullOrEmpty(returnUrl))
@@ -138,15 +138,15 @@ public class HomeController : BaseAdminController
if (storeid != null)
storeid = storeid.Trim();
- if (await _groupService.IsStaff(_workContextAccessor.WorkContext.CurrentCustomer))
+ if (await _groupService.IsStaff(_contextAccessor.WorkContext.CurrentCustomer))
returnUrl = Url.Action("Index", "Home", new { area = Constants.AreaAdmin });
var store = await _storeService.GetStoreById(storeid);
if (store != null || storeid == "")
- await _customerService.UpdateUserField(_workContextAccessor.WorkContext.CurrentCustomer,
+ await _customerService.UpdateUserField(_contextAccessor.WorkContext.CurrentCustomer,
SystemCustomerFieldNames.AdminAreaStoreScopeConfiguration, storeid);
else
- await _customerService.UpdateUserField(_workContextAccessor.WorkContext.CurrentCustomer,
+ await _customerService.UpdateUserField(_contextAccessor.WorkContext.CurrentCustomer,
SystemCustomerFieldNames.AdminAreaStoreScopeConfiguration, "");
//home page
@@ -199,7 +199,7 @@ public class HomeController : BaseAdminController
public async Task<IActionResult> AccessDenied()
{
- var currentCustomer = _workContextAccessor.WorkContext.CurrentCustomer;
+ var currentCustomer = _contextAccessor.WorkContext.CurrentCustomer;
if (currentCustomer == null || await _groupService.IsGuest(currentCustomer))
{
_logger.LogInformation("Access denied to anonymous request");
diff --git a/src/Web/Grand.Web.Admin/Controllers/LoginController.cs b/src/Web/Grand.Web.Admin/Controllers/LoginController.cs
index c7e5c68f8..38c18a730 100644
--- a/src/Web/Grand.Web.Admin/Controllers/LoginController.cs
+++ b/src/Web/Grand.Web.Admin/Controllers/LoginController.cs
@@ -28,7 +28,7 @@ public class LoginController : BaseController
private readonly IMediator _mediator;
private readonly IMessageProviderService _messageProviderService;
private readonly ITranslationService _translationService;
- private readonly IWorkContextAccessor _workContextAccessor;
+ private readonly IContextAccessor _contextAccessor;
public LoginController(
CustomerSettings customerSettings,
@@ -38,7 +38,7 @@ public class LoginController : BaseController
ICustomerService customerService,
IGrandAuthenticationService authenticationService,
IMessageProviderService messageProviderService,
- IWorkContextAccessor workContextAccessor,
+ IContextAccessor contextAccessor,
IMediator mediator)
{
_customerSettings = customerSettings;
@@ -48,7 +48,7 @@ public class LoginController : BaseController
_customerService = customerService;
_authenticationService = authenticationService;
_messageProviderService = messageProviderService;
- _workContextAccessor = workContextAccessor;
+ _contextAccessor = contextAccessor;
_mediator = mediator;
}
@@ -128,11 +128,11 @@ public class LoginController : BaseController
if (_customerSettings.TwoFactorAuthenticationType != TwoFactorAuthenticationType.AppVerification)
{
- await twoFactorAuthenticationService.GenerateCodeSetup("", customer, _workContextAccessor.WorkContext.WorkingLanguage,
+ await twoFactorAuthenticationService.GenerateCodeSetup("", customer, _contextAccessor.WorkContext.WorkingLanguage,
_customerSettings.TwoFactorAuthenticationType);
if (_customerSettings.TwoFactorAuthenticationType == TwoFactorAuthenticationType.EmailVerification)
await _messageProviderService.SendCustomerEmailTokenValidationMessage(customer,
- _workContextAccessor.WorkContext.CurrentStore, _workContextAccessor.WorkContext.WorkingLanguage.Id);
+ _contextAccessor.StoreContext.CurrentStore, _contextAccessor.WorkContext.WorkingLanguage.Id);
}
return View();
diff --git a/src/Web/Grand.Web.Admin/Controllers/MerchandiseReturnController.cs b/src/Web/Grand.Web.Admin/Controllers/MerchandiseReturnController.cs
index 272f73688..795de9f54 100644
--- a/src/Web/Grand.Web.Admin/Controllers/MerchandiseReturnController.cs
+++ b/src/Web/Grand.Web.Admin/Controllers/MerchandiseReturnController.cs
@@ -26,14 +26,14 @@ public class MerchandiseReturnController : BaseAdminController
ITranslationService translationService,
IMerchandiseReturnService merchandiseReturnService,
IOrderService orderService,
- IWorkContextAccessor workContextAccessor,
+ IContextAccessor contextAccessor,
IGroupService groupService)
{
_merchandiseReturnViewModelService = merchandiseReturnViewModelService;
_translationService = translationService;
_merchandiseReturnService = merchandiseReturnService;
_orderService = orderService;
- _workContextAccessor = workContextAccessor;
+ _contextAccessor = contextAccessor;
_groupService = groupService;
}
@@ -45,7 +45,7 @@ public class MerchandiseReturnController : BaseAdminController
private readonly ITranslationService _translationService;
private readonly IMerchandiseReturnService _merchandiseReturnService;
private readonly IOrderService _orderService;
- private readonly IWorkContextAccessor _workContextAccessor;
+ private readonly IContextAccessor _contextAccessor;
private readonly IGroupService _groupService;
#endregion Fields
@@ -68,8 +68,8 @@ public class MerchandiseReturnController : BaseAdminController
[HttpPost]
public async Task<IActionResult> List(DataSourceRequest command, MerchandiseReturnListModel model)
{
- if (await _groupService.IsStaff(_workContextAccessor.WorkContext.CurrentCustomer))
- model.StoreId = _workContextAccessor.WorkContext.CurrentCustomer.StaffStoreId;
+ if (await _groupService.IsStaff(_contextAccessor.WorkContext.CurrentCustomer))
+ model.StoreId = _contextAccessor.WorkContext.CurrentCustomer.StaffStoreId;
var merchandiseReturnModels =
await _merchandiseReturnViewModelService.PrepareMerchandiseReturnModel(model, command.Page,
command.PageSize);
@@ -96,8 +96,8 @@ public class MerchandiseReturnController : BaseAdminController
//not found
return RedirectToAction("List", "MerchandiseReturn");
- if (await _groupService.IsStaff(_workContextAccessor.WorkContext.CurrentCustomer) &&
- merchandiseReturn.StoreId != _workContextAccessor.WorkContext.CurrentCustomer.StaffStoreId)
+ if (await _groupService.IsStaff(_contextAccessor.WorkContext.CurrentCustomer) &&
+ merchandiseReturn.StoreId != _contextAccessor.WorkContext.CurrentCustomer.StaffStoreId)
return RedirectToAction("List", "MerchandiseReturn");
return RedirectToAction("Edit", "MerchandiseReturn", new { id = merchandiseReturn.Id });
@@ -111,8 +111,8 @@ public class MerchandiseReturnController : BaseAdminController
if (merchandiseReturn == null)
return ErrorForKendoGridJson("Merchandise return not found");
- if (await _groupService.IsStaff(_workContextAccessor.WorkContext.CurrentCustomer) &&
- merchandiseReturn.StoreId != _workContextAccessor.WorkContext.CurrentCustomer.StaffStoreId)
+ if (await _groupService.IsStaff(_contextAccessor.WorkContext.CurrentCustomer) &&
+ merchandiseReturn.StoreId != _contextAccessor.WorkContext.CurrentCustomer.StaffStoreId)
return ErrorForKendoGridJson("Merchandise return is not your");
var items = await _merchandiseReturnViewModelService.PrepareMerchandiseReturnItemModel(merchandiseReturnId);
var gridModel = new DataSourceResult {
@@ -132,8 +132,8 @@ public class MerchandiseReturnController : BaseAdminController
//No merchandise return found with the specified id
return RedirectToAction("List");
- if (await _groupService.IsStaff(_workContextAccessor.WorkContext.CurrentCustomer) &&
- merchandiseReturn.StoreId != _workContextAccessor.WorkContext.CurrentCustomer.StaffStoreId)
+ if (await _groupService.IsStaff(_contextAccessor.WorkContext.CurrentCustomer) &&
+ merchandiseReturn.StoreId != _contextAccessor.WorkContext.CurrentCustomer.StaffStoreId)
return RedirectToAction("List", "MerchandiseReturn");
var model = new MerchandiseReturnModel();
await _merchandiseReturnViewModelService.PrepareMerchandiseReturnModel(model, merchandiseReturn, false);
@@ -154,8 +154,8 @@ public class MerchandiseReturnController : BaseAdminController
//No merchandise return found with the specified id
return RedirectToAction("List");
- if (await _groupService.IsStaff(_workContextAccessor.WorkContext.CurrentCustomer) &&
- merchandiseReturn.StoreId != _workContextAccessor.WorkContext.CurrentCustomer.StaffStoreId)
+ if (await _groupService.IsStaff(_contextAccessor.WorkContext.CurrentCustomer) &&
+ merchandiseReturn.StoreId != _contextAccessor.WorkContext.CurrentCustomer.StaffStoreId)
return RedirectToAction("List", "MerchandiseReturn");
if (ModelState.IsValid)
@@ -190,8 +190,8 @@ public class MerchandiseReturnController : BaseAdminController
//No merchandise return found with the specified id
return RedirectToAction("List");
- if (await _groupService.IsStaff(_workContextAccessor.WorkContext.CurrentCustomer) &&
- merchandiseReturn.StoreId != _workContextAccessor.WorkContext.CurrentCustomer.StaffStoreId)
+ if (await _groupService.IsStaff(_contextAccessor.WorkContext.CurrentCustomer) &&
+ merchandiseReturn.StoreId != _contextAccessor.WorkContext.CurrentCustomer.StaffStoreId)
return RedirectToAction("List", "MerchandiseReturn");
if (ModelState.IsValid)
{
@@ -216,8 +216,8 @@ public class MerchandiseReturnController : BaseAdminController
if (merchandiseReturn == null)
throw new ArgumentException("No merchandise return found with the specified id");
- if (await _groupService.IsStaff(_workContextAccessor.WorkContext.CurrentCustomer) &&
- merchandiseReturn.StoreId != _workContextAccessor.WorkContext.CurrentCustomer.StaffStoreId) return Content("");
+ if (await _groupService.IsStaff(_contextAccessor.WorkContext.CurrentCustomer) &&
+ merchandiseReturn.StoreId != _contextAccessor.WorkContext.CurrentCustomer.StaffStoreId) return Content("");
//merchandise return notes
var merchandiseReturnNoteModels =
await _merchandiseReturnViewModelService.PrepareMerchandiseReturnNotes(merchandiseReturn);
@@ -240,8 +240,8 @@ public class MerchandiseReturnController : BaseAdminController
if (order == null)
return Json(new { Result = false });
- if (await _groupService.IsStaff(_workContextAccessor.WorkContext.CurrentCustomer) &&
- merchandiseReturn.StoreId != _workContextAccessor.WorkContext.CurrentCustomer.StaffStoreId) return Json(new { Result = false });
+ if (await _groupService.IsStaff(_contextAccessor.WorkContext.CurrentCustomer) &&
+ merchandiseReturn.StoreId != _contextAccessor.WorkContext.CurrentCustomer.StaffStoreId) return Json(new { Result = false });
await _merchandiseReturnViewModelService.InsertMerchandiseReturnNote(merchandiseReturn, order, downloadId,
displayToCustomer, message);
@@ -256,8 +256,8 @@ public class MerchandiseReturnController : BaseAdminController
if (merchandiseReturn == null)
throw new ArgumentException("No merchandise return found with the specified id");
- if (await _groupService.IsStaff(_workContextAccessor.WorkContext.CurrentCustomer) &&
- merchandiseReturn.StoreId != _workContextAccessor.WorkContext.CurrentCustomer.StaffStoreId) return Json(new { Result = false });
+ if (await _groupService.IsStaff(_contextAccessor.WorkContext.CurrentCustomer) &&
+ merchandiseReturn.StoreId != _contextAccessor.WorkContext.CurrentCustomer.StaffStoreId) return Json(new { Result = false });
await _merchandiseReturnViewModelService.DeleteMerchandiseReturnNote(merchandiseReturn, id);
diff --git a/src/Web/Grand.Web.Admin/Controllers/NewsLetterSubscriptionController.cs b/src/Web/Grand.Web.Admin/Controllers/NewsLetterSubscriptionController.cs
index e02264baa..b0ab6d846 100644
--- a/src/Web/Grand.Web.Admin/Controllers/NewsLetterSubscriptionController.cs
+++ b/src/Web/Grand.Web.Admin/Controllers/NewsLetterSubscriptionController.cs
@@ -26,7 +26,7 @@ public class NewsLetterSubscriptionController : BaseAdminController
private readonly INewsLetterSubscriptionService _newsLetterSubscriptionService;
private readonly IStoreService _storeService;
private readonly ITranslationService _translationService;
- private readonly IWorkContextAccessor _workContextAccessor;
+ private readonly IContextAccessor _contextAccessor;
public NewsLetterSubscriptionController(INewsLetterSubscriptionService newsLetterSubscriptionService,
INewsletterCategoryService newsletterCategoryService,
@@ -34,7 +34,7 @@ public class NewsLetterSubscriptionController : BaseAdminController
ITranslationService translationService,
IStoreService storeService,
IGroupService groupService,
- IWorkContextAccessor workContextAccessor)
+ IContextAccessor contextAccessor)
{
_newsLetterSubscriptionService = newsLetterSubscriptionService;
_newsletterCategoryService = newsletterCategoryService;
@@ -42,7 +42,7 @@ public class NewsLetterSubscriptionController : BaseAdminController
_translationService = translationService;
_storeService = storeService;
_groupService = groupService;
- _workContextAccessor = workContextAccessor;
+ _contextAccessor = contextAccessor;
}
[NonAction]
@@ -76,7 +76,7 @@ public class NewsLetterSubscriptionController : BaseAdminController
{
var model = new NewsLetterSubscriptionListModel();
- var storeId = _workContextAccessor.WorkContext.CurrentCustomer.StaffStoreId;
+ var storeId = _contextAccessor.WorkContext.CurrentCustomer.StaffStoreId;
//stores
model.AvailableStores.Add(new SelectListItem
@@ -123,8 +123,8 @@ public class NewsLetterSubscriptionController : BaseAdminController
break;
}
- if (await _groupService.IsStaff(_workContextAccessor.WorkContext.CurrentCustomer))
- model.StoreId = _workContextAccessor.WorkContext.CurrentCustomer.StaffStoreId;
+ if (await _groupService.IsStaff(_contextAccessor.WorkContext.CurrentCustomer))
+ model.StoreId = _contextAccessor.WorkContext.CurrentCustomer.StaffStoreId;
var newsletterSubscriptions = await _newsLetterSubscriptionService.GetAllNewsLetterSubscriptions(
model.SearchEmail,
@@ -190,8 +190,8 @@ public class NewsLetterSubscriptionController : BaseAdminController
break;
}
- if (await _groupService.IsStaff(_workContextAccessor.WorkContext.CurrentCustomer))
- model.StoreId = _workContextAccessor.WorkContext.CurrentCustomer.StaffStoreId;
+ if (await _groupService.IsStaff(_contextAccessor.WorkContext.CurrentCustomer))
+ model.StoreId = _contextAccessor.WorkContext.CurrentCustomer.StaffStoreId;
var subscriptions = await _newsLetterSubscriptionService.GetAllNewsLetterSubscriptions(model.SearchEmail,
model.StoreId, isActive, searchCategoryIds);
@@ -212,7 +212,7 @@ public class NewsLetterSubscriptionController : BaseAdminController
if (importcsvfile is { Length: > 0 })
{
var count = await _newsLetterSubscriptionService.ImportNewsletterSubscribersFromTxt(
- importcsvfile.OpenReadStream(), _workContextAccessor.WorkContext.CurrentStore.Id);
+ importcsvfile.OpenReadStream(), _contextAccessor.StoreContext.CurrentStore.Id);
Success(string.Format(
_translationService.GetResource("admin.marketing.NewsLetterSubscriptions.ImportEmailsSuccess"),
count));
diff --git a/src/Web/Grand.Web.Admin/Controllers/OnlineCustomerController.cs b/src/Web/Grand.Web.Admin/Controllers/OnlineCustomerController.cs
index ad6c447df..e5ad28f11 100644
--- a/src/Web/Grand.Web.Admin/Controllers/OnlineCustomerController.cs
+++ b/src/Web/Grand.Web.Admin/Controllers/OnlineCustomerController.cs
@@ -20,13 +20,13 @@ public class OnlineCustomerController : BaseAdminController
IDateTimeService dateTimeService,
CustomerSettings customerSettings,
ITranslationService translationService,
- IWorkContextAccessor workContextAccessor)
+ IContextAccessor contextAccessor)
{
_customerService = customerService;
_dateTimeService = dateTimeService;
_customerSettings = customerSettings;
_translationService = translationService;
- _workContextAccessor = workContextAccessor;
+ _contextAccessor = contextAccessor;
}
#endregion
@@ -37,7 +37,7 @@ public class OnlineCustomerController : BaseAdminController
private readonly IDateTimeService _dateTimeService;
private readonly CustomerSettings _customerSettings;
private readonly ITranslationService _translationService;
- private readonly IWorkContextAccessor _workContextAccessor;
+ private readonly IContextAccessor _contextAccessor;
#endregion
@@ -54,7 +54,7 @@ public class OnlineCustomerController : BaseAdminController
{
var customers = await _customerService.GetOnlineCustomers(
DateTime.UtcNow.AddMinutes(-_customerSettings.OnlineCustomerMinutes),
- null, _workContextAccessor.WorkContext.CurrentCustomer.StaffStoreId, _workContextAccessor.WorkContext.CurrentCustomer.SeId, command.Page - 1,
+ null, _contextAccessor.WorkContext.CurrentCustomer.StaffStoreId, _contextAccessor.WorkContext.CurrentCustomer.SeId, command.Page - 1,
command.PageSize);
var items = new List<OnlineCustomerModel>();
foreach (var x in customers)
diff --git a/src/Web/Grand.Web.Admin/Controllers/OrderController.cs b/src/Web/Grand.Web.Admin/Controllers/OrderController.cs
index 96916cac1..8e621fc6e 100644
--- a/src/Web/Grand.Web.Admin/Controllers/OrderController.cs
+++ b/src/Web/Grand.Web.Admin/Controllers/OrderController.cs
@@ -28,7 +28,7 @@ public class OrderController(
IOrderService orderService,
IOrderStatusService orderStatusService,
ITranslationService translationService,
- IWorkContextAccessor workContextAccessor,
+ IContextAccessor contextAccessor,
IPdfService pdfService,
IGroupService groupService,
IExportManager<Order> exportManager,
@@ -39,8 +39,8 @@ public class OrderController(
protected virtual async Task<bool> CheckSalesManager(Order order)
{
- return await groupService.IsSalesManager(workContextAccessor.WorkContext.CurrentCustomer)
- && workContextAccessor.WorkContext.CurrentCustomer.SeId != order.SeId;
+ return await groupService.IsSalesManager(contextAccessor.WorkContext.CurrentCustomer)
+ && contextAccessor.WorkContext.CurrentCustomer.SeId != order.SeId;
}
#endregion
@@ -64,7 +64,7 @@ public class OrderController(
int? paymentStatusId = null, int? shippingStatusId = null, DateTime? startDate = null, string code = null)
{
var model = await orderViewModelService.PrepareOrderListModel(orderStatusId, paymentStatusId, shippingStatusId,
- startDate, workContextAccessor.WorkContext.CurrentCustomer.StaffStoreId, code);
+ startDate, contextAccessor.WorkContext.CurrentCustomer.StaffStoreId, code);
return View(model);
}
@@ -76,8 +76,8 @@ public class OrderController(
return Content("");
var storeId = string.Empty;
- if (await groupService.IsStaff(workContextAccessor.WorkContext.CurrentCustomer))
- storeId = workContextAccessor.WorkContext.CurrentCustomer.StaffStoreId;
+ if (await groupService.IsStaff(contextAccessor.WorkContext.CurrentCustomer))
+ storeId = contextAccessor.WorkContext.CurrentCustomer.StaffStoreId;
//products
const int productNumber = 15;
@@ -100,8 +100,8 @@ public class OrderController(
[HttpPost]
public async Task<IActionResult> OrderList(DataSourceRequest command, OrderListModel model)
{
- if (await groupService.IsStaff(workContextAccessor.WorkContext.CurrentCustomer))
- model.StoreId = workContextAccessor.WorkContext.CurrentCustomer.StaffStoreId;
+ if (await groupService.IsStaff(contextAccessor.WorkContext.CurrentCustomer))
+ model.StoreId = contextAccessor.WorkContext.CurrentCustomer.StaffStoreId;
var (orderModels, totalCount) =
await orderViewModelService.PrepareOrderModel(model, command.Page, command.PageSize);
@@ -133,8 +133,8 @@ public class OrderController(
if (order == null || await CheckSalesManager(order))
return RedirectToAction("List");
- if (await groupService.IsStaff(workContextAccessor.WorkContext.CurrentCustomer) &&
- order.StoreId != workContextAccessor.WorkContext.CurrentCustomer.StaffStoreId) return RedirectToAction("List");
+ if (await groupService.IsStaff(contextAccessor.WorkContext.CurrentCustomer) &&
+ order.StoreId != contextAccessor.WorkContext.CurrentCustomer.StaffStoreId) return RedirectToAction("List");
return RedirectToAction("Edit", "Order", new { id = order.Id });
}
@@ -147,8 +147,8 @@ public class OrderController(
[HttpPost]
public async Task<IActionResult> ExportExcelAll(OrderListModel model)
{
- if (await groupService.IsStaff(workContextAccessor.WorkContext.CurrentCustomer))
- model.StoreId = workContextAccessor.WorkContext.CurrentCustomer.StaffStoreId;
+ if (await groupService.IsStaff(contextAccessor.WorkContext.CurrentCustomer))
+ model.StoreId = contextAccessor.WorkContext.CurrentCustomer.StaffStoreId;
//load orders
var orders = await orderViewModelService.PrepareOrders(model);
@@ -178,8 +178,8 @@ public class OrderController(
orders.AddRange(await orderService.GetOrdersByIds(ids));
}
- if (await groupService.IsStaff(workContextAccessor.WorkContext.CurrentCustomer))
- orders = orders.Where(x => x.StoreId == workContextAccessor.WorkContext.CurrentCustomer.StaffStoreId).ToList();
+ if (await groupService.IsStaff(contextAccessor.WorkContext.CurrentCustomer))
+ orders = orders.Where(x => x.StoreId == contextAccessor.WorkContext.CurrentCustomer.StaffStoreId).ToList();
var bytes = await exportManager.Export(orders);
return File(bytes, "text/xls", "orders.xlsx");
}
@@ -199,8 +199,8 @@ public class OrderController(
//No order found with the specified id
return RedirectToAction("List");
- if (await groupService.IsStaff(workContextAccessor.WorkContext.CurrentCustomer) &&
- order.StoreId != workContextAccessor.WorkContext.CurrentCustomer.StaffStoreId) return RedirectToAction("List");
+ if (await groupService.IsStaff(contextAccessor.WorkContext.CurrentCustomer) &&
+ order.StoreId != contextAccessor.WorkContext.CurrentCustomer.StaffStoreId) return RedirectToAction("List");
try
{
await mediator.Send(new CancelOrderCommand { Order = order, NotifyCustomer = true });
@@ -225,8 +225,8 @@ public class OrderController(
//No order found with the specified id
return RedirectToAction("List");
- if (await groupService.IsStaff(workContextAccessor.WorkContext.CurrentCustomer) &&
- order.StoreId != workContextAccessor.WorkContext.CurrentCustomer.StaffStoreId) return RedirectToAction("List");
+ if (await groupService.IsStaff(contextAccessor.WorkContext.CurrentCustomer) &&
+ order.StoreId != contextAccessor.WorkContext.CurrentCustomer.StaffStoreId) return RedirectToAction("List");
try
{
@@ -253,8 +253,8 @@ public class OrderController(
//No order found with the specified id
return RedirectToAction("List");
- if (await groupService.IsStaff(workContextAccessor.WorkContext.CurrentCustomer) &&
- order.StoreId != workContextAccessor.WorkContext.CurrentCustomer.StaffStoreId) return RedirectToAction("List");
+ if (await groupService.IsStaff(contextAccessor.WorkContext.CurrentCustomer) &&
+ order.StoreId != contextAccessor.WorkContext.CurrentCustomer.StaffStoreId) return RedirectToAction("List");
try
{
@@ -295,8 +295,8 @@ public class OrderController(
//No order found with the specified id
return RedirectToAction("List");
- if (await groupService.IsStaff(workContextAccessor.WorkContext.CurrentCustomer) &&
- order.StoreId != workContextAccessor.WorkContext.CurrentCustomer.StaffStoreId) return RedirectToAction("List");
+ if (await groupService.IsStaff(contextAccessor.WorkContext.CurrentCustomer) &&
+ order.StoreId != contextAccessor.WorkContext.CurrentCustomer.StaffStoreId) return RedirectToAction("List");
var model = new OrderModel();
await orderViewModelService.PrepareOrderDetailsModel(model, order);
@@ -330,7 +330,7 @@ public class OrderController(
ICollection<string> selectedIds,
[FromServices] IShipmentService shipmentService)
{
- if (await groupService.IsStaff(workContextAccessor.WorkContext.CurrentCustomer))
+ if (await groupService.IsStaff(contextAccessor.WorkContext.CurrentCustomer))
return RedirectToAction("List", "Order");
if (selectedIds != null)
@@ -354,8 +354,8 @@ public class OrderController(
public async Task<IActionResult> PdfInvoice(string orderId)
{
var order = await orderService.GetOrderById(orderId);
- if ((await groupService.IsStaff(workContextAccessor.WorkContext.CurrentCustomer) &&
- order.StoreId != workContextAccessor.WorkContext.CurrentCustomer.StaffStoreId) ||
+ if ((await groupService.IsStaff(contextAccessor.WorkContext.CurrentCustomer) &&
+ order.StoreId != contextAccessor.WorkContext.CurrentCustomer.StaffStoreId) ||
await CheckSalesManager(order)) return RedirectToAction("List");
var orders = new List<Order> {
@@ -364,7 +364,7 @@ public class OrderController(
byte[] bytes;
using (var stream = new MemoryStream())
{
- await pdfService.PrintOrdersToPdf(stream, orders, workContextAccessor.WorkContext.WorkingLanguage.Id);
+ await pdfService.PrintOrdersToPdf(stream, orders, contextAccessor.WorkContext.WorkingLanguage.Id);
bytes = stream.ToArray();
}
@@ -377,13 +377,13 @@ public class OrderController(
{
//load orders
var orders = await orderViewModelService.PrepareOrders(model);
- if (await groupService.IsStaff(workContextAccessor.WorkContext.CurrentCustomer))
- orders = orders.Where(x => x.StoreId == workContextAccessor.WorkContext.CurrentCustomer.StaffStoreId).ToList();
+ if (await groupService.IsStaff(contextAccessor.WorkContext.CurrentCustomer))
+ orders = orders.Where(x => x.StoreId == contextAccessor.WorkContext.CurrentCustomer.StaffStoreId).ToList();
byte[] bytes;
using (var stream = new MemoryStream())
{
- await pdfService.PrintOrdersToPdf(stream, orders, workContextAccessor.WorkContext.WorkingLanguage.Id, model.VendorId);
+ await pdfService.PrintOrdersToPdf(stream, orders, contextAccessor.WorkContext.WorkingLanguage.Id, model.VendorId);
bytes = stream.ToArray();
}
@@ -404,8 +404,8 @@ public class OrderController(
orders.AddRange(await orderService.GetOrdersByIds(ids));
}
- if (await groupService.IsStaff(workContextAccessor.WorkContext.CurrentCustomer))
- orders = orders.Where(x => x.StoreId == workContextAccessor.WorkContext.CurrentCustomer.StaffStoreId).ToList();
+ if (await groupService.IsStaff(contextAccessor.WorkContext.CurrentCustomer))
+ orders = orders.Where(x => x.StoreId == contextAccessor.WorkContext.CurrentCustomer.StaffStoreId).ToList();
//ensure that we at least one order selected
if (orders.Count == 0)
@@ -417,7 +417,7 @@ public class OrderController(
byte[] bytes;
using (var stream = new MemoryStream())
{
- await pdfService.PrintOrdersToPdf(stream, orders, workContextAccessor.WorkContext.WorkingLanguage.Id);
+ await pdfService.PrintOrdersToPdf(stream, orders, contextAccessor.WorkContext.WorkingLanguage.Id);
bytes = stream.ToArray();
}
@@ -433,8 +433,8 @@ public class OrderController(
//No order found with the specified id
return RedirectToAction("List");
- if (await groupService.IsStaff(workContextAccessor.WorkContext.CurrentCustomer) &&
- order.StoreId != workContextAccessor.WorkContext.CurrentCustomer.StaffStoreId)
+ if (await groupService.IsStaff(contextAccessor.WorkContext.CurrentCustomer) &&
+ order.StoreId != contextAccessor.WorkContext.CurrentCustomer.StaffStoreId)
return RedirectToAction("Edit", "Order", new { id });
order.OrderSubtotalInclTax = model.OrderSubtotalInclTaxValue;
@@ -471,8 +471,8 @@ public class OrderController(
//No order found with the specified id
return RedirectToAction("List");
- if (await groupService.IsStaff(workContextAccessor.WorkContext.CurrentCustomer) &&
- order.StoreId != workContextAccessor.WorkContext.CurrentCustomer.StaffStoreId)
+ if (await groupService.IsStaff(contextAccessor.WorkContext.CurrentCustomer) &&
+ order.StoreId != contextAccessor.WorkContext.CurrentCustomer.StaffStoreId)
return RedirectToAction("Edit", "Order", new { id });
order.ShippingMethod = model.ShippingMethod;
@@ -500,8 +500,8 @@ public class OrderController(
//No order found with the specified id
return RedirectToAction("List");
- if (await groupService.IsStaff(workContextAccessor.WorkContext.CurrentCustomer) &&
- order.StoreId != workContextAccessor.WorkContext.CurrentCustomer.StaffStoreId)
+ if (await groupService.IsStaff(contextAccessor.WorkContext.CurrentCustomer) &&
+ order.StoreId != contextAccessor.WorkContext.CurrentCustomer.StaffStoreId)
return RedirectToAction("Edit", "Order", new { id });
order.UserFields = model.UserFields;
@@ -525,8 +525,8 @@ public class OrderController(
//No order found with the specified id
return RedirectToAction("List");
- if (await groupService.IsStaff(workContextAccessor.WorkContext.CurrentCustomer) &&
- order.StoreId != workContextAccessor.WorkContext.CurrentCustomer.StaffStoreId)
+ if (await groupService.IsStaff(contextAccessor.WorkContext.CurrentCustomer) &&
+ order.StoreId != contextAccessor.WorkContext.CurrentCustomer.StaffStoreId)
return RedirectToAction("Edit", "Order", new { id });
if (order.OrderStatusId == (int)OrderStatusSystem.Cancelled)
{
@@ -591,8 +591,8 @@ public class OrderController(
//No order found with the specified id
return RedirectToAction("List");
- if (await groupService.IsStaff(workContextAccessor.WorkContext.CurrentCustomer) &&
- order.StoreId != workContextAccessor.WorkContext.CurrentCustomer.StaffStoreId)
+ if (await groupService.IsStaff(contextAccessor.WorkContext.CurrentCustomer) &&
+ order.StoreId != contextAccessor.WorkContext.CurrentCustomer.StaffStoreId)
return RedirectToAction("Edit", "Order", new { id });
var orderItem = order.OrderItems.FirstOrDefault(x => x.Id == orderItemId);
@@ -618,8 +618,8 @@ public class OrderController(
//No order found with the specified id
return RedirectToAction("List");
- if (await groupService.IsStaff(workContextAccessor.WorkContext.CurrentCustomer) &&
- order.StoreId != workContextAccessor.WorkContext.CurrentCustomer.StaffStoreId)
+ if (await groupService.IsStaff(contextAccessor.WorkContext.CurrentCustomer) &&
+ order.StoreId != contextAccessor.WorkContext.CurrentCustomer.StaffStoreId)
return RedirectToAction("Edit", "Order", new { id });
var orderItem = order.OrderItems.FirstOrDefault(x => x.Id == orderItemId);
@@ -648,8 +648,8 @@ public class OrderController(
//No order found with the specified id
return RedirectToAction("List");
- if (await groupService.IsStaff(workContextAccessor.WorkContext.CurrentCustomer) &&
- order.StoreId != workContextAccessor.WorkContext.CurrentCustomer.StaffStoreId)
+ if (await groupService.IsStaff(contextAccessor.WorkContext.CurrentCustomer) &&
+ order.StoreId != contextAccessor.WorkContext.CurrentCustomer.StaffStoreId)
return RedirectToAction("Edit", "Order", new { id });
var orderItem = order.OrderItems.FirstOrDefault(x => x.Id == orderItemId);
@@ -676,8 +676,8 @@ public class OrderController(
//No order found with the specified id
return RedirectToAction("List");
- if (await groupService.IsStaff(workContextAccessor.WorkContext.CurrentCustomer) &&
- order.StoreId != workContextAccessor.WorkContext.CurrentCustomer.StaffStoreId)
+ if (await groupService.IsStaff(contextAccessor.WorkContext.CurrentCustomer) &&
+ order.StoreId != contextAccessor.WorkContext.CurrentCustomer.StaffStoreId)
return RedirectToAction("Edit", "Order", new { id });
var orderItem = order.OrderItems.FirstOrDefault(x => x.Id == orderItemId);
@@ -704,8 +704,8 @@ public class OrderController(
//No order found with the specified id
return RedirectToAction("List");
- if (await groupService.IsStaff(workContextAccessor.WorkContext.CurrentCustomer) &&
- order.StoreId != workContextAccessor.WorkContext.CurrentCustomer.StaffStoreId)
+ if (await groupService.IsStaff(contextAccessor.WorkContext.CurrentCustomer) &&
+ order.StoreId != contextAccessor.WorkContext.CurrentCustomer.StaffStoreId)
return RedirectToAction("Edit", "Order", new { id });
var orderItem = order.OrderItems.FirstOrDefault(x => x.Id == orderItemId);
@@ -734,8 +734,8 @@ public class OrderController(
//No order found with the specified id
return RedirectToAction("List");
- if (await groupService.IsStaff(workContextAccessor.WorkContext.CurrentCustomer) &&
- order.StoreId != workContextAccessor.WorkContext.CurrentCustomer.StaffStoreId)
+ if (await groupService.IsStaff(contextAccessor.WorkContext.CurrentCustomer) &&
+ order.StoreId != contextAccessor.WorkContext.CurrentCustomer.StaffStoreId)
return RedirectToAction("Edit", "Order", new { id = order.Id });
var orderItem = order.OrderItems.FirstOrDefault(x => x.Id == model.OrderItemId);
@@ -761,8 +761,8 @@ public class OrderController(
//No order found with the specified id
return RedirectToAction("List");
- if (await groupService.IsStaff(workContextAccessor.WorkContext.CurrentCustomer) &&
- order.StoreId != workContextAccessor.WorkContext.CurrentCustomer.StaffStoreId)
+ if (await groupService.IsStaff(contextAccessor.WorkContext.CurrentCustomer) &&
+ order.StoreId != contextAccessor.WorkContext.CurrentCustomer.StaffStoreId)
return RedirectToAction("Edit", "Order", new { id = model.OrderId });
var orderItem = order.OrderItems.FirstOrDefault(x => x.Id == model.OrderItemId);
@@ -801,7 +801,7 @@ public class OrderController(
categoryIds.Add(model.SearchCategoryId);
var storeId = string.Empty;
- if (await groupService.IsStaff(workContextAccessor.WorkContext.CurrentCustomer)) storeId = workContextAccessor.WorkContext.CurrentCustomer.StaffStoreId;
+ if (await groupService.IsStaff(contextAccessor.WorkContext.CurrentCustomer)) storeId = contextAccessor.WorkContext.CurrentCustomer.StaffStoreId;
var gridModel = new DataSourceResult();
var products = (await productService.SearchProducts(categoryIds: categoryIds,
@@ -835,8 +835,8 @@ public class OrderController(
if (order == null || await CheckSalesManager(order))
return RedirectToAction("List");
- if (await groupService.IsStaff(workContextAccessor.WorkContext.CurrentCustomer) &&
- order.StoreId != workContextAccessor.WorkContext.CurrentCustomer.StaffStoreId) return RedirectToAction("List");
+ if (await groupService.IsStaff(contextAccessor.WorkContext.CurrentCustomer) &&
+ order.StoreId != contextAccessor.WorkContext.CurrentCustomer.StaffStoreId) return RedirectToAction("List");
var model = await orderViewModelService.PrepareAddProductToOrderModel(order, productId);
return View(model);
@@ -850,8 +850,8 @@ public class OrderController(
if (order == null || await CheckSalesManager(order))
return RedirectToAction("List");
- if (await groupService.IsStaff(workContextAccessor.WorkContext.CurrentCustomer) &&
- order.StoreId != workContextAccessor.WorkContext.CurrentCustomer.StaffStoreId) return RedirectToAction("List");
+ if (await groupService.IsStaff(contextAccessor.WorkContext.CurrentCustomer) &&
+ order.StoreId != contextAccessor.WorkContext.CurrentCustomer.StaffStoreId) return RedirectToAction("List");
var warnings = await orderViewModelService.AddProductToOrderDetails(model);
if (!warnings.Any())
@@ -878,8 +878,8 @@ public class OrderController(
//No order found with the specified id
return RedirectToAction("List");
- if (await groupService.IsStaff(workContextAccessor.WorkContext.CurrentCustomer) &&
- order.StoreId != workContextAccessor.WorkContext.CurrentCustomer.StaffStoreId) return RedirectToAction("List");
+ if (await groupService.IsStaff(contextAccessor.WorkContext.CurrentCustomer) &&
+ order.StoreId != contextAccessor.WorkContext.CurrentCustomer.StaffStoreId) return RedirectToAction("List");
var address = new Address();
switch (billingAddress)
@@ -917,8 +917,8 @@ public class OrderController(
//No order found with the specified id
return RedirectToAction("List");
- if (await groupService.IsStaff(workContextAccessor.WorkContext.CurrentCustomer) &&
- order.StoreId != workContextAccessor.WorkContext.CurrentCustomer.StaffStoreId) return RedirectToAction("List");
+ if (await groupService.IsStaff(contextAccessor.WorkContext.CurrentCustomer) &&
+ order.StoreId != contextAccessor.WorkContext.CurrentCustomer.StaffStoreId) return RedirectToAction("List");
var address = new Address();
switch (model.BillingAddress)
@@ -964,8 +964,8 @@ public class OrderController(
if (order == null || await CheckSalesManager(order))
throw new ArgumentException("No order found with the specified id");
- if (await groupService.IsStaff(workContextAccessor.WorkContext.CurrentCustomer) &&
- order.StoreId != workContextAccessor.WorkContext.CurrentCustomer.StaffStoreId) return Content("");
+ if (await groupService.IsStaff(contextAccessor.WorkContext.CurrentCustomer) &&
+ order.StoreId != contextAccessor.WorkContext.CurrentCustomer.StaffStoreId) return Content("");
//order notes
var orderNoteModels = await orderViewModelService.PrepareOrderNotes(order);
var gridModel = new DataSourceResult {
@@ -983,8 +983,8 @@ public class OrderController(
if (order == null || await CheckSalesManager(order))
return Json(new { Result = false });
- if (await groupService.IsStaff(workContextAccessor.WorkContext.CurrentCustomer) &&
- order.StoreId != workContextAccessor.WorkContext.CurrentCustomer.StaffStoreId) return Json(new { Result = false });
+ if (await groupService.IsStaff(contextAccessor.WorkContext.CurrentCustomer) &&
+ order.StoreId != contextAccessor.WorkContext.CurrentCustomer.StaffStoreId) return Json(new { Result = false });
await orderViewModelService.InsertOrderNote(order, downloadId, displayToCustomer, message);
return Json(new { Result = true });
@@ -998,8 +998,8 @@ public class OrderController(
if (order == null || await CheckSalesManager(order))
throw new ArgumentException("No order found with the specified id");
- if (await groupService.IsStaff(workContextAccessor.WorkContext.CurrentCustomer) &&
- order.StoreId != workContextAccessor.WorkContext.CurrentCustomer.StaffStoreId) return Json(new { Result = false });
+ if (await groupService.IsStaff(contextAccessor.WorkContext.CurrentCustomer) &&
+ order.StoreId != contextAccessor.WorkContext.CurrentCustomer.StaffStoreId) return Json(new { Result = false });
await orderViewModelService.DeleteOrderNote(order, id);
diff --git a/src/Web/Grand.Web.Admin/Controllers/PageController.cs b/src/Web/Grand.Web.Admin/Controllers/PageController.cs
index 9c64b6d31..07e71086d 100644
--- a/src/Web/Grand.Web.Admin/Controllers/PageController.cs
+++ b/src/Web/Grand.Web.Admin/Controllers/PageController.cs
@@ -24,14 +24,14 @@ public class PageController : BaseAdminController
IPageService pageService,
ILanguageService languageService,
ITranslationService translationService,
- IWorkContextAccessor workContextAccessor,
+ IContextAccessor contextAccessor,
IDateTimeService dateTimeService)
{
_pageViewModelService = pageViewModelService;
_pageService = pageService;
_languageService = languageService;
_translationService = translationService;
- _workContextAccessor = workContextAccessor;
+ _contextAccessor = contextAccessor;
_dateTimeService = dateTimeService;
}
@@ -43,7 +43,7 @@ public class PageController : BaseAdminController
private readonly IPageService _pageService;
private readonly ILanguageService _languageService;
private readonly ITranslationService _translationService;
- private readonly IWorkContextAccessor _workContextAccessor;
+ private readonly IContextAccessor _contextAccessor;
private readonly IDateTimeService _dateTimeService;
#endregion Fields
@@ -128,7 +128,7 @@ public class PageController : BaseAdminController
return RedirectToAction("List");
var model = page.ToModel(_dateTimeService);
- model.Url = Url.RouteUrl("Page", new { SeName = page.GetSeName(_workContextAccessor.WorkContext.WorkingLanguage.Id) }, "http");
+ model.Url = Url.RouteUrl("Page", new { SeName = page.GetSeName(_contextAccessor.WorkContext.WorkingLanguage.Id) }, "http");
//layouts
await _pageViewModelService.PrepareLayoutsModel(model);
//locales
@@ -169,7 +169,7 @@ public class PageController : BaseAdminController
}
//If we got this far, something failed, redisplay form
- model.Url = Url.RouteUrl("Page", new { SeName = page.GetSeName(_workContextAccessor.WorkContext.WorkingLanguage.Id) }, "http");
+ model.Url = Url.RouteUrl("Page", new { SeName = page.GetSeName(_contextAccessor.WorkContext.WorkingLanguage.Id) }, "http");
//layouts
await _pageViewModelService.PrepareLayoutsModel(model);
return View(model);
diff --git a/src/Web/Grand.Web.Admin/Controllers/PaymentController.cs b/src/Web/Grand.Web.Admin/Controllers/PaymentController.cs
index e9cbfce20..c5236c8a9 100644
--- a/src/Web/Grand.Web.Admin/Controllers/PaymentController.cs
+++ b/src/Web/Grand.Web.Admin/Controllers/PaymentController.cs
@@ -30,7 +30,7 @@ public class PaymentController : BaseAdminController
IShippingMethodService shippingMethodService,
ITranslationService translationService,
IServiceProvider serviceProvider,
- IWorkContextAccessor workContextAccessor)
+ IContextAccessor contextAccessor)
{
_paymentService = paymentService;
_settingService = settingService;
@@ -38,7 +38,7 @@ public class PaymentController : BaseAdminController
_shippingMethodService = shippingMethodService;
_translationService = translationService;
_serviceProvider = serviceProvider;
- _workContextAccessor = workContextAccessor;
+ _contextAccessor = contextAccessor;
}
#endregion
@@ -51,7 +51,7 @@ public class PaymentController : BaseAdminController
private readonly IShippingMethodService _shippingMethodService;
private readonly ITranslationService _translationService;
private readonly IServiceProvider _serviceProvider;
- private readonly IWorkContextAccessor _workContextAccessor;
+ private readonly IContextAccessor _contextAccessor;
#endregion
@@ -83,7 +83,7 @@ public class PaymentController : BaseAdminController
if (plugin != null)
{
tmp.ConfigurationUrl = plugin.ConfigurationUrl();
- tmp.LogoUrl = pluginInfo.GetLogoUrl(_workContextAccessor.WorkContext.CurrentHost.Url);
+ tmp.LogoUrl = pluginInfo.GetLogoUrl(_contextAccessor.StoreContext.CurrentHost.Url);
}
}
diff --git a/src/Web/Grand.Web.Admin/Controllers/PaymentTransactionController.cs b/src/Web/Grand.Web.Admin/Controllers/PaymentTransactionController.cs
index 953da3d6d..fc4034136 100644
--- a/src/Web/Grand.Web.Admin/Controllers/PaymentTransactionController.cs
+++ b/src/Web/Grand.Web.Admin/Controllers/PaymentTransactionController.cs
@@ -27,7 +27,7 @@ public class PaymentTransactionController : BaseAdminController
ITranslationService translationService,
IPaymentTransactionService paymentTransactionService,
IOrderService orderService,
- IWorkContextAccessor workContextAccessor,
+ IContextAccessor contextAccessor,
IGroupService groupService,
IDateTimeService dateTimeService,
IMediator mediator,
@@ -36,7 +36,7 @@ public class PaymentTransactionController : BaseAdminController
_translationService = translationService;
_paymentTransactionService = paymentTransactionService;
_orderService = orderService;
- _workContextAccessor = workContextAccessor;
+ _contextAccessor = contextAccessor;
_groupService = groupService;
_dateTimeService = dateTimeService;
_mediator = mediator;
@@ -50,7 +50,7 @@ public class PaymentTransactionController : BaseAdminController
private readonly IPaymentTransactionService _paymentTransactionService;
private readonly IOrderService _orderService;
private readonly ITranslationService _translationService;
- private readonly IWorkContextAccessor _workContextAccessor;
+ private readonly IContextAccessor _contextAccessor;
private readonly IGroupService _groupService;
private readonly IDateTimeService _dateTimeService;
private readonly IMediator _mediator;
@@ -82,8 +82,8 @@ public class PaymentTransactionController : BaseAdminController
[HttpPost]
public async Task<IActionResult> List(DataSourceRequest command, PaymentTransactionListModel model)
{
- if (await _groupService.IsStaff(_workContextAccessor.WorkContext.CurrentCustomer))
- model.StoreId = _workContextAccessor.WorkContext.CurrentCustomer.StaffStoreId;
+ if (await _groupService.IsStaff(_contextAccessor.WorkContext.CurrentCustomer))
+ model.StoreId = _contextAccessor.WorkContext.CurrentCustomer.StaffStoreId;
DateTime? startDateValue = model.StartDate == null
? null
: _dateTimeService.ConvertToUtcTime(model.StartDate.Value, _dateTimeService.CurrentTimeZone);
@@ -161,8 +161,8 @@ public class PaymentTransactionController : BaseAdminController
//not found
return RedirectToAction("List", "PaymentTransaction");
- if (await _groupService.IsStaff(_workContextAccessor.WorkContext.CurrentCustomer) &&
- paymentTransaction.StoreId != _workContextAccessor.WorkContext.CurrentCustomer.StaffStoreId)
+ if (await _groupService.IsStaff(_contextAccessor.WorkContext.CurrentCustomer) &&
+ paymentTransaction.StoreId != _contextAccessor.WorkContext.CurrentCustomer.StaffStoreId)
return RedirectToAction("List", "PaymentTransaction");
return RedirectToAction("Edit", "PaymentTransaction", new { id = paymentTransaction.Id });
@@ -177,8 +177,8 @@ public class PaymentTransactionController : BaseAdminController
if (paymentTransaction == null)
return RedirectToAction("List", "PaymentTransaction");
- if (await _groupService.IsStaff(_workContextAccessor.WorkContext.CurrentCustomer) &&
- paymentTransaction.StoreId != _workContextAccessor.WorkContext.CurrentCustomer.StaffStoreId)
+ if (await _groupService.IsStaff(_contextAccessor.WorkContext.CurrentCustomer) &&
+ paymentTransaction.StoreId != _contextAccessor.WorkContext.CurrentCustomer.StaffStoreId)
return RedirectToAction("List", "PaymentTransaction");
var order = await _orderService.GetOrderByGuid(paymentTransaction.OrderGuid);
@@ -236,8 +236,8 @@ public class PaymentTransactionController : BaseAdminController
if (paymentTransaction == null)
return RedirectToAction("List", "PaymentTransaction");
- if (await _groupService.IsStaff(_workContextAccessor.WorkContext.CurrentCustomer) &&
- paymentTransaction.StoreId != _workContextAccessor.WorkContext.CurrentCustomer.StaffStoreId)
+ if (await _groupService.IsStaff(_contextAccessor.WorkContext.CurrentCustomer) &&
+ paymentTransaction.StoreId != _contextAccessor.WorkContext.CurrentCustomer.StaffStoreId)
return RedirectToAction("List", "PaymentTransaction");
try
@@ -265,8 +265,8 @@ public class PaymentTransactionController : BaseAdminController
if (paymentTransaction == null)
return RedirectToAction("List", "PaymentTransaction");
- if (await _groupService.IsStaff(_workContextAccessor.WorkContext.CurrentCustomer) &&
- paymentTransaction.StoreId != _workContextAccessor.WorkContext.CurrentCustomer.StaffStoreId)
+ if (await _groupService.IsStaff(_contextAccessor.WorkContext.CurrentCustomer) &&
+ paymentTransaction.StoreId != _contextAccessor.WorkContext.CurrentCustomer.StaffStoreId)
return RedirectToAction("List", "PaymentTransaction");
try
@@ -290,8 +290,8 @@ public class PaymentTransactionController : BaseAdminController
if (paymentTransaction == null)
return RedirectToAction("List", "PaymentTransaction");
- if (await _groupService.IsStaff(_workContextAccessor.WorkContext.CurrentCustomer) &&
- paymentTransaction.StoreId != _workContextAccessor.WorkContext.CurrentCustomer.StaffStoreId)
+ if (await _groupService.IsStaff(_contextAccessor.WorkContext.CurrentCustomer) &&
+ paymentTransaction.StoreId != _contextAccessor.WorkContext.CurrentCustomer.StaffStoreId)
return RedirectToAction("List", "PaymentTransaction");
try
@@ -318,8 +318,8 @@ public class PaymentTransactionController : BaseAdminController
if (paymentTransaction == null)
return RedirectToAction("List", "PaymentTransaction");
- if (await _groupService.IsStaff(_workContextAccessor.WorkContext.CurrentCustomer) &&
- paymentTransaction.StoreId != _workContextAccessor.WorkContext.CurrentCustomer.StaffStoreId)
+ if (await _groupService.IsStaff(_contextAccessor.WorkContext.CurrentCustomer) &&
+ paymentTransaction.StoreId != _contextAccessor.WorkContext.CurrentCustomer.StaffStoreId)
return RedirectToAction("List", "PaymentTransaction");
try
@@ -343,8 +343,8 @@ public class PaymentTransactionController : BaseAdminController
if (paymentTransaction == null)
return RedirectToAction("List", "PaymentTransaction");
- if (await _groupService.IsStaff(_workContextAccessor.WorkContext.CurrentCustomer) &&
- paymentTransaction.StoreId != _workContextAccessor.WorkContext.CurrentCustomer.StaffStoreId)
+ if (await _groupService.IsStaff(_contextAccessor.WorkContext.CurrentCustomer) &&
+ paymentTransaction.StoreId != _contextAccessor.WorkContext.CurrentCustomer.StaffStoreId)
return RedirectToAction("List", "PaymentTransaction");
try
@@ -371,8 +371,8 @@ public class PaymentTransactionController : BaseAdminController
if (paymentTransaction == null)
return RedirectToAction("List", "PaymentTransaction");
- if (await _groupService.IsStaff(_workContextAccessor.WorkContext.CurrentCustomer) &&
- paymentTransaction.StoreId != _workContextAccessor.WorkContext.CurrentCustomer.StaffStoreId)
+ if (await _groupService.IsStaff(_contextAccessor.WorkContext.CurrentCustomer) &&
+ paymentTransaction.StoreId != _contextAccessor.WorkContext.CurrentCustomer.StaffStoreId)
return RedirectToAction("List", "PaymentTransaction");
try
@@ -395,8 +395,8 @@ public class PaymentTransactionController : BaseAdminController
if (paymentTransaction == null)
return RedirectToAction("List", "PaymentTransaction");
- if (await _groupService.IsStaff(_workContextAccessor.WorkContext.CurrentCustomer) &&
- paymentTransaction.StoreId != _workContextAccessor.WorkContext.CurrentCustomer.StaffStoreId)
+ if (await _groupService.IsStaff(_contextAccessor.WorkContext.CurrentCustomer) &&
+ paymentTransaction.StoreId != _contextAccessor.WorkContext.CurrentCustomer.StaffStoreId)
return RedirectToAction("List", "PaymentTransaction");
var model = new PaymentTransactionModel {
@@ -416,8 +416,8 @@ public class PaymentTransactionController : BaseAdminController
if (paymentTransaction == null)
return RedirectToAction("List", "PaymentTransaction");
- if (await _groupService.IsStaff(_workContextAccessor.WorkContext.CurrentCustomer) &&
- paymentTransaction.StoreId != _workContextAccessor.WorkContext.CurrentCustomer.StaffStoreId)
+ if (await _groupService.IsStaff(_contextAccessor.WorkContext.CurrentCustomer) &&
+ paymentTransaction.StoreId != _contextAccessor.WorkContext.CurrentCustomer.StaffStoreId)
return RedirectToAction("List", "PaymentTransaction");
try
@@ -466,8 +466,8 @@ public class PaymentTransactionController : BaseAdminController
if (paymentTransaction == null)
return RedirectToAction("List", "PaymentTransaction");
- if (await _groupService.IsStaff(_workContextAccessor.WorkContext.CurrentCustomer) &&
- paymentTransaction.StoreId != _workContextAccessor.WorkContext.CurrentCustomer.StaffStoreId)
+ if (await _groupService.IsStaff(_contextAccessor.WorkContext.CurrentCustomer) &&
+ paymentTransaction.StoreId != _contextAccessor.WorkContext.CurrentCustomer.StaffStoreId)
return RedirectToAction("List", "PaymentTransaction");
var model = new PaymentTransactionModel {
@@ -487,8 +487,8 @@ public class PaymentTransactionController : BaseAdminController
if (paymentTransaction == null)
return RedirectToAction("List", "PaymentTransaction");
- if (await _groupService.IsStaff(_workContextAccessor.WorkContext.CurrentCustomer) &&
- paymentTransaction.StoreId != _workContextAccessor.WorkContext.CurrentCustomer.StaffStoreId)
+ if (await _groupService.IsStaff(_contextAccessor.WorkContext.CurrentCustomer) &&
+ paymentTransaction.StoreId != _contextAccessor.WorkContext.CurrentCustomer.StaffStoreId)
return RedirectToAction("List", "PaymentTransaction");
try
@@ -523,8 +523,8 @@ public class PaymentTransactionController : BaseAdminController
if (paymentTransaction == null)
return RedirectToAction("List");
- if (await _groupService.IsStaff(_workContextAccessor.WorkContext.CurrentCustomer) &&
- paymentTransaction.StoreId != _workContextAccessor.WorkContext.CurrentCustomer.StaffStoreId)
+ if (await _groupService.IsStaff(_contextAccessor.WorkContext.CurrentCustomer) &&
+ paymentTransaction.StoreId != _contextAccessor.WorkContext.CurrentCustomer.StaffStoreId)
return RedirectToAction("List", "MerchandiseReturn");
if (ModelState.IsValid)
{
diff --git a/src/Web/Grand.Web.Admin/Controllers/PermissionController.cs b/src/Web/Grand.Web.Admin/Controllers/PermissionController.cs
index 4ab0836d0..a8632b632 100644
--- a/src/Web/Grand.Web.Admin/Controllers/PermissionController.cs
+++ b/src/Web/Grand.Web.Admin/Controllers/PermissionController.cs
@@ -18,12 +18,12 @@ public class PermissionController : BaseAdminController
{
#region Constructors
- public PermissionController(IWorkContextAccessor workContextAccessor,
+ public PermissionController(IContextAccessor contextAccessor,
IPermissionService permissionService,
IGroupService groupService,
ITranslationService translationService)
{
- _workContextAccessor = workContextAccessor;
+ _contextAccessor = contextAccessor;
_permissionService = permissionService;
_groupService = groupService;
_translationService = translationService;
@@ -33,7 +33,7 @@ public class PermissionController : BaseAdminController
#region Fields
- private readonly IWorkContextAccessor _workContextAccessor;
+ private readonly IContextAccessor _contextAccessor;
private readonly IPermissionService _permissionService;
private readonly IGroupService _groupService;
private readonly ITranslationService _translationService;
@@ -50,7 +50,7 @@ public class PermissionController : BaseAdminController
var customerGroups = await _groupService.GetAllCustomerGroups(showHidden: true);
foreach (var pr in permissionRecords.OrderBy(x => x.Category))
model.AvailablePermissions.Add(new PermissionRecordModel {
- Name =_translationService.GetResource(pr.GetTranslationPermissionName(), _workContextAccessor.WorkContext.WorkingLanguage.Id),
+ Name =_translationService.GetResource(pr.GetTranslationPermissionName(), _contextAccessor.WorkContext.WorkingLanguage.Id),
SystemName = pr.SystemName,
Area = pr.Area,
Category = pr.Category,
@@ -169,7 +169,7 @@ public class PermissionController : BaseAdminController
if (permissionRecord != null)
{
model.AvailableActions = permissionRecord.Actions.ToList();
- model.PermissionName = _translationService.GetResource(permissionRecord.GetTranslationPermissionName(), _workContextAccessor.WorkContext.WorkingLanguage.Id);
+ model.PermissionName = _translationService.GetResource(permissionRecord.GetTranslationPermissionName(), _contextAccessor.WorkContext.WorkingLanguage.Id);
}
else
{
diff --git a/src/Web/Grand.Web.Admin/Controllers/PluginController.cs b/src/Web/Grand.Web.Admin/Controllers/PluginController.cs
index 9ee83531f..148cf1b5b 100644
--- a/src/Web/Grand.Web.Admin/Controllers/PluginController.cs
+++ b/src/Web/Grand.Web.Admin/Controllers/PluginController.cs
@@ -25,7 +25,7 @@ public class PluginController(
ITranslationService translationService,
ILogger<PluginController> logger,
IHostApplicationLifetime applicationLifetime,
- IWorkContextAccessor workContextAccessor,
+ IContextAccessor contextAccessor,
IServiceProvider serviceProvider,
IEnumTranslationService enumTranslationService,
IWebHostEnvironment webHostEnvironment,
@@ -34,12 +34,14 @@ public class PluginController(
{
#region Utilities
+ private readonly string PluginsPath = Path.Combine(webHostEnvironment.ContentRootPath, CommonPath.Plugins);
+
[NonAction]
protected virtual PluginModel PreparePluginModel(PluginInfo PluginInfo)
{
var pluginModel = PluginInfo.ToModel();
//logo
- pluginModel.LogoUrl = PluginInfo.GetLogoUrl(workContextAccessor.WorkContext.CurrentHost.Url);
+ pluginModel.LogoUrl = PluginInfo.GetLogoUrl(contextAccessor.StoreContext.CurrentHost.Url);
//configuration URLs
if (PluginInfo.Installed)
@@ -65,18 +67,9 @@ public class PluginController(
foreach (var directory in Directory.GetDirectories(path)) DeleteDirectory(directory);
- try
- {
+ if (Directory.Exists(path) && path.StartsWith(PluginsPath, StringComparison.Ordinal))
Directory.Delete(path, true);
- }
- catch (IOException)
- {
- Directory.Delete(path, true);
- }
- catch (UnauthorizedAccessException)
- {
- Directory.Delete(path, true);
- }
+
}
protected byte[] ToByteArray(Stream stream)
@@ -162,7 +155,7 @@ public class PluginController(
Success(translationService.GetResource("Admin.Plugins.Installed"));
logger.LogInformation("The plugin has been installed by the user {CurrentCustomerEmail}",
- workContextAccessor.WorkContext.CurrentCustomer.Email);
+ contextAccessor.WorkContext.CurrentCustomer.Email);
//stop application
applicationLifetime.StopApplication();
@@ -196,7 +189,7 @@ public class PluginController(
Success(translationService.GetResource("Admin.Plugins.Uninstalled"));
logger.LogInformation("The plugin has been uninstalled by the user {CurrentCustomerEmail}",
- workContextAccessor.WorkContext.CurrentCustomer.Email);
+ contextAccessor.WorkContext.CurrentCustomer.Email);
//stop application
applicationLifetime.StopApplication();
@@ -225,18 +218,13 @@ public class PluginController(
//No plugin found with the specified id
return RedirectToAction("List");
- var pluginsPath = "Plugins";
-
- foreach (var folder in Directory.GetDirectories(pluginsPath))
- if (Path.GetFileName(folder) != "bin" && Directory.GetFiles(folder).Select(x => Path.GetFileName(x))
- .Contains(pluginInfo.PluginFileName))
- DeleteDirectory(folder);
+ DeleteDirectory(pluginInfo.OriginalAssemblyFile.DirectoryName);
//uninstall plugin
Success(translationService.GetResource("Admin.Plugins.Removed"));
logger.LogInformation("The plugin has been removed by the user {CurrentCustomerEmail}",
- workContextAccessor.WorkContext.CurrentCustomer.Email);
+ contextAccessor.WorkContext.CurrentCustomer.Email);
//stop application
applicationLifetime.StopApplication();
@@ -252,7 +240,7 @@ public class PluginController(
public IActionResult ReloadList()
{
logger.LogInformation("Reload list of plugins by the user {CurrentCustomerEmail}",
- workContextAccessor.WorkContext.CurrentCustomer.Email);
+ contextAccessor.WorkContext.CurrentCustomer.Email);
//stop application
applicationLifetime.StopApplication();
@@ -281,11 +269,14 @@ public class PluginController(
if (!Path.GetExtension(zippedFile.FileName).Equals(".zip", StringComparison.InvariantCultureIgnoreCase))
throw new Exception("Only zip archives are supported");
- //ensure that temp directory is created
+ // Ensure that temp directory is created
Directory.CreateDirectory(new DirectoryInfo(tempDirectory).FullName);
- //copy original archive to the temp directory
- zipFilePath = Path.Combine(tempDirectory, zippedFile.FileName);
+ // Generate a unique file name for the uploaded file
+ var uniqueFileName = Guid.NewGuid().ToString() + ".zip";
+ zipFilePath = Path.Combine(tempDirectory, uniqueFileName);
+
+ // Copy original archive to the temp directory
using (var fileStream = new FileStream(zipFilePath, FileMode.Create))
{
zippedFile.CopyTo(fileStream);
@@ -298,13 +289,12 @@ public class PluginController(
}
finally
{
- //delete temporary file
- if(Directory.Exists(tempDirectory))
- DeleteDirectory(tempDirectory);
+ // Delete temporary file
+ DeleteDirectory(tempDirectory);
}
logger.LogInformation("The plugin has been uploaded by the user {CurrentCustomerEmail}",
- workContextAccessor.WorkContext.CurrentCustomer.Email);
+ contextAccessor.WorkContext.CurrentCustomer.Email);
//stop application
applicationLifetime.StopApplication();
@@ -389,8 +379,7 @@ public class PluginController(
try
{
- if (Directory.Exists(pathToUpload))
- DeleteDirectory(pathToUpload);
+ DeleteDirectory(pathToUpload);
}
catch { }
diff --git a/src/Web/Grand.Web.Admin/Controllers/ProductAttributeController.cs b/src/Web/Grand.Web.Admin/Controllers/ProductAttributeController.cs
index 816692377..a99203f30 100644
--- a/src/Web/Grand.Web.Admin/Controllers/ProductAttributeController.cs
+++ b/src/Web/Grand.Web.Admin/Controllers/ProductAttributeController.cs
@@ -24,7 +24,7 @@ public class ProductAttributeController : BaseAdminController
IProductAttributeService productAttributeService,
ILanguageService languageService,
ITranslationService translationService,
- IWorkContextAccessor workContextAccessor,
+ IContextAccessor contextAccessor,
IGroupService groupService,
SeoSettings seoSettings)
{
@@ -32,7 +32,7 @@ public class ProductAttributeController : BaseAdminController
_productAttributeService = productAttributeService;
_languageService = languageService;
_translationService = translationService;
- _workContextAccessor = workContextAccessor;
+ _contextAccessor = contextAccessor;
_groupService = groupService;
_seoSettings = seoSettings;
}
@@ -45,7 +45,7 @@ public class ProductAttributeController : BaseAdminController
private readonly IProductAttributeService _productAttributeService;
private readonly ILanguageService _languageService;
private readonly ITranslationService _translationService;
- private readonly IWorkContextAccessor _workContextAccessor;
+ private readonly IContextAccessor _contextAccessor;
private readonly IGroupService _groupService;
private readonly SeoSettings _seoSettings;
@@ -102,8 +102,8 @@ public class ProductAttributeController : BaseAdminController
string.IsNullOrEmpty(productAttribute.SeName) ? productAttribute.Name : productAttribute.SeName,
_seoSettings.ConvertNonWesternChars, _seoSettings.AllowUnicodeCharsInUrls,
_seoSettings.SeoCharConversion);
- if (await _groupService.IsStaff(_workContextAccessor.WorkContext.CurrentCustomer))
- model.Stores = [_workContextAccessor.WorkContext.CurrentCustomer.StaffStoreId];
+ if (await _groupService.IsStaff(_contextAccessor.WorkContext.CurrentCustomer))
+ model.Stores = [_contextAccessor.WorkContext.CurrentCustomer.StaffStoreId];
await _productAttributeService.InsertProductAttribute(productAttribute);
@@ -154,8 +154,8 @@ public class ProductAttributeController : BaseAdminController
string.IsNullOrEmpty(productAttribute.SeName) ? productAttribute.Name : productAttribute.SeName,
_seoSettings.ConvertNonWesternChars, _seoSettings.AllowUnicodeCharsInUrls,
_seoSettings.SeoCharConversion);
- if (await _groupService.IsStaff(_workContextAccessor.WorkContext.CurrentCustomer))
- model.Stores = [_workContextAccessor.WorkContext.CurrentCustomer.StaffStoreId];
+ if (await _groupService.IsStaff(_contextAccessor.WorkContext.CurrentCustomer))
+ model.Stores = [_contextAccessor.WorkContext.CurrentCustomer.StaffStoreId];
await _productAttributeService.UpdateProductAttribute(productAttribute);
Success(_translationService.GetResource("Admin.Catalog.Attributes.ProductAttributes.Updated"));
diff --git a/src/Web/Grand.Web.Admin/Controllers/ProductController.cs b/src/Web/Grand.Web.Admin/Controllers/ProductController.cs
index 8941dc5aa..85b6f30e0 100644
--- a/src/Web/Grand.Web.Admin/Controllers/ProductController.cs
+++ b/src/Web/Grand.Web.Admin/Controllers/ProductController.cs
@@ -25,6 +25,7 @@ using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.Rendering;
using Microsoft.AspNetCore.StaticFiles;
+using Grand.Web.Common.Helpers;
namespace Grand.Web.Admin.Controllers;
@@ -37,7 +38,7 @@ public class ProductController : BaseAdminController
IProductViewModelService productViewModelService,
IProductService productService,
IInventoryManageService inventoryManageService,
- IWorkContextAccessor workContextAccessor,
+ IContextAccessor contextAccessor,
IGroupService groupService,
ILanguageService languageService,
ITranslationService translationService,
@@ -50,7 +51,7 @@ public class ProductController : BaseAdminController
_productViewModelService = productViewModelService;
_productService = productService;
_inventoryManageService = inventoryManageService;
- _workContextAccessor = workContextAccessor;
+ _contextAccessor = contextAccessor;
_groupService = groupService;
_languageService = languageService;
_translationService = translationService;
@@ -68,7 +69,7 @@ public class ProductController : BaseAdminController
private readonly IProductViewModelService _productViewModelService;
private readonly IProductService _productService;
private readonly IInventoryManageService _inventoryManageService;
- private readonly IWorkContextAccessor _workContextAccessor;
+ private readonly IContextAccessor _contextAccessor;
private readonly IGroupService _groupService;
private readonly ILanguageService _languageService;
private readonly ITranslationService _translationService;
@@ -85,10 +86,8 @@ public class ProductController : BaseAdminController
protected async Task<(bool allow, string message)> CheckAccessToProduct(Product product)
{
if (product == null) return (false, "Product not exists");
- if (await _groupService.IsStaff(_workContextAccessor.WorkContext.CurrentCustomer))
- if (!(!product.LimitedToStores || (product.Stores.Contains(_workContextAccessor.WorkContext.CurrentCustomer.StaffStoreId) &&
- product.LimitedToStores)))
- return (false, "This is not your product");
+ if (await _groupService.IsStaff(_contextAccessor.WorkContext.CurrentCustomer) && !(!product.LimitedToStores || (product.Stores.Contains(_contextAccessor.WorkContext.CurrentCustomer.StaffStoreId) && product.LimitedToStores)))
+ return (false, "This is not your product");
return (true, null);
}
@@ -130,9 +129,9 @@ public class ProductController : BaseAdminController
var product = await _productService.GetProductBySku(sku);
if (product != null)
{
- if (await _groupService.IsStaff(_workContextAccessor.WorkContext.CurrentCustomer))
+ if (await _groupService.IsStaff(_contextAccessor.WorkContext.CurrentCustomer))
{
- if (!product.LimitedToStores || (product.Stores.Contains(_workContextAccessor.WorkContext.CurrentCustomer.StaffStoreId) &&
+ if (!product.LimitedToStores || (product.Stores.Contains(_contextAccessor.WorkContext.CurrentCustomer.StaffStoreId) &&
product.LimitedToStores))
return RedirectToAction("Edit", new { id = product.Id });
return RedirectToAction("List", "Product");
@@ -181,17 +180,17 @@ public class ProductController : BaseAdminController
if (product == null)
//No product found with the specified id
return RedirectToAction("List");
- if (await _groupService.IsStaff(_workContextAccessor.WorkContext.CurrentCustomer))
+ if (await _groupService.IsStaff(_contextAccessor.WorkContext.CurrentCustomer))
{
if (!product.LimitedToStores || (product.LimitedToStores &&
- product.Stores.Contains(_workContextAccessor.WorkContext.CurrentCustomer.StaffStoreId) &&
+ product.Stores.Contains(_contextAccessor.WorkContext.CurrentCustomer.StaffStoreId) &&
product.Stores.Count > 1))
{
Warning(_translationService.GetResource("Admin.Catalog.Products.Permissions"));
}
else
{
- if (!product.AccessToEntityByStore(_workContextAccessor.WorkContext.CurrentCustomer.StaffStoreId))
+ if (!product.AccessToEntityByStore(_contextAccessor.WorkContext.CurrentCustomer.StaffStoreId))
return RedirectToAction("List");
}
}
@@ -224,9 +223,8 @@ public class ProductController : BaseAdminController
//No product found with the specified id
return RedirectToAction("List");
- if (await _groupService.IsStaff(_workContextAccessor.WorkContext.CurrentCustomer))
- if (!product.AccessToEntityByStore(_workContextAccessor.WorkContext.CurrentCustomer.StaffStoreId))
- return RedirectToAction("Edit", new { id = product.Id });
+ if (await _groupService.IsStaff(_contextAccessor.WorkContext.CurrentCustomer) && !product.AccessToEntityByStore(_contextAccessor.WorkContext.CurrentCustomer.StaffStoreId))
+ return RedirectToAction("Edit", new { id = product.Id });
if (model.Ticks != product.Ticks)
{
@@ -264,9 +262,8 @@ public class ProductController : BaseAdminController
//No product found with the specified id
return RedirectToAction("List");
- if (await _groupService.IsStaff(_workContextAccessor.WorkContext.CurrentCustomer))
- if (!product.AccessToEntityByStore(_workContextAccessor.WorkContext.CurrentCustomer.StaffStoreId))
- return RedirectToAction("Edit", new { id = product.Id });
+ if (await _groupService.IsStaff(_contextAccessor.WorkContext.CurrentCustomer) && !product.AccessToEntityByStore(_contextAccessor.WorkContext.CurrentCustomer.StaffStoreId))
+ return RedirectToAction("Edit", new { id = product.Id });
if (ModelState.IsValid)
{
@@ -297,11 +294,11 @@ public class ProductController : BaseAdminController
try
{
var originalProduct = await _productService.GetProductById(copyModel.Id, true);
- if (await _groupService.IsStaff(_workContextAccessor.WorkContext.CurrentCustomer))
+ if (await _groupService.IsStaff(_contextAccessor.WorkContext.CurrentCustomer))
{
originalProduct.LimitedToStores = true;
originalProduct.Stores.Clear();
- originalProduct.Stores.Add(_workContextAccessor.WorkContext.CurrentCustomer.StaffStoreId);
+ originalProduct.Stores.Add(_contextAccessor.WorkContext.CurrentCustomer.StaffStoreId);
}
var newProduct = await copyProductService.CopyProduct(originalProduct,
@@ -1146,12 +1143,12 @@ public class ProductController : BaseAdminController
});
var product = await _productService.GetProductById(objectId);
- if (await _groupService.IsStaff(_workContextAccessor.WorkContext.CurrentCustomer))
- if (!product.AccessToEntityByStore(_workContextAccessor.WorkContext.CurrentCustomer.StaffStoreId))
- return Json(new {
- success = false,
- message = "Access denied - staff permissions"
- });
+ if (await _groupService.IsStaff(_contextAccessor.WorkContext.CurrentCustomer) && !product.AccessToEntityByStore(_contextAccessor.WorkContext.CurrentCustomer.StaffStoreId))
+ return Json(new
+ {
+ success = false,
+ message = "Access denied - staff permissions"
+ });
var values = new List<(string pictureUrl, string pictureId)>();
foreach (var file in httpPostedFiles)
@@ -1419,8 +1416,8 @@ public class ProductController : BaseAdminController
ProductId = productId
};
- if (await _groupService.IsStaff(_workContextAccessor.WorkContext.CurrentCustomer))
- model.StoreId = _workContextAccessor.WorkContext.CurrentCustomer.StaffStoreId;
+ if (await _groupService.IsStaff(_contextAccessor.WorkContext.CurrentCustomer))
+ model.StoreId = _contextAccessor.WorkContext.CurrentCustomer.StaffStoreId;
var (orderModels, totalCount) =
await orderViewModelService.PrepareOrderModel(model, command.Page, command.PageSize);
@@ -1447,8 +1444,8 @@ public class ProductController : BaseAdminController
return ErrorForKendoGridJson(permission.message);
var storeId = string.Empty;
- if (await _groupService.IsStaff(_workContextAccessor.WorkContext.CurrentCustomer))
- storeId = _workContextAccessor.WorkContext.CurrentCustomer.StaffStoreId;
+ if (await _groupService.IsStaff(_contextAccessor.WorkContext.CurrentCustomer))
+ storeId = _contextAccessor.WorkContext.CurrentCustomer.StaffStoreId;
var productReviews = await productReviewService.GetAllProductReviews("", null,
null, null, "", storeId, productId);
@@ -1596,7 +1593,8 @@ public class ProductController : BaseAdminController
items.Add(new ProductModel.ProductPriceModel {
Id = item.Id,
CurrencyCode = item.CurrencyCode,
- Price = item.Price
+ Price = item.Price,
+ ProductId = product.Id
});
var gridModel = new DataSourceResult {
@@ -1609,9 +1607,9 @@ public class ProductController : BaseAdminController
[PermissionAuthorizeAction(PermissionActionName.Edit)]
[HttpPost]
- public async Task<IActionResult> ProductPriceInsert(string productId, ProductModel.ProductPriceModel model)
+ public async Task<IActionResult> ProductPriceInsert(ProductModel.ProductPriceModel model)
{
- var product = await _productService.GetProductById(productId);
+ var product = await _productService.GetProductById(model.ProductId);
if (product == null)
throw new ArgumentException("No product found with the specified id");
@@ -1638,9 +1636,9 @@ public class ProductController : BaseAdminController
[PermissionAuthorizeAction(PermissionActionName.Edit)]
[HttpPost]
- public async Task<IActionResult> ProductPriceUpdate(string productId, ProductModel.ProductPriceModel model)
+ public async Task<IActionResult> ProductPriceUpdate(ProductModel.ProductPriceModel model)
{
- var product = await _productService.GetProductById(productId);
+ var product = await _productService.GetProductById(model.ProductId);
if (product == null)
throw new ArgumentException("No product found with the specified id");
@@ -1656,7 +1654,7 @@ public class ProductController : BaseAdminController
{
productPrice!.CurrencyCode = model.CurrencyCode;
productPrice.Price = model.Price;
- productPrice.ProductId = productId;
+ productPrice.ProductId = model.ProductId;
await _productService.UpdateProductPrice(productPrice);
@@ -1672,9 +1670,9 @@ public class ProductController : BaseAdminController
[PermissionAuthorizeAction(PermissionActionName.Edit)]
[HttpPost]
- public async Task<IActionResult> ProductPriceDelete(string productId, ProductModel.ProductPriceModel model)
+ public async Task<IActionResult> ProductPriceDelete(ProductModel.ProductPriceModel model)
{
- var product = await _productService.GetProductById(productId);
+ var product = await _productService.GetProductById(model.ProductId);
if (product == null)
throw new ArgumentException("No product found with the specified id");
@@ -1684,7 +1682,7 @@ public class ProductController : BaseAdminController
if (ModelState.IsValid)
{
- productPrice!.ProductId = productId;
+ productPrice!.ProductId = model.ProductId;
await _productService.DeleteProductPrice(productPrice);
return new JsonResult("");
@@ -1894,9 +1892,8 @@ public class ProductController : BaseAdminController
if (productAttributeMapping == null)
throw new ArgumentException("No product attribute mapping found with the specified id");
- if (await _groupService.IsStaff(_workContextAccessor.WorkContext.CurrentCustomer))
- if (!product.AccessToEntityByStore(_workContextAccessor.WorkContext.CurrentCustomer.StaffStoreId))
- return ErrorForKendoGridJson(_translationService.GetResource("Admin.Catalog.Products.Permissions"));
+ if (await _groupService.IsStaff(_contextAccessor.WorkContext.CurrentCustomer) && !product.AccessToEntityByStore(_contextAccessor.WorkContext.CurrentCustomer.StaffStoreId))
+ return ErrorForKendoGridJson(_translationService.GetResource("Admin.Catalog.Products.Permissions"));
await productAttributeService.DeleteProductAttributeMapping(productAttributeMapping, product.Id);
return new JsonResult("");
@@ -1982,9 +1979,8 @@ public class ProductController : BaseAdminController
if (productAttributeMapping == null)
return Content("No attribute value found with the specified id");
- if (await _groupService.IsStaff(_workContextAccessor.WorkContext.CurrentCustomer))
- if (!product.AccessToEntityByStore(_workContextAccessor.WorkContext.CurrentCustomer.StaffStoreId))
- return Content(_translationService.GetResource("Admin.Catalog.Products.Permissions"));
+ if (await _groupService.IsStaff(_contextAccessor.WorkContext.CurrentCustomer) && !product.AccessToEntityByStore(_contextAccessor.WorkContext.CurrentCustomer.StaffStoreId))
+ return Content(_translationService.GetResource("Admin.Catalog.Products.Permissions"));
await _productViewModelService.UpdateProductAttributeConditionModel(product, productAttributeMapping, model);
return Content("");
@@ -2008,10 +2004,8 @@ public class ProductController : BaseAdminController
if (productAttributeMapping == null)
throw new ArgumentException("No product attribute mapping found with the specified id");
- if (await _groupService.IsStaff(_workContextAccessor.WorkContext.CurrentCustomer))
- if (!(!product.LimitedToStores || (product.Stores.Contains(_workContextAccessor.WorkContext.CurrentCustomer.StaffStoreId) &&
- product.LimitedToStores)))
- return Content("This is not your product");
+ if (await _groupService.IsStaff(_contextAccessor.WorkContext.CurrentCustomer) && !(!product.LimitedToStores || (product.Stores.Contains(_contextAccessor.WorkContext.CurrentCustomer.StaffStoreId) && product.LimitedToStores)))
+ return Content("This is not your product");
var productAttribute =
await productAttributeService.GetProductAttributeById(productAttributeMapping.ProductAttributeId);
var model = new ProductModel.ProductAttributeValueListModel {
@@ -2169,9 +2163,8 @@ public class ProductController : BaseAdminController
if (pav == null)
throw new ArgumentException("No product attribute value found with the specified id");
- if (await _groupService.IsStaff(_workContextAccessor.WorkContext.CurrentCustomer))
- if (!product.AccessToEntityByStore(_workContextAccessor.WorkContext.CurrentCustomer.StaffStoreId))
- throw new ArgumentException(_translationService.GetResource("Admin.Catalog.Products.Permissions"));
+ if (await _groupService.IsStaff(_contextAccessor.WorkContext.CurrentCustomer) && !product.AccessToEntityByStore(_contextAccessor.WorkContext.CurrentCustomer.StaffStoreId))
+ throw new ArgumentException(_translationService.GetResource("Admin.Catalog.Products.Permissions"));
if (ModelState.IsValid)
{
@@ -2249,9 +2242,8 @@ public class ProductController : BaseAdminController
if (combination == null)
throw new ArgumentException("No product attribute combination found with the specified id");
- if (await _groupService.IsStaff(_workContextAccessor.WorkContext.CurrentCustomer))
- if (!product.AccessToEntityByStore(_workContextAccessor.WorkContext.CurrentCustomer.StaffStoreId))
- return Content(_translationService.GetResource("Admin.Catalog.Products.Permissions"));
+ if (await _groupService.IsStaff(_contextAccessor.WorkContext.CurrentCustomer) && !product.AccessToEntityByStore(_contextAccessor.WorkContext.CurrentCustomer.StaffStoreId))
+ return Content(_translationService.GetResource("Admin.Catalog.Products.Permissions"));
await productAttributeService.DeleteProductAttributeCombination(combination, productId);
if (product.ManageInventoryMethodId == ManageInventoryMethod.ManageStockByAttributes)
@@ -2290,9 +2282,8 @@ public class ProductController : BaseAdminController
//No product found with the specified id
return RedirectToAction("List", "Product");
- if (await _groupService.IsStaff(_workContextAccessor.WorkContext.CurrentCustomer))
- if (!product.AccessToEntityByStore(_workContextAccessor.WorkContext.CurrentCustomer.StaffStoreId))
- return Content(_translationService.GetResource("Admin.Catalog.Products.Permissions"));
+ if (await _groupService.IsStaff(_contextAccessor.WorkContext.CurrentCustomer) && !product.AccessToEntityByStore(_contextAccessor.WorkContext.CurrentCustomer.StaffStoreId))
+ return Content(_translationService.GetResource("Admin.Catalog.Products.Permissions"));
var warnings = await _productViewModelService.InsertOrUpdateProductAttributeCombinationPopup(product, model);
if (!warnings.Any()) return Content("");
@@ -2310,9 +2301,8 @@ public class ProductController : BaseAdminController
if (product == null)
throw new ArgumentException("No product found with the specified id");
- if (await _groupService.IsStaff(_workContextAccessor.WorkContext.CurrentCustomer))
- if (!product.AccessToEntityByStore(_workContextAccessor.WorkContext.CurrentCustomer.StaffStoreId))
- return Content(_translationService.GetResource("Admin.Catalog.Products.Permissions"));
+ if (await _groupService.IsStaff(_contextAccessor.WorkContext.CurrentCustomer) && !product.AccessToEntityByStore(_contextAccessor.WorkContext.CurrentCustomer.StaffStoreId))
+ return Content(_translationService.GetResource("Admin.Catalog.Products.Permissions"));
await _productViewModelService.GenerateAllAttributeCombinations(product);
@@ -2327,9 +2317,8 @@ public class ProductController : BaseAdminController
if (product == null)
throw new ArgumentException("No product found with the specified id");
- if (await _groupService.IsStaff(_workContextAccessor.WorkContext.CurrentCustomer))
- if (!product.AccessToEntityByStore(_workContextAccessor.WorkContext.CurrentCustomer.StaffStoreId))
- throw new ArgumentException(_translationService.GetResource("Admin.Catalog.Products.Permissions"));
+ if (await _groupService.IsStaff(_contextAccessor.WorkContext.CurrentCustomer) && !product.AccessToEntityByStore(_contextAccessor.WorkContext.CurrentCustomer.StaffStoreId))
+ throw new ArgumentException(_translationService.GetResource("Admin.Catalog.Products.Permissions"));
if (ModelState.IsValid)
{
@@ -2381,9 +2370,8 @@ public class ProductController : BaseAdminController
if (product == null)
throw new ArgumentException("No product found with the specified id");
- if (await _groupService.IsStaff(_workContextAccessor.WorkContext.CurrentCustomer))
- if (!product.AccessToEntityByStore(_workContextAccessor.WorkContext.CurrentCustomer.StaffStoreId))
- return Content("", _translationService.GetResource("Admin.Catalog.Products.Permissions"));
+ if (await _groupService.IsStaff(_contextAccessor.WorkContext.CurrentCustomer) && !product.AccessToEntityByStore(_contextAccessor.WorkContext.CurrentCustomer.StaffStoreId))
+ return Content("", _translationService.GetResource("Admin.Catalog.Products.Permissions"));
var combination =
product.ProductAttributeCombinations.FirstOrDefault(x => x.Id == productAttributeCombinationId);
@@ -2403,9 +2391,8 @@ public class ProductController : BaseAdminController
if (product == null)
throw new ArgumentException("No product found with the specified id");
- if (await _groupService.IsStaff(_workContextAccessor.WorkContext.CurrentCustomer))
- if (!product.AccessToEntityByStore(_workContextAccessor.WorkContext.CurrentCustomer.StaffStoreId))
- return Content("", _translationService.GetResource("Admin.Catalog.Products.Permissions"));
+ if (await _groupService.IsStaff(_contextAccessor.WorkContext.CurrentCustomer) && !product.AccessToEntityByStore(_contextAccessor.WorkContext.CurrentCustomer.StaffStoreId))
+ return Content("", _translationService.GetResource("Admin.Catalog.Products.Permissions"));
var combination =
product.ProductAttributeCombinations.FirstOrDefault(x => x.Id == productAttributeCombinationId);
@@ -2425,9 +2412,8 @@ public class ProductController : BaseAdminController
if (product == null)
throw new ArgumentException("No product found with the specified id");
- if (await _groupService.IsStaff(_workContextAccessor.WorkContext.CurrentCustomer))
- if (!product.AccessToEntityByStore(_workContextAccessor.WorkContext.CurrentCustomer.StaffStoreId))
- return ErrorForKendoGridJson(_translationService.GetResource("Admin.Catalog.Products.Permissions"));
+ if (await _groupService.IsStaff(_contextAccessor.WorkContext.CurrentCustomer) && !product.AccessToEntityByStore(_contextAccessor.WorkContext.CurrentCustomer.StaffStoreId))
+ return ErrorForKendoGridJson(_translationService.GetResource("Admin.Catalog.Products.Permissions"));
var combination =
product.ProductAttributeCombinations.FirstOrDefault(x => x.Id == productAttributeCombinationId);
@@ -2488,9 +2474,8 @@ public class ProductController : BaseAdminController
if (product == null)
throw new ArgumentException("No product found with the specified id");
- if (await _groupService.IsStaff(_workContextAccessor.WorkContext.CurrentCustomer))
- if (!product.AccessToEntityByStore(_workContextAccessor.WorkContext.CurrentCustomer.StaffStoreId))
- return Json(new { errors = _translationService.GetResource("Admin.Catalog.Products.Permissions") });
+ if (await _groupService.IsStaff(_contextAccessor.WorkContext.CurrentCustomer) && !product.AccessToEntityByStore(_contextAccessor.WorkContext.CurrentCustomer.StaffStoreId))
+ return Json(new { errors = _translationService.GetResource("Admin.Catalog.Products.Permissions") });
var reservations = await _productReservationService.GetProductReservationsByProductId(productId, null, null);
if (reservations.Any())
@@ -2584,7 +2569,7 @@ public class ProductController : BaseAdminController
(iterator.DayOfWeek == DayOfWeek.Sunday && !model.Sunday))
continue;
- for (var i = 0; i < model.Quantity; i++)
+ for (var i = 0; i < model.Quantity.MaxQuantity(); i++)
{
dates.Add(iterator);
try
@@ -2622,9 +2607,8 @@ public class ProductController : BaseAdminController
if (product == null)
throw new ArgumentException("No product found with the specified id");
- if (await _groupService.IsStaff(_workContextAccessor.WorkContext.CurrentCustomer))
- if (!product.AccessToEntityByStore(_workContextAccessor.WorkContext.CurrentCustomer.StaffStoreId))
- return Json(new { errors = _translationService.GetResource("Admin.Catalog.Products.Permissions") });
+ if (await _groupService.IsStaff(_contextAccessor.WorkContext.CurrentCustomer) && !product.AccessToEntityByStore(_contextAccessor.WorkContext.CurrentCustomer.StaffStoreId))
+ return Json(new { errors = _translationService.GetResource("Admin.Catalog.Products.Permissions") });
var toDelete = await _productReservationService.GetProductReservationsByProductId(productId, true, null);
foreach (var record in toDelete) await _productReservationService.DeleteProductReservation(record);
@@ -2639,9 +2623,8 @@ public class ProductController : BaseAdminController
if (product == null)
throw new ArgumentException("No product found with the specified id");
- if (await _groupService.IsStaff(_workContextAccessor.WorkContext.CurrentCustomer))
- if (!product.AccessToEntityByStore(_workContextAccessor.WorkContext.CurrentCustomer.StaffStoreId))
- return Json(new { errors = _translationService.GetResource("Admin.Catalog.Products.Permissions") });
+ if (await _groupService.IsStaff(_contextAccessor.WorkContext.CurrentCustomer) && !product.AccessToEntityByStore(_contextAccessor.WorkContext.CurrentCustomer.StaffStoreId))
+ return Json(new { errors = _translationService.GetResource("Admin.Catalog.Products.Permissions") });
var toDelete =
(await _productReservationService.GetProductReservationsByProductId(productId, true, null)).Where(x =>
@@ -2659,9 +2642,8 @@ public class ProductController : BaseAdminController
if (product == null)
throw new ArgumentException("No product found with the specified id");
- if (await _groupService.IsStaff(_workContextAccessor.WorkContext.CurrentCustomer))
- if (!product.AccessToEntityByStore(_workContextAccessor.WorkContext.CurrentCustomer.StaffStoreId))
- return ErrorForKendoGridJson(_translationService.GetResource("Admin.Catalog.Products.Permissions"));
+ if (await _groupService.IsStaff(_contextAccessor.WorkContext.CurrentCustomer) && !product.AccessToEntityByStore(_contextAccessor.WorkContext.CurrentCustomer.StaffStoreId))
+ return ErrorForKendoGridJson(_translationService.GetResource("Admin.Catalog.Products.Permissions"));
var toDelete = await _productReservationService.GetProductReservation(model.ReservationId);
if (toDelete != null)
@@ -2689,9 +2671,8 @@ public class ProductController : BaseAdminController
if (product == null)
throw new ArgumentException("No product found with the specified id");
- if (await _groupService.IsStaff(_workContextAccessor.WorkContext.CurrentCustomer))
- if (!product.AccessToEntityByStore(_workContextAccessor.WorkContext.CurrentCustomer.StaffStoreId))
- return Json(new { errors = _translationService.GetResource("Admin.Catalog.Products.Permissions") });
+ if (await _groupService.IsStaff(_contextAccessor.WorkContext.CurrentCustomer) && !product.AccessToEntityByStore(_contextAccessor.WorkContext.CurrentCustomer.StaffStoreId))
+ return Json(new { errors = _translationService.GetResource("Admin.Catalog.Products.Permissions") });
var (bidModels, totalCount) =
await _productViewModelService.PrepareBidMode(productId, command.Page, command.PageSize);
@@ -2710,10 +2691,8 @@ public class ProductController : BaseAdminController
if (product == null)
throw new ArgumentException("No product found with the specified id");
- if (await _groupService.IsStaff(_workContextAccessor.WorkContext.CurrentCustomer))
- if (!product.AccessToEntityByStore(_workContextAccessor.WorkContext.CurrentCustomer.StaffStoreId))
- return Json(new DataSourceResult
- { Errors = _translationService.GetResource("Admin.Catalog.Products.Permissions") });
+ if (await _groupService.IsStaff(_contextAccessor.WorkContext.CurrentCustomer) && !product.AccessToEntityByStore(_contextAccessor.WorkContext.CurrentCustomer.StaffStoreId))
+ return Json(new DataSourceResult { Errors = _translationService.GetResource("Admin.Catalog.Products.Permissions") });
var toDelete = await _auctionService.GetBid(model.BidId);
if (toDelete != null)
diff --git a/src/Web/Grand.Web.Admin/Controllers/ProductReviewController.cs b/src/Web/Grand.Web.Admin/Controllers/ProductReviewController.cs
index 1ee6f1fb0..32460840a 100644
--- a/src/Web/Grand.Web.Admin/Controllers/ProductReviewController.cs
+++ b/src/Web/Grand.Web.Admin/Controllers/ProductReviewController.cs
@@ -21,13 +21,13 @@ public class ProductReviewController : BaseAdminController
IProductReviewViewModelService productReviewViewModelService,
IProductReviewService productReviewService,
ITranslationService translationService,
- IWorkContextAccessor workContextAccessor,
+ IContextAccessor contextAccessor,
IGroupService groupService)
{
_productReviewViewModelService = productReviewViewModelService;
_productReviewService = productReviewService;
_translationService = translationService;
- _workContextAccessor = workContextAccessor;
+ _contextAccessor = contextAccessor;
_groupService = groupService;
}
@@ -38,7 +38,7 @@ public class ProductReviewController : BaseAdminController
private readonly IProductReviewViewModelService _productReviewViewModelService;
private readonly IProductReviewService _productReviewService;
private readonly ITranslationService _translationService;
- private readonly IWorkContextAccessor _workContextAccessor;
+ private readonly IContextAccessor _contextAccessor;
private readonly IGroupService _groupService;
#endregion Fields
@@ -53,7 +53,7 @@ public class ProductReviewController : BaseAdminController
public async Task<IActionResult> List()
{
- var model = await _productReviewViewModelService.PrepareProductReviewListModel(_workContextAccessor.WorkContext.CurrentCustomer
+ var model = await _productReviewViewModelService.PrepareProductReviewListModel(_contextAccessor.WorkContext.CurrentCustomer
.StaffStoreId);
return View(model);
}
@@ -63,8 +63,8 @@ public class ProductReviewController : BaseAdminController
public async Task<IActionResult> List(DataSourceRequest command, ProductReviewListModel model)
{
//limit for store manager
- if (await _groupService.IsStaff(_workContextAccessor.WorkContext.CurrentCustomer))
- model.SearchStoreId = _workContextAccessor.WorkContext.CurrentCustomer.StaffStoreId;
+ if (await _groupService.IsStaff(_contextAccessor.WorkContext.CurrentCustomer))
+ model.SearchStoreId = _contextAccessor.WorkContext.CurrentCustomer.StaffStoreId;
var (productReviewModels, totalCount) =
await _productReviewViewModelService.PrepareProductReviewsModel(model, command.Page, command.PageSize);
@@ -86,8 +86,8 @@ public class ProductReviewController : BaseAdminController
//No product review found with the specified id
return RedirectToAction("List");
- if (await _groupService.IsStaff(_workContextAccessor.WorkContext.CurrentCustomer) &&
- productReview.StoreId != _workContextAccessor.WorkContext.CurrentCustomer.StaffStoreId) return RedirectToAction("List");
+ if (await _groupService.IsStaff(_contextAccessor.WorkContext.CurrentCustomer) &&
+ productReview.StoreId != _contextAccessor.WorkContext.CurrentCustomer.StaffStoreId) return RedirectToAction("List");
var model = new ProductReviewModel();
await _productReviewViewModelService.PrepareProductReviewModel(model, productReview, false, false);
@@ -104,8 +104,8 @@ public class ProductReviewController : BaseAdminController
//No product review found with the specified id
return RedirectToAction("List");
- if (await _groupService.IsStaff(_workContextAccessor.WorkContext.CurrentCustomer) &&
- productReview.StoreId != _workContextAccessor.WorkContext.CurrentCustomer.StaffStoreId) return RedirectToAction("List");
+ if (await _groupService.IsStaff(_contextAccessor.WorkContext.CurrentCustomer) &&
+ productReview.StoreId != _contextAccessor.WorkContext.CurrentCustomer.StaffStoreId) return RedirectToAction("List");
if (ModelState.IsValid)
{
@@ -131,8 +131,8 @@ public class ProductReviewController : BaseAdminController
//No product review found with the specified id
return RedirectToAction("List");
- if (await _groupService.IsStaff(_workContextAccessor.WorkContext.CurrentCustomer) &&
- productReview.StoreId != _workContextAccessor.WorkContext.CurrentCustomer.StaffStoreId) return RedirectToAction("List");
+ if (await _groupService.IsStaff(_contextAccessor.WorkContext.CurrentCustomer) &&
+ productReview.StoreId != _contextAccessor.WorkContext.CurrentCustomer.StaffStoreId) return RedirectToAction("List");
if (ModelState.IsValid)
{
@@ -151,7 +151,7 @@ public class ProductReviewController : BaseAdminController
{
if (selectedIds != null)
await _productReviewViewModelService.ApproveSelected(selectedIds.ToList(),
- _workContextAccessor.WorkContext.CurrentCustomer.StaffStoreId);
+ _contextAccessor.WorkContext.CurrentCustomer.StaffStoreId);
return Json(new { Result = true });
}
@@ -162,7 +162,7 @@ public class ProductReviewController : BaseAdminController
{
if (selectedIds != null)
await _productReviewViewModelService.DisapproveSelected(selectedIds.ToList(),
- _workContextAccessor.WorkContext.CurrentCustomer.StaffStoreId);
+ _contextAccessor.WorkContext.CurrentCustomer.StaffStoreId);
return Json(new { Result = true });
}
@@ -176,8 +176,8 @@ public class ProductReviewController : BaseAdminController
return Content("");
var storeId = string.Empty;
- if (await _groupService.IsStaff(_workContextAccessor.WorkContext.CurrentCustomer))
- storeId = _workContextAccessor.WorkContext.CurrentCustomer.StaffStoreId;
+ if (await _groupService.IsStaff(_contextAccessor.WorkContext.CurrentCustomer))
+ storeId = _contextAccessor.WorkContext.CurrentCustomer.StaffStoreId;
//products
const int productNumber = 15;
diff --git a/src/Web/Grand.Web.Admin/Controllers/ReportsController.cs b/src/Web/Grand.Web.Admin/Controllers/ReportsController.cs
index 92a7769eb..bb5c31443 100644
--- a/src/Web/Grand.Web.Admin/Controllers/ReportsController.cs
+++ b/src/Web/Grand.Web.Admin/Controllers/ReportsController.cs
@@ -52,7 +52,7 @@ public class ReportsController : BaseAdminController
private readonly IStoreService _storeService;
private readonly ITranslationService _translationService;
private readonly IVendorService _vendorService;
- private readonly IWorkContextAccessor _workContextAccessor;
+ private readonly IContextAccessor _contextAccessor;
private readonly IEnumTranslationService _enumTranslationService;
public ReportsController(IOrderService orderService,
IOrderReportService orderReportService,
@@ -60,7 +60,7 @@ public class ReportsController : BaseAdminController
ICustomerReportService customerReportService,
ICustomerReportViewModelService customerReportViewModelService,
IPermissionService permissionService,
- IWorkContextAccessor workContextAccessor,
+ IContextAccessor contextAccessor,
IPriceFormatter priceFormatter,
IProductService productService,
IProductAttributeFormatter productAttributeFormatter,
@@ -82,7 +82,7 @@ public class ReportsController : BaseAdminController
_customerReportService = customerReportService;
_customerReportViewModelService = customerReportViewModelService;
_permissionService = permissionService;
- _workContextAccessor = workContextAccessor;
+ _contextAccessor = contextAccessor;
_priceFormatter = priceFormatter;
_productService = productService;
_productAttributeFormatter = productAttributeFormatter;
@@ -104,8 +104,8 @@ public class ReportsController : BaseAdminController
int pageSize, int orderBy)
{
var storeId = "";
- if (await _groupService.IsStaff(_workContextAccessor.WorkContext.CurrentCustomer))
- storeId = _workContextAccessor.WorkContext.CurrentCustomer.StaffStoreId;
+ if (await _groupService.IsStaff(_contextAccessor.WorkContext.CurrentCustomer))
+ storeId = _contextAccessor.WorkContext.CurrentCustomer.StaffStoreId;
var items = await _orderReportService.BestSellersReport(
storeId,
@@ -140,7 +140,7 @@ public class ReportsController : BaseAdminController
{
var report = new List<OrderPeriodReportLineModel>();
var reportperiod7days =
- await _orderReportService.GetOrderPeriodReport(7, _workContextAccessor.WorkContext.CurrentCustomer.StaffStoreId);
+ await _orderReportService.GetOrderPeriodReport(7, _contextAccessor.WorkContext.CurrentCustomer.StaffStoreId);
report.Add(new OrderPeriodReportLineModel {
Period = _translationService.GetResource("Admin.Reports.Period.7days"),
Count = reportperiod7days.Count,
@@ -148,7 +148,7 @@ public class ReportsController : BaseAdminController
});
var reportperiod14days =
- await _orderReportService.GetOrderPeriodReport(14, _workContextAccessor.WorkContext.CurrentCustomer.StaffStoreId);
+ await _orderReportService.GetOrderPeriodReport(14, _contextAccessor.WorkContext.CurrentCustomer.StaffStoreId);
report.Add(new OrderPeriodReportLineModel {
Period = _translationService.GetResource("Admin.Reports.Period.14days"),
Count = reportperiod14days.Count,
@@ -156,7 +156,7 @@ public class ReportsController : BaseAdminController
});
var reportperiodmonth =
- await _orderReportService.GetOrderPeriodReport(30, _workContextAccessor.WorkContext.CurrentCustomer.StaffStoreId);
+ await _orderReportService.GetOrderPeriodReport(30, _contextAccessor.WorkContext.CurrentCustomer.StaffStoreId);
report.Add(new OrderPeriodReportLineModel {
Period = _translationService.GetResource("Admin.Reports.Period.month"),
Count = reportperiodmonth.Count,
@@ -164,7 +164,7 @@ public class ReportsController : BaseAdminController
});
var reportperiodyear =
- await _orderReportService.GetOrderPeriodReport(365, _workContextAccessor.WorkContext.CurrentCustomer.StaffStoreId);
+ await _orderReportService.GetOrderPeriodReport(365, _contextAccessor.WorkContext.CurrentCustomer.StaffStoreId);
report.Add(new OrderPeriodReportLineModel {
Period = _translationService.GetResource("Admin.Reports.Period.year"),
Count = reportperiodyear.Count,
@@ -204,8 +204,8 @@ public class ReportsController : BaseAdminController
var model = new BestsellersReportModel();
var storeId = "";
- if (await _groupService.IsStaff(_workContextAccessor.WorkContext.CurrentCustomer))
- storeId = _workContextAccessor.WorkContext.CurrentCustomer.StaffStoreId;
+ if (await _groupService.IsStaff(_contextAccessor.WorkContext.CurrentCustomer))
+ storeId = _contextAccessor.WorkContext.CurrentCustomer.StaffStoreId;
//stores
model.AvailableStores.Add(new SelectListItem
@@ -245,8 +245,8 @@ public class ReportsController : BaseAdminController
[HttpPost]
public async Task<IActionResult> BestsellersReportList(DataSourceRequest command, BestsellersReportModel model)
{
- if (await _groupService.IsStaff(_workContextAccessor.WorkContext.CurrentCustomer))
- model.StoreId = _workContextAccessor.WorkContext.CurrentCustomer.StaffStoreId;
+ if (await _groupService.IsStaff(_contextAccessor.WorkContext.CurrentCustomer))
+ model.StoreId = _contextAccessor.WorkContext.CurrentCustomer.StaffStoreId;
DateTime? startDateValue = model.StartDate == null
? null
@@ -319,8 +319,8 @@ public class ReportsController : BaseAdminController
return Content("");
var storeId = "";
- if (await _groupService.IsStaff(_workContextAccessor.WorkContext.CurrentCustomer))
- storeId = _workContextAccessor.WorkContext.CurrentCustomer.StaffStoreId;
+ if (await _groupService.IsStaff(_contextAccessor.WorkContext.CurrentCustomer))
+ storeId = _contextAccessor.WorkContext.CurrentCustomer.StaffStoreId;
var model = await _orderReportService.GetOrderByTimeReport(storeId, startDate, endDate);
var gridModel = new DataSourceResult {
@@ -347,8 +347,8 @@ public class ReportsController : BaseAdminController
: _dateTimeService.ConvertToUtcTime(model.EndDate.Value, _dateTimeService.CurrentTimeZone).AddDays(1);
var storeId = "";
- if (await _groupService.IsStaff(_workContextAccessor.WorkContext.CurrentCustomer))
- storeId = _workContextAccessor.WorkContext.CurrentCustomer.StaffStoreId;
+ if (await _groupService.IsStaff(_contextAccessor.WorkContext.CurrentCustomer))
+ storeId = _contextAccessor.WorkContext.CurrentCustomer.StaffStoreId;
var items = await _orderReportService.ProductsNeverSold(storeId, "",
startDateValue, endDateValue,
@@ -372,8 +372,8 @@ public class ReportsController : BaseAdminController
return Content("");
var storeId = "";
- if (await _groupService.IsStaff(_workContextAccessor.WorkContext.CurrentCustomer))
- storeId = _workContextAccessor.WorkContext.CurrentCustomer.StaffStoreId;
+ if (await _groupService.IsStaff(_contextAccessor.WorkContext.CurrentCustomer))
+ storeId = _contextAccessor.WorkContext.CurrentCustomer.StaffStoreId;
var report = new List<OrderAverageReportLineSummary> {
await _orderReportService.OrderAverageReport(storeId, (int)OrderStatusSystem.Pending),
@@ -413,8 +413,8 @@ public class ReportsController : BaseAdminController
if (!await _permissionService.Authorize(StandardPermission.ManageOrders))
return Content("");
var storeId = "";
- if (await _groupService.IsStaff(_workContextAccessor.WorkContext.CurrentCustomer))
- storeId = _workContextAccessor.WorkContext.CurrentCustomer.StaffStoreId;
+ if (await _groupService.IsStaff(_contextAccessor.WorkContext.CurrentCustomer))
+ storeId = _contextAccessor.WorkContext.CurrentCustomer.StaffStoreId;
//load orders
var orders = await _orderService.SearchOrders(
@@ -459,8 +459,8 @@ public class ReportsController : BaseAdminController
return Content("");
var storeId = "";
- if (await _groupService.IsStaff(_workContextAccessor.WorkContext.CurrentCustomer))
- storeId = _workContextAccessor.WorkContext.CurrentCustomer.StaffStoreId;
+ if (await _groupService.IsStaff(_contextAccessor.WorkContext.CurrentCustomer))
+ storeId = _contextAccessor.WorkContext.CurrentCustomer.StaffStoreId;
var model = new List<OrderIncompleteReportLineModel>();
@@ -543,8 +543,8 @@ public class ReportsController : BaseAdminController
var paymentStatus = model.PaymentStatusId > 0 ? (PaymentStatus?)model.PaymentStatusId : null;
var storeId = "";
- if (await _groupService.IsStaff(_workContextAccessor.WorkContext.CurrentCustomer))
- storeId = _workContextAccessor.WorkContext.CurrentCustomer.StaffStoreId;
+ if (await _groupService.IsStaff(_contextAccessor.WorkContext.CurrentCustomer))
+ storeId = _contextAccessor.WorkContext.CurrentCustomer.StaffStoreId;
var items = await _orderReportService.GetCountryReport(
storeId,
@@ -600,8 +600,8 @@ public class ReportsController : BaseAdminController
public async Task<IActionResult> LowStockReportList(DataSourceRequest command)
{
var storeId = "";
- if (await _groupService.IsStaff(_workContextAccessor.WorkContext.CurrentCustomer))
- storeId = _workContextAccessor.WorkContext.CurrentCustomer.StaffStoreId;
+ if (await _groupService.IsStaff(_contextAccessor.WorkContext.CurrentCustomer))
+ storeId = _contextAccessor.WorkContext.CurrentCustomer.StaffStoreId;
var lowStockProducts = await _productsReportService.LowStockProducts(storeId: storeId);
@@ -627,7 +627,7 @@ public class ReportsController : BaseAdminController
Id = product.Id,
Name = product.Name,
Attributes = await _productAttributeFormatter.FormatAttributes(product, combination.Attributes,
- _workContextAccessor.WorkContext.CurrentCustomer, "<br />", true, true, true, false),
+ _contextAccessor.WorkContext.CurrentCustomer, "<br />", true, true, true, false),
ManageInventoryMethod = _enumTranslationService.GetTranslationEnum(product.ManageInventoryMethodId),
StockQuantity = combination.StockQuantity,
Published = product.Published
@@ -660,8 +660,8 @@ public class ReportsController : BaseAdminController
public async Task<IActionResult> ReportBestCustomersByOrderTotalList(DataSourceRequest command,
BestCustomersReportModel model)
{
- if (await _groupService.IsStaff(_workContextAccessor.WorkContext.CurrentCustomer))
- model.StoreId = _workContextAccessor.WorkContext.CurrentCustomer.StaffStoreId;
+ if (await _groupService.IsStaff(_contextAccessor.WorkContext.CurrentCustomer))
+ model.StoreId = _contextAccessor.WorkContext.CurrentCustomer.StaffStoreId;
var (bestCustomerReportLineModels, totalCount) =
await _customerReportViewModelService.PrepareBestCustomerReportLineModel(model, 1, command.Page,
@@ -677,8 +677,8 @@ public class ReportsController : BaseAdminController
public async Task<IActionResult> ReportBestCustomersByNumberOfOrdersList(DataSourceRequest command,
BestCustomersReportModel model)
{
- if (await _groupService.IsStaff(_workContextAccessor.WorkContext.CurrentCustomer))
- model.StoreId = _workContextAccessor.WorkContext.CurrentCustomer.StaffStoreId;
+ if (await _groupService.IsStaff(_contextAccessor.WorkContext.CurrentCustomer))
+ model.StoreId = _contextAccessor.WorkContext.CurrentCustomer.StaffStoreId;
var (bestCustomerReportLineModels, totalCount) =
await _customerReportViewModelService.PrepareBestCustomerReportLineModel(model, 2, command.Page,
@@ -694,8 +694,8 @@ public class ReportsController : BaseAdminController
public async Task<IActionResult> ReportRegisteredCustomersList(DataSourceRequest command)
{
var storeId = "";
- if (await _groupService.IsStaff(_workContextAccessor.WorkContext.CurrentCustomer))
- storeId = _workContextAccessor.WorkContext.CurrentCustomer.StaffStoreId;
+ if (await _groupService.IsStaff(_contextAccessor.WorkContext.CurrentCustomer))
+ storeId = _contextAccessor.WorkContext.CurrentCustomer.StaffStoreId;
var model = await _customerReportViewModelService.GetReportRegisteredCustomersModel(storeId);
var gridModel = new DataSourceResult {
@@ -711,8 +711,8 @@ public class ReportsController : BaseAdminController
DateTime? endDate)
{
var storeId = "";
- if (await _groupService.IsStaff(_workContextAccessor.WorkContext.CurrentCustomer))
- storeId = _workContextAccessor.WorkContext.CurrentCustomer.StaffStoreId;
+ if (await _groupService.IsStaff(_contextAccessor.WorkContext.CurrentCustomer))
+ storeId = _contextAccessor.WorkContext.CurrentCustomer.StaffStoreId;
var model = await _customerReportService.GetCustomerByTimeReport(storeId, startDate, endDate);
var gridModel = new DataSourceResult {
diff --git a/src/Web/Grand.Web.Admin/Controllers/SearchController.cs b/src/Web/Grand.Web.Admin/Controllers/SearchController.cs
index 47cdb8e20..f8bee08f9 100644
--- a/src/Web/Grand.Web.Admin/Controllers/SearchController.cs
+++ b/src/Web/Grand.Web.Admin/Controllers/SearchController.cs
@@ -39,13 +39,13 @@ public class SearchController : BaseAdminController
private readonly IStoreService _storeService;
private readonly ITranslationService _translationService;
private readonly IVendorService _vendorService;
- private readonly IWorkContextAccessor _workContextAccessor;
+ private readonly IContextAccessor _contextAccessor;
public SearchController(IProductService productService, ICategoryService categoryService,
IBrandService brandService, ICollectionService collectionService,
IPageService pageService, INewsService newsService, IBlogService blogService, ICustomerService customerService,
IOrderService orderService,
- AdminSearchSettings adminSearchSettings, ITranslationService translationService, IWorkContextAccessor workContextAccessor,
+ AdminSearchSettings adminSearchSettings, ITranslationService translationService, IContextAccessor contextAccessor,
IGroupService groupService,
IStoreService storeService, IVendorService vendorService)
{
@@ -60,7 +60,7 @@ public class SearchController : BaseAdminController
_orderService = orderService;
_adminSearchSettings = adminSearchSettings;
_translationService = translationService;
- _workContextAccessor = workContextAccessor;
+ _contextAccessor = contextAccessor;
_groupService = groupService;
_storeService = storeService;
_vendorService = vendorService;
@@ -72,7 +72,7 @@ public class SearchController : BaseAdminController
if (string.IsNullOrEmpty(searchTerm))
return Json("error");
- if (!await _groupService.IsAdmin(_workContextAccessor.WorkContext.CurrentCustomer)) return Json("Access Denied");
+ if (!await _groupService.IsAdmin(_contextAccessor.WorkContext.CurrentCustomer)) return Json("Access Denied");
//object = actual result, int = display order for sorting
var result = new List<Tuple<object, int>>();
@@ -94,7 +94,7 @@ public class SearchController : BaseAdminController
{
var categories = await _categoryService.GetAllCategories(categoryName: searchTerm,
pageSize: _adminSearchSettings.MaxSearchResultsCount - result.Count, showHidden:
- await _groupService.IsAdmin(_workContextAccessor.WorkContext.CurrentCustomer));
+ await _groupService.IsAdmin(_contextAccessor.WorkContext.CurrentCustomer));
foreach (var category in categories)
result.Add(new Tuple<object, int>(new {
title = category.Name,
@@ -247,7 +247,7 @@ public class SearchController : BaseAdminController
return model;
}
- var storeId = _workContextAccessor.WorkContext.CurrentCustomer.StaffStoreId;
+ var storeId = _contextAccessor.WorkContext.CurrentCustomer.StaffStoreId;
var categories = await _categoryService.GetAllCategories(
storeId: storeId,
@@ -286,7 +286,7 @@ public class SearchController : BaseAdminController
return model;
}
- var storeId = _workContextAccessor.WorkContext.CurrentCustomer.StaffStoreId;
+ var storeId = _contextAccessor.WorkContext.CurrentCustomer.StaffStoreId;
var collections = await _collectionService.GetAllCollections(
storeId: storeId,
@@ -363,7 +363,7 @@ public class SearchController : BaseAdminController
}
var groups = await _storeService.GetAllStores();
- var storeId = _workContextAccessor.WorkContext.CurrentCustomer.StaffStoreId;
+ var storeId = _contextAccessor.WorkContext.CurrentCustomer.StaffStoreId;
if (!string.IsNullOrEmpty(storeId))
groups = groups.Where(x => x.Id == storeId).ToList();
diff --git a/src/Web/Grand.Web.Admin/Controllers/ShipmentController.cs b/src/Web/Grand.Web.Admin/Controllers/ShipmentController.cs
index 77e9ee9c5..df9b8d0d5 100644
--- a/src/Web/Grand.Web.Admin/Controllers/ShipmentController.cs
+++ b/src/Web/Grand.Web.Admin/Controllers/ShipmentController.cs
@@ -26,7 +26,7 @@ public class ShipmentController : BaseAdminController
IShipmentViewModelService shipmentViewModelService,
IOrderService orderService,
ITranslationService translationService,
- IWorkContextAccessor workContextAccessor,
+ IContextAccessor contextAccessor,
IGroupService groupService,
IPdfService pdfService,
IShipmentService shipmentService,
@@ -36,7 +36,7 @@ public class ShipmentController : BaseAdminController
_shipmentViewModelService = shipmentViewModelService;
_orderService = orderService;
_translationService = translationService;
- _workContextAccessor = workContextAccessor;
+ _contextAccessor = contextAccessor;
_groupService = groupService;
_pdfService = pdfService;
_shipmentService = shipmentService;
@@ -49,7 +49,7 @@ public class ShipmentController : BaseAdminController
private readonly IShipmentViewModelService _shipmentViewModelService;
private readonly IOrderService _orderService;
private readonly ITranslationService _translationService;
- private readonly IWorkContextAccessor _workContextAccessor;
+ private readonly IContextAccessor _contextAccessor;
private readonly IGroupService _groupService;
private readonly IPdfService _pdfService;
private readonly IShipmentService _shipmentService;
@@ -70,8 +70,8 @@ public class ShipmentController : BaseAdminController
[HttpPost]
public async Task<IActionResult> ShipmentListSelect(DataSourceRequest command, ShipmentListModel model)
{
- if (await _groupService.IsStaff(_workContextAccessor.WorkContext.CurrentCustomer))
- model.StoreId = _workContextAccessor.WorkContext.CurrentCustomer.StaffStoreId;
+ if (await _groupService.IsStaff(_contextAccessor.WorkContext.CurrentCustomer))
+ model.StoreId = _contextAccessor.WorkContext.CurrentCustomer.StaffStoreId;
var shipments = await _shipmentViewModelService.PrepareShipments(model, command.Page, command.PageSize);
var items = new List<ShipmentModel>();
@@ -93,8 +93,8 @@ public class ShipmentController : BaseAdminController
if (order == null)
throw new ArgumentException("No order found with the specified id");
- if (await _groupService.IsStaff(_workContextAccessor.WorkContext.CurrentCustomer) &&
- order.StoreId != _workContextAccessor.WorkContext.CurrentCustomer.StaffStoreId)
+ if (await _groupService.IsStaff(_contextAccessor.WorkContext.CurrentCustomer) &&
+ order.StoreId != _contextAccessor.WorkContext.CurrentCustomer.StaffStoreId)
return Content("");
//shipments
@@ -124,8 +124,8 @@ public class ShipmentController : BaseAdminController
if (order == null)
throw new ArgumentException("No order found with the specified id");
- if (await _groupService.IsStaff(_workContextAccessor.WorkContext.CurrentCustomer) &&
- shipment.StoreId != _workContextAccessor.WorkContext.CurrentCustomer.StaffStoreId)
+ if (await _groupService.IsStaff(_contextAccessor.WorkContext.CurrentCustomer) &&
+ shipment.StoreId != _contextAccessor.WorkContext.CurrentCustomer.StaffStoreId)
return Content("");
//shipments
@@ -146,8 +146,8 @@ public class ShipmentController : BaseAdminController
//No order found with the specified id
return RedirectToAction("List");
- if (await _groupService.IsStaff(_workContextAccessor.WorkContext.CurrentCustomer) &&
- order.StoreId != _workContextAccessor.WorkContext.CurrentCustomer.StaffStoreId)
+ if (await _groupService.IsStaff(_contextAccessor.WorkContext.CurrentCustomer) &&
+ order.StoreId != _contextAccessor.WorkContext.CurrentCustomer.StaffStoreId)
return RedirectToAction("List");
var model = await _shipmentViewModelService.PrepareShipmentModel(order);
@@ -165,8 +165,8 @@ public class ShipmentController : BaseAdminController
//No order found with the specified id
return RedirectToAction("List");
- if (await _groupService.IsStaff(_workContextAccessor.WorkContext.CurrentCustomer) &&
- order.StoreId != _workContextAccessor.WorkContext.CurrentCustomer.StaffStoreId)
+ if (await _groupService.IsStaff(_contextAccessor.WorkContext.CurrentCustomer) &&
+ order.StoreId != _contextAccessor.WorkContext.CurrentCustomer.StaffStoreId)
return RedirectToAction("List");
var orderItems = order.OrderItems;
@@ -215,8 +215,8 @@ public class ShipmentController : BaseAdminController
//No shipment found with the specified id
return RedirectToAction("List");
- if (await _groupService.IsStaff(_workContextAccessor.WorkContext.CurrentCustomer) &&
- shipment.StoreId != _workContextAccessor.WorkContext.CurrentCustomer.StaffStoreId)
+ if (await _groupService.IsStaff(_contextAccessor.WorkContext.CurrentCustomer) &&
+ shipment.StoreId != _contextAccessor.WorkContext.CurrentCustomer.StaffStoreId)
return RedirectToAction("List");
var orderId = shipment.OrderId;
@@ -238,8 +238,8 @@ public class ShipmentController : BaseAdminController
//No shipment found with the specified id
return RedirectToAction("List");
- if (await _groupService.IsStaff(_workContextAccessor.WorkContext.CurrentCustomer) &&
- shipment.StoreId != _workContextAccessor.WorkContext.CurrentCustomer.StaffStoreId)
+ if (await _groupService.IsStaff(_contextAccessor.WorkContext.CurrentCustomer) &&
+ shipment.StoreId != _contextAccessor.WorkContext.CurrentCustomer.StaffStoreId)
return RedirectToAction("List");
var orderId = shipment.OrderId;
@@ -272,8 +272,8 @@ public class ShipmentController : BaseAdminController
//No shipment found with the specified id
return RedirectToAction("List");
- if (await _groupService.IsStaff(_workContextAccessor.WorkContext.CurrentCustomer) &&
- shipment.StoreId != _workContextAccessor.WorkContext.CurrentCustomer.StaffStoreId)
+ if (await _groupService.IsStaff(_contextAccessor.WorkContext.CurrentCustomer) &&
+ shipment.StoreId != _contextAccessor.WorkContext.CurrentCustomer.StaffStoreId)
return RedirectToAction("List");
var order = await _orderService.GetOrderById(shipment.OrderId);
@@ -296,8 +296,8 @@ public class ShipmentController : BaseAdminController
//No shipment found with the specified id
return RedirectToAction("List");
- if (await _groupService.IsStaff(_workContextAccessor.WorkContext.CurrentCustomer) &&
- shipment.StoreId != _workContextAccessor.WorkContext.CurrentCustomer.StaffStoreId)
+ if (await _groupService.IsStaff(_contextAccessor.WorkContext.CurrentCustomer) &&
+ shipment.StoreId != _contextAccessor.WorkContext.CurrentCustomer.StaffStoreId)
return RedirectToAction("List");
var order = await _orderService.GetOrderById(shipment.OrderId);
@@ -320,8 +320,8 @@ public class ShipmentController : BaseAdminController
//No shipment found with the specified id
return RedirectToAction("List");
- if (await _groupService.IsStaff(_workContextAccessor.WorkContext.CurrentCustomer) &&
- shipment.StoreId != _workContextAccessor.WorkContext.CurrentCustomer.StaffStoreId)
+ if (await _groupService.IsStaff(_contextAccessor.WorkContext.CurrentCustomer) &&
+ shipment.StoreId != _contextAccessor.WorkContext.CurrentCustomer.StaffStoreId)
return RedirectToAction("List");
var order = await _orderService.GetOrderById(shipment.OrderId);
@@ -350,8 +350,8 @@ public class ShipmentController : BaseAdminController
//No shipment found with the specified id
return RedirectToAction("List");
- if (await _groupService.IsStaff(_workContextAccessor.WorkContext.CurrentCustomer) &&
- shipment.StoreId != _workContextAccessor.WorkContext.CurrentCustomer.StaffStoreId)
+ if (await _groupService.IsStaff(_contextAccessor.WorkContext.CurrentCustomer) &&
+ shipment.StoreId != _contextAccessor.WorkContext.CurrentCustomer.StaffStoreId)
return RedirectToAction("List");
var order = await _orderService.GetOrderById(shipment.OrderId);
@@ -383,8 +383,8 @@ public class ShipmentController : BaseAdminController
//No shipment found with the specified id
return RedirectToAction("List");
- if (await _groupService.IsStaff(_workContextAccessor.WorkContext.CurrentCustomer) &&
- shipment.StoreId != _workContextAccessor.WorkContext.CurrentCustomer.StaffStoreId)
+ if (await _groupService.IsStaff(_contextAccessor.WorkContext.CurrentCustomer) &&
+ shipment.StoreId != _contextAccessor.WorkContext.CurrentCustomer.StaffStoreId)
return RedirectToAction("List");
var order = await _orderService.GetOrderById(shipment.OrderId);
@@ -415,8 +415,8 @@ public class ShipmentController : BaseAdminController
//No shipment found with the specified id
return RedirectToAction("List");
- if (await _groupService.IsStaff(_workContextAccessor.WorkContext.CurrentCustomer) &&
- shipment.StoreId != _workContextAccessor.WorkContext.CurrentCustomer.StaffStoreId)
+ if (await _groupService.IsStaff(_contextAccessor.WorkContext.CurrentCustomer) &&
+ shipment.StoreId != _contextAccessor.WorkContext.CurrentCustomer.StaffStoreId)
return RedirectToAction("List");
var order = await _orderService.GetOrderById(shipment.OrderId);
@@ -449,8 +449,8 @@ public class ShipmentController : BaseAdminController
//No order found with the specified id
return RedirectToAction("List");
- if (await _groupService.IsStaff(_workContextAccessor.WorkContext.CurrentCustomer) &&
- shipment.StoreId != _workContextAccessor.WorkContext.CurrentCustomer.StaffStoreId)
+ if (await _groupService.IsStaff(_contextAccessor.WorkContext.CurrentCustomer) &&
+ shipment.StoreId != _contextAccessor.WorkContext.CurrentCustomer.StaffStoreId)
return RedirectToAction("ShipmentDetails", new { id = shipment.Id });
shipment.UserFields = model.UserFields;
@@ -470,8 +470,8 @@ public class ShipmentController : BaseAdminController
//no shipment found with the specified id
return RedirectToAction("List");
- if (await _groupService.IsStaff(_workContextAccessor.WorkContext.CurrentCustomer) &&
- shipment.StoreId != _workContextAccessor.WorkContext.CurrentCustomer.StaffStoreId)
+ if (await _groupService.IsStaff(_contextAccessor.WorkContext.CurrentCustomer) &&
+ shipment.StoreId != _contextAccessor.WorkContext.CurrentCustomer.StaffStoreId)
return RedirectToAction("List");
var order = await _orderService.GetOrderById(shipment.OrderId);
@@ -486,7 +486,7 @@ public class ShipmentController : BaseAdminController
byte[] bytes;
using (var stream = new MemoryStream())
{
- await _pdfService.PrintPackagingSlipsToPdf(stream, shipments, _workContextAccessor.WorkContext.WorkingLanguage.Id);
+ await _pdfService.PrintPackagingSlipsToPdf(stream, shipments, _contextAccessor.WorkContext.WorkingLanguage.Id);
bytes = stream.ToArray();
}
@@ -497,8 +497,8 @@ public class ShipmentController : BaseAdminController
[HttpPost]
public async Task<IActionResult> PdfPackagingSlipAll(ShipmentListModel model)
{
- if (await _groupService.IsStaff(_workContextAccessor.WorkContext.CurrentCustomer))
- model.StoreId = _workContextAccessor.WorkContext.CurrentCustomer.StaffStoreId;
+ if (await _groupService.IsStaff(_contextAccessor.WorkContext.CurrentCustomer))
+ model.StoreId = _contextAccessor.WorkContext.CurrentCustomer.StaffStoreId;
//load shipments
var shipments = await _shipmentViewModelService.PrepareShipments(model, 1, 100);
@@ -514,7 +514,7 @@ public class ShipmentController : BaseAdminController
using (var stream = new MemoryStream())
{
await _pdfService.PrintPackagingSlipsToPdf(stream, shipments.shipments.ToList(),
- _workContextAccessor.WorkContext.WorkingLanguage.Id);
+ _contextAccessor.WorkContext.WorkingLanguage.Id);
bytes = stream.ToArray();
}
@@ -537,8 +537,8 @@ public class ShipmentController : BaseAdminController
}
var storeId = "";
- if (await _groupService.IsStaff(_workContextAccessor.WorkContext.CurrentCustomer))
- storeId = _workContextAccessor.WorkContext.CurrentCustomer.StaffStoreId;
+ if (await _groupService.IsStaff(_contextAccessor.WorkContext.CurrentCustomer))
+ storeId = _contextAccessor.WorkContext.CurrentCustomer.StaffStoreId;
shipments_access = shipments.Where(x => x.StoreId == storeId || string.IsNullOrEmpty(storeId)).ToList();
//ensure that we at least one shipment selected
@@ -551,7 +551,7 @@ public class ShipmentController : BaseAdminController
byte[] bytes;
using (var stream = new MemoryStream())
{
- await _pdfService.PrintPackagingSlipsToPdf(stream, shipments_access, _workContextAccessor.WorkContext.WorkingLanguage.Id);
+ await _pdfService.PrintPackagingSlipsToPdf(stream, shipments_access, _contextAccessor.WorkContext.WorkingLanguage.Id);
bytes = stream.ToArray();
}
@@ -567,8 +567,8 @@ public class ShipmentController : BaseAdminController
if (selectedIds != null) shipments.AddRange(await _shipmentService.GetShipmentsByIds(selectedIds.ToArray()));
var storeId = "";
- if (await _groupService.IsStaff(_workContextAccessor.WorkContext.CurrentCustomer))
- storeId = _workContextAccessor.WorkContext.CurrentCustomer.StaffStoreId;
+ if (await _groupService.IsStaff(_contextAccessor.WorkContext.CurrentCustomer))
+ storeId = _contextAccessor.WorkContext.CurrentCustomer.StaffStoreId;
shipments_access = shipments.Where(x => x.StoreId == storeId || string.IsNullOrEmpty(storeId)).ToList();
foreach (var shipment in shipments_access)
@@ -593,8 +593,8 @@ public class ShipmentController : BaseAdminController
if (selectedIds != null) shipments.AddRange(await _shipmentService.GetShipmentsByIds(selectedIds.ToArray()));
var storeId = "";
- if (await _groupService.IsStaff(_workContextAccessor.WorkContext.CurrentCustomer))
- storeId = _workContextAccessor.WorkContext.CurrentCustomer.StaffStoreId;
+ if (await _groupService.IsStaff(_contextAccessor.WorkContext.CurrentCustomer))
+ storeId = _contextAccessor.WorkContext.CurrentCustomer.StaffStoreId;
shipments_access = shipments.Where(x => x.StoreId == storeId || string.IsNullOrEmpty(storeId)).ToList();
foreach (var shipment in shipments_access)
try
@@ -619,8 +619,8 @@ public class ShipmentController : BaseAdminController
if (shipment == null)
throw new ArgumentException("No shipment found with the specified id");
- if (await _groupService.IsStaff(_workContextAccessor.WorkContext.CurrentCustomer) &&
- shipment.StoreId != _workContextAccessor.WorkContext.CurrentCustomer.StaffStoreId)
+ if (await _groupService.IsStaff(_contextAccessor.WorkContext.CurrentCustomer) &&
+ shipment.StoreId != _contextAccessor.WorkContext.CurrentCustomer.StaffStoreId)
return Content("");
//shipment notes
@@ -640,8 +640,8 @@ public class ShipmentController : BaseAdminController
if (shipment == null)
return Json(new { Result = false });
- if (await _groupService.IsStaff(_workContextAccessor.WorkContext.CurrentCustomer) &&
- shipment.StoreId != _workContextAccessor.WorkContext.CurrentCustomer.StaffStoreId)
+ if (await _groupService.IsStaff(_contextAccessor.WorkContext.CurrentCustomer) &&
+ shipment.StoreId != _contextAccessor.WorkContext.CurrentCustomer.StaffStoreId)
return Json(new { Result = false });
await _shipmentViewModelService.InsertShipmentNote(shipment, downloadId, displayToCustomer, message);
@@ -657,8 +657,8 @@ public class ShipmentController : BaseAdminController
if (shipment == null)
throw new ArgumentException("No shipment found with the specified id");
- if (await _groupService.IsStaff(_workContextAccessor.WorkContext.CurrentCustomer) &&
- shipment.StoreId != _workContextAccessor.WorkContext.CurrentCustomer.StaffStoreId)
+ if (await _groupService.IsStaff(_contextAccessor.WorkContext.CurrentCustomer) &&
+ shipment.StoreId != _contextAccessor.WorkContext.CurrentCustomer.StaffStoreId)
return Json(new { Result = false });
await _shipmentViewModelService.DeleteShipmentNote(shipment, id);
diff --git a/src/Web/Grand.Web.Admin/Controllers/SpecificationAttributeController.cs b/src/Web/Grand.Web.Admin/Controllers/SpecificationAttributeController.cs
index 5c39e0464..ae9b864e2 100644
--- a/src/Web/Grand.Web.Admin/Controllers/SpecificationAttributeController.cs
+++ b/src/Web/Grand.Web.Admin/Controllers/SpecificationAttributeController.cs
@@ -23,7 +23,7 @@ public class SpecificationAttributeController : BaseAdminController
ISpecificationAttributeService specificationAttributeService,
ILanguageService languageService,
ITranslationService translationService,
- IWorkContextAccessor workContextAccessor,
+ IContextAccessor contextAccessor,
IGroupService groupService,
IProductService productService,
SeoSettings seoSettings)
@@ -31,7 +31,7 @@ public class SpecificationAttributeController : BaseAdminController
_specificationAttributeService = specificationAttributeService;
_languageService = languageService;
_translationService = translationService;
- _workContextAccessor = workContextAccessor;
+ _contextAccessor = contextAccessor;
_groupService = groupService;
_productService = productService;
_seoSettings = seoSettings;
@@ -54,8 +54,8 @@ public class SpecificationAttributeController : BaseAdminController
var searchStoreId = string.Empty;
//limit for store manager
- if (!string.IsNullOrEmpty(_workContextAccessor.WorkContext.CurrentCustomer.StaffStoreId))
- searchStoreId = _workContextAccessor.WorkContext.CurrentCustomer.StaffStoreId;
+ if (!string.IsNullOrEmpty(_contextAccessor.WorkContext.CurrentCustomer.StaffStoreId))
+ searchStoreId = _contextAccessor.WorkContext.CurrentCustomer.StaffStoreId;
var specificationProducts = new List<SpecificationAttributeModel.UsedByProductModel>();
var total = 0;
@@ -103,7 +103,7 @@ public class SpecificationAttributeController : BaseAdminController
private readonly IProductService _productService;
private readonly ILanguageService _languageService;
private readonly ITranslationService _translationService;
- private readonly IWorkContextAccessor _workContextAccessor;
+ private readonly IContextAccessor _contextAccessor;
private readonly IGroupService _groupService;
private readonly SeoSettings _seoSettings;
@@ -160,8 +160,8 @@ public class SpecificationAttributeController : BaseAdminController
? specificationAttribute.Name
: specificationAttribute.SeName, _seoSettings.ConvertNonWesternChars,
_seoSettings.AllowUnicodeCharsInUrls, _seoSettings.SeoCharConversion);
- if (await _groupService.IsStaff(_workContextAccessor.WorkContext.CurrentCustomer))
- model.Stores = [_workContextAccessor.WorkContext.CurrentCustomer.StaffStoreId];
+ if (await _groupService.IsStaff(_contextAccessor.WorkContext.CurrentCustomer))
+ model.Stores = [_contextAccessor.WorkContext.CurrentCustomer.StaffStoreId];
await _specificationAttributeService.InsertSpecificationAttribute(specificationAttribute);
Success(_translationService.GetResource("Admin.Catalog.Attributes.SpecificationAttributes.Added"));
@@ -211,8 +211,8 @@ public class SpecificationAttributeController : BaseAdminController
? specificationAttribute.Name
: specificationAttribute.SeName, _seoSettings.ConvertNonWesternChars,
_seoSettings.AllowUnicodeCharsInUrls, _seoSettings.SeoCharConversion);
- if (await _groupService.IsStaff(_workContextAccessor.WorkContext.CurrentCustomer))
- model.Stores = [_workContextAccessor.WorkContext.CurrentCustomer.StaffStoreId];
+ if (await _groupService.IsStaff(_contextAccessor.WorkContext.CurrentCustomer))
+ model.Stores = [_contextAccessor.WorkContext.CurrentCustomer.StaffStoreId];
await _specificationAttributeService.UpdateSpecificationAttribute(specificationAttribute);
Success(_translationService.GetResource("Admin.Catalog.Attributes.SpecificationAttributes.Updated"));
diff --git a/src/Web/Grand.Web.Admin/Controllers/SystemController.cs b/src/Web/Grand.Web.Admin/Controllers/SystemController.cs
index 944ee5854..1197d415b 100644
--- a/src/Web/Grand.Web.Admin/Controllers/SystemController.cs
+++ b/src/Web/Grand.Web.Admin/Controllers/SystemController.cs
@@ -32,7 +32,7 @@ public class SystemController : BaseAdminController
ICurrencyService currencyService,
IMeasureService measureService,
IDateTimeService dateTimeService,
- IWorkContextAccessor workContextAccessor,
+ IContextAccessor contextAccessor,
ITranslationService translationService,
IHostApplicationLifetime applicationLifetime,
IWebHostEnvironment webHostEnvironment,
@@ -48,7 +48,7 @@ public class SystemController : BaseAdminController
_currencySettings = currencySettings;
_measureSettings = measureSettings;
_dateTimeService = dateTimeService;
- _workContextAccessor = workContextAccessor;
+ _contextAccessor = contextAccessor;
_translationService = translationService;
_applicationLifetime = applicationLifetime;
_webHostEnvironment = webHostEnvironment;
@@ -66,7 +66,7 @@ public class SystemController : BaseAdminController
private readonly ICurrencyService _currencyService;
private readonly IMeasureService _measureService;
private readonly IDateTimeService _dateTimeService;
- private readonly IWorkContextAccessor _workContextAccessor;
+ private readonly IContextAccessor _contextAccessor;
private readonly ITranslationService _translationService;
private readonly IHostApplicationLifetime _applicationLifetime;
private readonly IWebHostEnvironment _webHostEnvironment;
@@ -120,7 +120,7 @@ public class SystemController : BaseAdminController
});
//current host
- var currenthostName = _workContextAccessor.WorkContext.CurrentHost.HostName;
+ var currenthostName = _contextAccessor.StoreContext.CurrentHost.HostName;
if (!string.IsNullOrEmpty(currenthostName) &&
currenthostName.Equals(HttpContext.Request.Host.Value, StringComparison.OrdinalIgnoreCase))
model.SystemWarnings.Add(new SystemInfoModel.SystemWarningModel {
@@ -261,7 +261,7 @@ public class SystemController : BaseAdminController
public async Task<IActionResult> ClearCache(string returnUrl, [FromServices] ICacheBase cacheBase)
{
- _logger.LogInformation($"Clear cache has been done by the user: {_workContextAccessor.WorkContext.CurrentCustomer.Email}");
+ _logger.LogInformation($"Clear cache has been done by the user: {_contextAccessor.WorkContext.CurrentCustomer.Email}");
await cacheBase.Clear();
@@ -277,7 +277,7 @@ public class SystemController : BaseAdminController
public IActionResult RestartApplication(string returnUrl = "")
{
- _logger.LogInformation($"The application has been restarted by the user {_workContextAccessor.WorkContext.CurrentCustomer.Email}");
+ _logger.LogInformation($"The application has been restarted by the user {_contextAccessor.WorkContext.CurrentCustomer.Email}");
//stop application
_applicationLifetime.StopApplication();
diff --git a/src/Web/Grand.Web.Admin/Controllers/VendorReviewController.cs b/src/Web/Grand.Web.Admin/Controllers/VendorReviewController.cs
index f82becfdc..19f1d3b1d 100644
--- a/src/Web/Grand.Web.Admin/Controllers/VendorReviewController.cs
+++ b/src/Web/Grand.Web.Admin/Controllers/VendorReviewController.cs
@@ -1,8 +1,6 @@
-using Grand.Business.Core.Interfaces.Common.Directory;
-using Grand.Business.Core.Interfaces.Common.Localization;
+using Grand.Business.Core.Interfaces.Common.Localization;
using Grand.Business.Core.Interfaces.Customers;
using Grand.Domain.Permissions;
-using Grand.Infrastructure;
using Grand.Web.Admin.Interfaces;
using Grand.Web.Admin.Models.Vendors;
using Grand.Web.Common.DataSource;
@@ -20,15 +18,11 @@ public class VendorReviewController : BaseAdminController
public VendorReviewController(
IVendorViewModelService vendorViewModelService,
IVendorService vendorService,
- ITranslationService translationService,
- IGroupService groupService,
- IWorkContextAccessor workContextAccessor)
+ ITranslationService translationService)
{
_vendorViewModelService = vendorViewModelService;
_vendorService = vendorService;
_translationService = translationService;
- _groupService = groupService;
- _workContextAccessor = workContextAccessor;
}
#endregion
@@ -38,8 +32,6 @@ public class VendorReviewController : BaseAdminController
private readonly IVendorViewModelService _vendorViewModelService;
private readonly IVendorService _vendorService;
private readonly ITranslationService _translationService;
- private readonly IWorkContextAccessor _workContextAccessor;
- private readonly IGroupService _groupService;
#endregion Fields
@@ -159,10 +151,11 @@ public class VendorReviewController : BaseAdminController
keywords: term);
var result = (from p in vendors
- select new {
- label = p.Name,
- vendorid = p.Id
- })
+ select new
+ {
+ label = p.Name,
+ vendorid = p.Id
+ })
.ToList();
return Json(result);
}
diff --git a/src/Web/Grand.Web.Admin/Models/Catalog/ProductModel.cs b/src/Web/Grand.Web.Admin/Models/Catalog/ProductModel.cs
index 64bf86127..34ad110b2 100644
--- a/src/Web/Grand.Web.Admin/Models/Catalog/ProductModel.cs
+++ b/src/Web/Grand.Web.Admin/Models/Catalog/ProductModel.cs
@@ -662,6 +662,7 @@ public class ProductModel : BaseEntityModel, ILocalizedModel<ProductLocalizedMod
public class ProductPriceModel : BaseEntityModel
{
+ public string ProductId { get; set; }
public string CurrencyCode { get; set; }
public double Price { get; set; }
diff --git a/src/Web/Grand.Web.Admin/Services/AffiliateViewModelService.cs b/src/Web/Grand.Web.Admin/Services/AffiliateViewModelService.cs
index c4c387cc1..403270b1c 100644
--- a/src/Web/Grand.Web.Admin/Services/AffiliateViewModelService.cs
+++ b/src/Web/Grand.Web.Admin/Services/AffiliateViewModelService.cs
@@ -31,16 +31,16 @@ public class AffiliateViewModelService : IAffiliateViewModelService
private readonly IPriceFormatter _priceFormatter;
private readonly SeoSettings _seoSettings;
private readonly ITranslationService _translationService;
- private readonly IWorkContextAccessor _workContextAccessor;
+ private readonly IContextAccessor _contextAccessor;
private readonly IEnumTranslationService _enumTranslationService;
- public AffiliateViewModelService(IWorkContextAccessor workContextAccessor, ICountryService countryService,
+ public AffiliateViewModelService(IContextAccessor contextAccessor, ICountryService countryService,
IPriceFormatter priceFormatter, IAffiliateService affiliateService,
ICustomerService customerService, IOrderService orderService, ITranslationService translationService,
IDateTimeService dateTimeService,
IOrderStatusService orderStatusService,
SeoSettings seoSettings, ICurrencyService currencyService, IEnumTranslationService enumTranslationService)
{
- _workContextAccessor = workContextAccessor;
+ _contextAccessor = contextAccessor;
_countryService = countryService;
_priceFormatter = priceFormatter;
_affiliateService = affiliateService;
@@ -64,9 +64,9 @@ public class AffiliateViewModelService : IAffiliateViewModelService
model.Id = affiliate.Id;
model.Name = affiliate.Name;
- var host = _workContextAccessor.WorkContext.CurrentHost == null
- ? _workContextAccessor.WorkContext.CurrentStore.Url.TrimEnd('/')
- : _workContextAccessor.WorkContext.CurrentHost.Url.TrimEnd('/');
+ var host = _contextAccessor.StoreContext.CurrentHost == null
+ ? _contextAccessor.StoreContext.CurrentStore.Url.TrimEnd('/')
+ : _contextAccessor.StoreContext.CurrentHost.Url.TrimEnd('/');
model.Url = affiliate.GenerateUrl(host);
if (!excludeProperties)
{
diff --git a/src/Web/Grand.Web.Admin/Services/BlogViewModelService.cs b/src/Web/Grand.Web.Admin/Services/BlogViewModelService.cs
index 058c67b74..8bef2a537 100644
--- a/src/Web/Grand.Web.Admin/Services/BlogViewModelService.cs
+++ b/src/Web/Grand.Web.Admin/Services/BlogViewModelService.cs
@@ -31,7 +31,7 @@ public class BlogViewModelService : IBlogViewModelService
private readonly IStoreService _storeService;
private readonly ITranslationService _translationService;
private readonly IVendorService _vendorService;
- private readonly IWorkContextAccessor _workContextAccessor;
+ private readonly IContextAccessor _contextAccessor;
private readonly ISeNameService _seNameService;
private readonly IEnumTranslationService _enumTranslationService;
@@ -44,7 +44,7 @@ public class BlogViewModelService : IBlogViewModelService
ITranslationService translationService,
IProductService productService,
IVendorService vendorService,
- IWorkContextAccessor workContextAccessor,
+ IContextAccessor contextAccessor,
ISeNameService seNameService,
IEnumTranslationService enumTranslationService)
{
@@ -56,7 +56,7 @@ public class BlogViewModelService : IBlogViewModelService
_translationService = translationService;
_productService = productService;
_vendorService = vendorService;
- _workContextAccessor = workContextAccessor;
+ _contextAccessor = contextAccessor;
_seNameService = seNameService;
_enumTranslationService = enumTranslationService;
}
@@ -64,7 +64,7 @@ public class BlogViewModelService : IBlogViewModelService
public virtual async Task<(IEnumerable<BlogPostModel> blogPosts, int totalCount)> PrepareBlogPostsModel(
int pageIndex, int pageSize)
{
- var blogPosts = await _blogService.GetAllBlogPosts(_workContextAccessor.WorkContext.CurrentCustomer.StaffStoreId, null, null,
+ var blogPosts = await _blogService.GetAllBlogPosts(_contextAccessor.WorkContext.CurrentCustomer.StaffStoreId, null, null,
pageIndex - 1, pageSize, true);
return (blogPosts.Select(x =>
{
@@ -127,9 +127,9 @@ public class BlogViewModelService : IBlogViewModelService
PrepareBlogPostCommentsModel(string filterByBlogPostId, int pageIndex, int pageSize)
{
IList<BlogComment> comments;
- var storeId = string.IsNullOrEmpty(_workContextAccessor.WorkContext.CurrentCustomer.StaffStoreId)
+ var storeId = string.IsNullOrEmpty(_contextAccessor.WorkContext.CurrentCustomer.StaffStoreId)
? ""
- : _workContextAccessor.WorkContext.CurrentCustomer.StaffStoreId;
+ : _contextAccessor.WorkContext.CurrentCustomer.StaffStoreId;
if (!string.IsNullOrEmpty(filterByBlogPostId))
{
//filter comments by blog
@@ -185,7 +185,7 @@ public class BlogViewModelService : IBlogViewModelService
};
//stores
- var storeId = _workContextAccessor.WorkContext.CurrentCustomer.StaffStoreId;
+ var storeId = _contextAccessor.WorkContext.CurrentCustomer.StaffStoreId;
model.AvailableStores.Add(new SelectListItem
{ Text = _translationService.GetResource("Admin.Common.All"), Value = " " });
foreach (var s in (await _storeService.GetAllStores()).Where(x =>
@@ -209,7 +209,7 @@ public class BlogViewModelService : IBlogViewModelService
public virtual async Task<(IList<ProductModel> products, int totalCount)> PrepareProductModel(
BlogProductModel.AddProductModel model, int pageIndex, int pageSize)
{
- model.SearchStoreId = _workContextAccessor.WorkContext.CurrentCustomer.StaffStoreId;
+ model.SearchStoreId = _contextAccessor.WorkContext.CurrentCustomer.StaffStoreId;
var products = await _productService.PrepareProductList(model.SearchCategoryId, model.SearchBrandId,
model.SearchCollectionId, model.SearchStoreId, model.SearchVendorId, model.SearchProductTypeId,
model.SearchProductName, pageIndex, pageSize);
diff --git a/src/Web/Grand.Web.Admin/Services/BrandViewModelService.cs b/src/Web/Grand.Web.Admin/Services/BrandViewModelService.cs
index 3be02c66e..2e8daa3e5 100644
--- a/src/Web/Grand.Web.Admin/Services/BrandViewModelService.cs
+++ b/src/Web/Grand.Web.Admin/Services/BrandViewModelService.cs
@@ -26,7 +26,7 @@ public class BrandViewModelService : IBrandViewModelService
private readonly IPictureService _pictureService;
private readonly IDiscountService _discountService;
private readonly IDateTimeService _dateTimeService;
- private readonly IWorkContextAccessor _workContextAccessor;
+ private readonly IContextAccessor _contextAccessor;
private readonly ISeNameService _seNameService;
private readonly IEnumTranslationService _enumTranslationService;
@@ -40,7 +40,7 @@ public class BrandViewModelService : IBrandViewModelService
IPictureService pictureService,
IDiscountService discountService,
IDateTimeService dateTimeService,
- IWorkContextAccessor workContextAccessor,
+ IContextAccessor contextAccessor,
ISeNameService seNameService,
IEnumTranslationService enumTranslationService)
{
@@ -49,7 +49,7 @@ public class BrandViewModelService : IBrandViewModelService
_pictureService = pictureService;
_discountService = discountService;
_dateTimeService = dateTimeService;
- _workContextAccessor = workContextAccessor;
+ _contextAccessor = contextAccessor;
_seNameService = seNameService;
_enumTranslationService = enumTranslationService;
}
@@ -82,7 +82,7 @@ public class BrandViewModelService : IBrandViewModelService
ArgumentNullException.ThrowIfNull(model);
model.AvailableDiscounts = (await _discountService
- .GetDiscountsQuery(DiscountType.AssignedToBrands, _workContextAccessor.WorkContext.CurrentCustomer.Id))
+ .GetDiscountsQuery(DiscountType.AssignedToBrands, _contextAccessor.WorkContext.CurrentCustomer.Id))
.Select(d => d.ToModel(_dateTimeService))
.ToList();
diff --git a/src/Web/Grand.Web.Admin/Services/CollectionViewModelService.cs b/src/Web/Grand.Web.Admin/Services/CollectionViewModelService.cs
index 5c845e65e..01b48bdec 100644
--- a/src/Web/Grand.Web.Admin/Services/CollectionViewModelService.cs
+++ b/src/Web/Grand.Web.Admin/Services/CollectionViewModelService.cs
@@ -33,7 +33,7 @@ public class CollectionViewModelService : ICollectionViewModelService
private readonly ITranslationService _translationService;
private readonly IDiscountService _discountService;
private readonly IVendorService _vendorService;
- private readonly IWorkContextAccessor _workContextAccessor;
+ private readonly IContextAccessor _contextAccessor;
private readonly ISeNameService _seNameService;
private readonly IEnumTranslationService _enumTranslationService;
@@ -51,7 +51,7 @@ public class CollectionViewModelService : ICollectionViewModelService
ITranslationService translationService,
IDiscountService discountService,
IVendorService vendorService,
- IWorkContextAccessor workContextAccessor,
+ IContextAccessor contextAccessor,
ISeNameService seNameService,
IEnumTranslationService enumTranslationService)
{
@@ -64,7 +64,7 @@ public class CollectionViewModelService : ICollectionViewModelService
_translationService = translationService;
_discountService = discountService;
_vendorService = vendorService;
- _workContextAccessor = workContextAccessor;
+ _contextAccessor = contextAccessor;
_seNameService = seNameService;
_enumTranslationService = enumTranslationService;
}
@@ -97,7 +97,7 @@ public class CollectionViewModelService : ICollectionViewModelService
ArgumentNullException.ThrowIfNull(model);
model.AvailableDiscounts = (await _discountService
- .GetDiscountsQuery(DiscountType.AssignedToCollections, _workContextAccessor.WorkContext.CurrentCustomer.Id))
+ .GetDiscountsQuery(DiscountType.AssignedToCollections, _contextAccessor.WorkContext.CurrentCustomer.Id))
.Select(d => d.ToModel())
.ToList();
diff --git a/src/Web/Grand.Web.Admin/Services/ContactAttributeViewModelService.cs b/src/Web/Grand.Web.Admin/Services/ContactAttributeViewModelService.cs
index 78fb57649..575263c0e 100644
--- a/src/Web/Grand.Web.Admin/Services/ContactAttributeViewModelService.cs
+++ b/src/Web/Grand.Web.Admin/Services/ContactAttributeViewModelService.cs
@@ -14,14 +14,14 @@ namespace Grand.Web.Admin.Services;
public class ContactAttributeViewModelService(
IContactAttributeService contactAttributeService,
IContactAttributeParser contactAttributeParser,
- IWorkContextAccessor workContextAccessor,
+ IContextAccessor contextAccessor,
IEnumTranslationService enumTranslationService)
: IContactAttributeViewModelService
{
public virtual async Task<IEnumerable<ContactAttributeModel>> PrepareContactAttributeListModel()
{
var contactAttributes =
- await contactAttributeService.GetAllContactAttributes(workContextAccessor.WorkContext.CurrentCustomer.StaffStoreId, true);
+ await contactAttributeService.GetAllContactAttributes(contextAccessor.WorkContext.CurrentCustomer.StaffStoreId, true);
return contactAttributes.Select(x =>
{
var attributeModel = x.ToModel();
@@ -49,7 +49,7 @@ public class ContactAttributeViewModelService(
EnableCondition = contactAttribute.ConditionAttribute.Any(),
SelectedAttributeId = selectedAttribute != null ? selectedAttribute.Id : "",
ConditionAttributes =
- (await contactAttributeService.GetAllContactAttributes(workContextAccessor.WorkContext.CurrentCustomer.StaffStoreId, true))
+ (await contactAttributeService.GetAllContactAttributes(contextAccessor.WorkContext.CurrentCustomer.StaffStoreId, true))
//ignore this attribute and non-combinable attributes
.Where(x => x.Id != contactAttribute.Id && x.CanBeUsedAsCondition())
.Select(x =>
diff --git a/src/Web/Grand.Web.Admin/Services/ContactFormViewModelService.cs b/src/Web/Grand.Web.Admin/Services/ContactFormViewModelService.cs
index 8bf429298..fabc47e61 100644
--- a/src/Web/Grand.Web.Admin/Services/ContactFormViewModelService.cs
+++ b/src/Web/Grand.Web.Admin/Services/ContactFormViewModelService.cs
@@ -4,7 +4,6 @@ using Grand.Business.Core.Interfaces.Common.Stores;
using Grand.Business.Core.Interfaces.Marketing.Contacts;
using Grand.Business.Core.Interfaces.Messages;
using Grand.Domain.Messages;
-using Grand.Infrastructure;
using Grand.Web.Admin.Extensions.Mapping;
using Grand.Web.Admin.Interfaces;
using Grand.Web.Admin.Models.Messages;
@@ -19,19 +18,16 @@ public class ContactFormViewModelService : IContactFormViewModelService
private readonly IEmailAccountService _emailAccountService;
private readonly IStoreService _storeService;
private readonly ITranslationService _translationService;
- private readonly IWorkContextAccessor _workContextAccessor;
public ContactFormViewModelService(IContactUsService contactUsService,
IDateTimeService dateTimeService,
ITranslationService translationService,
- IWorkContextAccessor workContextAccessor,
IStoreService storeService,
IEmailAccountService emailAccountService)
{
_contactUsService = contactUsService;
_dateTimeService = dateTimeService;
_translationService = translationService;
- _workContextAccessor = workContextAccessor;
_storeService = storeService;
_emailAccountService = emailAccountService;
}
@@ -40,8 +36,7 @@ public class ContactFormViewModelService : IContactFormViewModelService
{
var model = new ContactFormListModel();
//stores
- model.AvailableStores.Add(new SelectListItem
- { Text = _translationService.GetResource("Admin.Common.All"), Value = "" });
+ model.AvailableStores.Add(new SelectListItem { Text = _translationService.GetResource("Admin.Common.All"), Value = "" });
foreach (var s in await _storeService.GetAllStores())
model.AvailableStores.Add(new SelectListItem { Text = s.Shortcut, Value = s.Id });
diff --git a/src/Web/Grand.Web.Admin/Services/CustomerReportViewModelService.cs b/src/Web/Grand.Web.Admin/Services/CustomerReportViewModelService.cs
index 6ca916146..46533a151 100644
--- a/src/Web/Grand.Web.Admin/Services/CustomerReportViewModelService.cs
+++ b/src/Web/Grand.Web.Admin/Services/CustomerReportViewModelService.cs
@@ -6,10 +6,8 @@ using Grand.Business.Core.Interfaces.Customers;
using Grand.Business.Core.Interfaces.System.Reports;
using Grand.Domain.Payments;
using Grand.Domain.Shipping;
-using Grand.Infrastructure;
using Grand.Web.Admin.Interfaces;
using Grand.Web.Admin.Models.Customers;
-using Grand.Web.Common.Extensions;
using Grand.Web.Common.Localization;
using Microsoft.AspNetCore.Mvc.Rendering;
@@ -24,16 +22,14 @@ public class CustomerReportViewModelService : ICustomerReportViewModelService
private readonly IOrderStatusService _orderStatusService;
private readonly IPriceFormatter _priceFormatter;
private readonly ITranslationService _translationService;
- private readonly IWorkContextAccessor _workContextAccessor;
private readonly IEnumTranslationService _enumTranslationService;
-
- public CustomerReportViewModelService(IWorkContextAccessor workContextAccessor,
+
+ public CustomerReportViewModelService(
ICustomerService customerService,
ITranslationService translationService, ICustomerReportService customerReportService,
IDateTimeService dateTimeService, IPriceFormatter priceFormatter,
IOrderStatusService orderStatusService, ICurrencyService currencyService, IEnumTranslationService enumTranslationService)
{
- _workContextAccessor = workContextAccessor;
_customerService = customerService;
_translationService = translationService;
_customerReportService = customerReportService;
diff --git a/src/Web/Grand.Web.Admin/Services/CustomerViewModelService.cs b/src/Web/Grand.Web.Admin/Services/CustomerViewModelService.cs
index f2b40c6b1..f5da42cf5 100644
--- a/src/Web/Grand.Web.Admin/Services/CustomerViewModelService.cs
+++ b/src/Web/Grand.Web.Admin/Services/CustomerViewModelService.cs
@@ -69,7 +69,7 @@ public class CustomerViewModelService : ICustomerViewModelService
private readonly TaxSettings _taxSettings;
private readonly ITranslationService _translationService;
private readonly IVendorService _vendorService;
- private readonly IWorkContextAccessor _workContextAccessor;
+ private readonly IContextAccessor _contextAccessor;
private readonly IEnumTranslationService _enumTranslationService;
public CustomerViewModelService(
@@ -81,7 +81,7 @@ public class CustomerViewModelService : ICustomerViewModelService
ITranslationService translationService,
ILoyaltyPointsService loyaltyPointsService,
ICountryService countryService,
- IWorkContextAccessor workContextAccessor,
+ IContextAccessor contextAccessor,
IVendorService vendorService,
IStoreService storeService,
ICustomerAttributeParser customerAttributeParser,
@@ -115,7 +115,7 @@ public class CustomerViewModelService : ICustomerViewModelService
_customerSettings = customerSettings;
_commonSettings = commonSettings;
_enumTranslationService = enumTranslationService;
- _workContextAccessor = workContextAccessor;
+ _contextAccessor = contextAccessor;
_vendorService = vendorService;
_addressSettings = addressSettings;
_storeService = storeService;
@@ -154,7 +154,7 @@ public class CustomerViewModelService : ICustomerViewModelService
CustomerListModel model,
string[] searchCustomerGroupIds, string[] searchCustomerTagIds, int pageIndex, int pageSize)
{
- var salesEmployeeId = _workContextAccessor.WorkContext.CurrentCustomer.SeId;
+ var salesEmployeeId = _contextAccessor.WorkContext.CurrentCustomer.SeId;
var customers = await _customerService.GetAllCustomers(
customerGroupIds: searchCustomerGroupIds,
@@ -262,7 +262,7 @@ public class CustomerViewModelService : ICustomerViewModelService
}
else
{
- model.SeId = _workContextAccessor.WorkContext.CurrentCustomer.SeId;
+ model.SeId = _contextAccessor.WorkContext.CurrentCustomer.SeId;
}
model.UsernamesEnabled = _customerSettings.UsernamesEnabled;
@@ -333,7 +333,7 @@ public class CustomerViewModelService : ICustomerViewModelService
model.LoyaltyPointsAvailableStores.Add(new SelectListItem {
Text = store.Shortcut,
Value = store.Id,
- Selected = store.Id == _workContextAccessor.WorkContext.CurrentStore.Id
+ Selected = store.Id == _contextAccessor.StoreContext.CurrentStore.Id
});
//external authentication records
@@ -384,7 +384,7 @@ public class CustomerViewModelService : ICustomerViewModelService
IsTaxExempt = model.IsTaxExempt,
FreeShipping = model.FreeShipping,
Active = model.Active,
- StoreId = _workContextAccessor.WorkContext.CurrentStore.Id,
+ StoreId = _contextAccessor.StoreContext.CurrentStore.Id,
OwnerId = ownerId,
Attributes = model.Attributes,
LastActivityDateUtc = DateTime.UtcNow
@@ -648,7 +648,7 @@ public class CustomerViewModelService : ICustomerViewModelService
{
var customers = new List<Customer>();
customers.AddRange(await _customerService.GetCustomersByIds(selectedIds.ToArray()));
- foreach (var customer in customers.Where(customer => customer.Id != _workContextAccessor.WorkContext.CurrentCustomer.Id))
+ foreach (var customer in customers.Where(customer => customer.Id != _contextAccessor.WorkContext.CurrentCustomer.Id))
await _customerService.DeleteCustomer(customer);
}
@@ -731,7 +731,7 @@ public class CustomerViewModelService : ICustomerViewModelService
if (_addressSettings.CountryEnabled && !string.IsNullOrEmpty(model.CountryName))
addressHtmlSb.AppendFormat("{0}", WebUtility.HtmlEncode(model.CountryName));
var customAttributesFormatted =
- await _addressAttributeParser.FormatAttributes(_workContextAccessor.WorkContext.WorkingLanguage, x.Attributes);
+ await _addressAttributeParser.FormatAttributes(_contextAccessor.WorkContext.WorkingLanguage, x.Attributes);
if (!string.IsNullOrEmpty(customAttributesFormatted))
//already encoded
addressHtmlSb.AppendFormat("<br />{0}", customAttributesFormatted);
@@ -1138,8 +1138,8 @@ public class CustomerViewModelService : ICustomerViewModelService
var messageProviderService = _httpContextAccessor.HttpContext!.RequestServices
.GetRequiredService<IMessageProviderService>();
await messageProviderService.SendNewCustomerNoteMessage(customerNote,
- await _customerService.GetCustomerById(customerId), _workContextAccessor.WorkContext.CurrentStore,
- _workContextAccessor.WorkContext.WorkingLanguage.Id);
+ await _customerService.GetCustomerById(customerId), _contextAccessor.StoreContext.CurrentStore,
+ _contextAccessor.WorkContext.WorkingLanguage.Id);
}
return customerNote;
diff --git a/src/Web/Grand.Web.Admin/Services/DiscountViewModelService.cs b/src/Web/Grand.Web.Admin/Services/DiscountViewModelService.cs
index e3bd7a93e..e28c55f3e 100644
--- a/src/Web/Grand.Web.Admin/Services/DiscountViewModelService.cs
+++ b/src/Web/Grand.Web.Admin/Services/DiscountViewModelService.cs
@@ -35,7 +35,7 @@ public class DiscountViewModelService : IDiscountViewModelService
ICurrencyService currencyService,
ICategoryService categoryService,
IProductService productService,
- IWorkContextAccessor workContextAccessor,
+ IContextAccessor contextAccessor,
ICollectionService collectionService,
IBrandService brandService,
IStoreService storeService,
@@ -52,7 +52,7 @@ public class DiscountViewModelService : IDiscountViewModelService
_currencyService = currencyService;
_categoryService = categoryService;
_productService = productService;
- _workContextAccessor = workContextAccessor;
+ _contextAccessor = contextAccessor;
_collectionService = collectionService;
_brandService = brandService;
_storeService = storeService;
@@ -74,7 +74,7 @@ public class DiscountViewModelService : IDiscountViewModelService
private readonly ICurrencyService _currencyService;
private readonly ICategoryService _categoryService;
private readonly IProductService _productService;
- private readonly IWorkContextAccessor _workContextAccessor;
+ private readonly IContextAccessor _contextAccessor;
private readonly IBrandService _brandService;
private readonly ICollectionService _collectionService;
private readonly IStoreService _storeService;
@@ -105,7 +105,7 @@ public class DiscountViewModelService : IDiscountViewModelService
if (model.SearchDiscountTypeId > 0)
discountType = (DiscountType)model.SearchDiscountTypeId;
var discounts = await _discountService.GetDiscountsQuery(discountType,
- _workContextAccessor.WorkContext.CurrentCustomer.StaffStoreId,
+ _contextAccessor.WorkContext.CurrentCustomer.StaffStoreId,
null,
model.SearchDiscountCouponCode,
model.SearchDiscountName);
@@ -251,7 +251,7 @@ public class DiscountViewModelService : IDiscountViewModelService
ArgumentNullException.ThrowIfNull(discountRequirementRule);
ArgumentNullException.ThrowIfNull(discount);
- var storeLocation = _workContextAccessor.WorkContext.CurrentHost.Url.TrimEnd('/');
+ var storeLocation = _contextAccessor.StoreContext.CurrentHost.Url.TrimEnd('/');
var url =
$"{storeLocation}/{discountRequirementRule.GetConfigurationUrl(discount.Id, discountRequirementId)}";
diff --git a/src/Web/Grand.Web.Admin/Services/GiftVoucherViewModelService.cs b/src/Web/Grand.Web.Admin/Services/GiftVoucherViewModelService.cs
index ee8f4a5db..882270da5 100644
--- a/src/Web/Grand.Web.Admin/Services/GiftVoucherViewModelService.cs
+++ b/src/Web/Grand.Web.Admin/Services/GiftVoucherViewModelService.cs
@@ -26,7 +26,7 @@ public class GiftVoucherViewModelService : IGiftVoucherViewModelService
ICurrencyService currencyService,
LanguageSettings languageSettings,
ITranslationService translationService, ILanguageService languageService,
- IWorkContextAccessor workContextAccessor,
+ IContextAccessor contextAccessor,
IStoreService storeService)
{
_giftVoucherService = giftVoucherService;
diff --git a/src/Web/Grand.Web.Admin/Services/OrderViewModelService.cs b/src/Web/Grand.Web.Admin/Services/OrderViewModelService.cs
index dbbff6985..9d8d8836c 100644
--- a/src/Web/Grand.Web.Admin/Services/OrderViewModelService.cs
+++ b/src/Web/Grand.Web.Admin/Services/OrderViewModelService.cs
@@ -48,7 +48,7 @@ public class OrderViewModelService : IOrderViewModelService
private readonly IPriceFormatter _priceFormatter;
private readonly IDiscountService _discountService;
private readonly ITranslationService _translationService;
- private readonly IWorkContextAccessor _workContextAccessor;
+ private readonly IContextAccessor _contextAccessor;
private readonly ICurrencyService _currencyService;
private readonly IPaymentService _paymentService;
private readonly IPaymentTransactionService _paymentTransactionService;
@@ -89,7 +89,7 @@ public class OrderViewModelService : IOrderViewModelService
IPriceFormatter priceFormatter,
IDiscountService discountService,
ITranslationService translationService,
- IWorkContextAccessor workContextAccessor,
+ IContextAccessor contextAccessor,
ICurrencyService currencyService,
IPaymentService paymentService,
IPaymentTransactionService paymentTransactionService,
@@ -125,7 +125,7 @@ public class OrderViewModelService : IOrderViewModelService
_priceFormatter = priceFormatter;
_discountService = discountService;
_translationService = translationService;
- _workContextAccessor = workContextAccessor;
+ _contextAccessor = contextAccessor;
_currencyService = currencyService;
_paymentService = paymentService;
_paymentTransactionService = paymentTransactionService;
@@ -280,7 +280,7 @@ public class OrderViewModelService : IOrderViewModelService
if (product != null)
filterByProductId = model.ProductId;
- var salesEmployeeId = _workContextAccessor.WorkContext.CurrentCustomer.SeId;
+ var salesEmployeeId = _contextAccessor.WorkContext.CurrentCustomer.SeId;
//load orders
var orders = await _orderService.SearchOrders(
@@ -591,7 +591,7 @@ public class OrderViewModelService : IOrderViewModelService
model.BillingAddress = await order.BillingAddress.ToModel(_countryService);
model.BillingAddress.FormattedCustomAddressAttributes =
- await _addressAttributeParser.FormatAttributes(_workContextAccessor.WorkContext.WorkingLanguage,
+ await _addressAttributeParser.FormatAttributes(_contextAccessor.WorkContext.WorkingLanguage,
order.BillingAddress.Attributes);
model.BillingAddress.NameEnabled = _addressSettings.NameEnabled;
model.BillingAddress.FirstNameEnabled = true;
@@ -632,7 +632,7 @@ public class OrderViewModelService : IOrderViewModelService
{
model.ShippingAddress = await order.ShippingAddress.ToModel(_countryService);
model.ShippingAddress.FormattedCustomAddressAttributes =
- await _addressAttributeParser.FormatAttributes(_workContextAccessor.WorkContext.WorkingLanguage,
+ await _addressAttributeParser.FormatAttributes(_contextAccessor.WorkContext.WorkingLanguage,
order.ShippingAddress.Attributes);
model.ShippingAddress.NameEnabled = _addressSettings.NameEnabled;
model.ShippingAddress.FirstNameEnabled = true;
@@ -1189,7 +1189,7 @@ public class OrderViewModelService : IOrderViewModelService
if (product != null)
filterByProductId = model.ProductId;
- var salesEmployeeId = _workContextAccessor.WorkContext.CurrentCustomer.SeId;
+ var salesEmployeeId = _contextAccessor.WorkContext.CurrentCustomer.SeId;
//load orders
var orders = await _orderService.SearchOrders(model.StoreId,
diff --git a/src/Web/Grand.Web.Admin/Services/ProductViewModelService.cs b/src/Web/Grand.Web.Admin/Services/ProductViewModelService.cs
index 83fd92a95..0e995f31e 100644
--- a/src/Web/Grand.Web.Admin/Services/ProductViewModelService.cs
+++ b/src/Web/Grand.Web.Admin/Services/ProductViewModelService.cs
@@ -52,7 +52,7 @@ public class ProductViewModelService(
ITranslationService translationService,
IProductLayoutService productLayoutService,
ISpecificationAttributeService specificationAttributeService,
- IWorkContextAccessor workContextAccessor,
+ IContextAccessor contextAccessor,
IGroupService groupService,
IWarehouseService warehouseService,
IDeliveryDateService deliveryDateService,
@@ -142,7 +142,7 @@ public class ProductViewModelService(
public virtual async Task PrepareTierPriceModel(ProductModel.TierPriceModel model)
{
- var storeId = workContextAccessor.WorkContext.CurrentCustomer.StaffStoreId;
+ var storeId = contextAccessor.WorkContext.CurrentCustomer.StaffStoreId;
if (string.IsNullOrEmpty(storeId))
model.AvailableStores.Add(new SelectListItem
@@ -404,7 +404,7 @@ public class ProductViewModelService(
//discounts
model.AvailableDiscounts = (await discountService
- .GetDiscountsQuery(DiscountType.AssignedToSkus, workContextAccessor.WorkContext.CurrentCustomer.StaffStoreId))
+ .GetDiscountsQuery(DiscountType.AssignedToSkus, contextAccessor.WorkContext.CurrentCustomer.StaffStoreId))
.Select(d => d.ToModel(dateTimeService))
.ToList();
if (!excludeProperties && product != null) model.SelectedDiscountIds = product.AppliedDiscounts.ToArray();
@@ -526,7 +526,7 @@ public class ProductViewModelService(
{
var model = new ProductListModel();
- var storeId = workContextAccessor.WorkContext.CurrentCustomer.StaffStoreId;
+ var storeId = contextAccessor.WorkContext.CurrentCustomer.StaffStoreId;
//stores
model.AvailableStores.Add(new SelectListItem
@@ -576,8 +576,8 @@ public class ProductViewModelService(
ProductListModel model, int pageIndex, int pageSize)
{
//limit for store manager
- if (!string.IsNullOrEmpty(workContextAccessor.WorkContext.CurrentCustomer.StaffStoreId))
- model.SearchStoreId = workContextAccessor.WorkContext.CurrentCustomer.StaffStoreId;
+ if (!string.IsNullOrEmpty(contextAccessor.WorkContext.CurrentCustomer.StaffStoreId))
+ model.SearchStoreId = contextAccessor.WorkContext.CurrentCustomer.StaffStoreId;
var categoryIds = new List<string>();
if (!string.IsNullOrEmpty(model.SearchCategoryId))
@@ -651,7 +651,7 @@ public class ProductViewModelService(
public virtual async Task<IList<Product>> PrepareProducts(ProductListModel model)
{
//limit for store manager
- model.SearchStoreId = workContextAccessor.WorkContext.CurrentCustomer.StaffStoreId;
+ model.SearchStoreId = contextAccessor.WorkContext.CurrentCustomer.StaffStoreId;
var categoryIds = new List<string>();
if (!string.IsNullOrEmpty(model.SearchCategoryId))
@@ -694,8 +694,8 @@ public class ProductViewModelService(
public virtual async Task<Product> InsertProductModel(ProductModel model)
{
//a staff should have access only to his products
- if (await groupService.IsStaff(workContextAccessor.WorkContext.CurrentCustomer))
- model.Stores = [workContextAccessor.WorkContext.CurrentCustomer.StaffStoreId];
+ if (await groupService.IsStaff(contextAccessor.WorkContext.CurrentCustomer))
+ model.Stores = [contextAccessor.WorkContext.CurrentCustomer.StaffStoreId];
//product
var product = model.ToEntity(dateTimeService);
@@ -703,7 +703,7 @@ public class ProductViewModelService(
//discounts
var allDiscounts =
await discountService.GetDiscountsQuery(DiscountType.AssignedToSkus,
- workContextAccessor.WorkContext.CurrentCustomer.StaffStoreId);
+ contextAccessor.WorkContext.CurrentCustomer.StaffStoreId);
foreach (var discount in allDiscounts)
if (model.SelectedDiscountIds != null && model.SelectedDiscountIds.Contains(discount.Id))
{
@@ -734,8 +734,8 @@ public class ProductViewModelService(
public virtual async Task<Product> UpdateProductModel(Product product, ProductModel model)
{
//a staff should have access only to his products
- if (await groupService.IsStaff(workContextAccessor.WorkContext.CurrentCustomer))
- model.Stores = [workContextAccessor.WorkContext.CurrentCustomer.StaffStoreId];
+ if (await groupService.IsStaff(contextAccessor.WorkContext.CurrentCustomer))
+ model.Stores = [contextAccessor.WorkContext.CurrentCustomer.StaffStoreId];
var prevStockQuantity = stockQuantityService.GetTotalStockQuantity(product, total: true);
var prevMultiWarehouseStock = product.ProductWarehouseInventory.Select(i => new ProductWarehouseInventory
@@ -753,7 +753,7 @@ public class ProductViewModelService(
//discounts
var allDiscounts =
await discountService.GetDiscountsQuery(DiscountType.AssignedToSkus,
- workContextAccessor.WorkContext.CurrentCustomer.StaffStoreId);
+ contextAccessor.WorkContext.CurrentCustomer.StaffStoreId);
foreach (var discount in allDiscounts)
if (model.SelectedDiscountIds != null && model.SelectedDiscountIds.Contains(discount.Id))
{
@@ -832,8 +832,8 @@ public class ProductViewModelService(
for (var i = 0; i < products.Count; i++)
{
var product = products[i];
- if (await groupService.IsStaff(workContextAccessor.WorkContext.CurrentCustomer))
- if (!(product.LimitedToStores && product.Stores.Contains(workContextAccessor.WorkContext.CurrentCustomer.StaffStoreId) &&
+ if (await groupService.IsStaff(contextAccessor.WorkContext.CurrentCustomer))
+ if (!(product.LimitedToStores && product.Stores.Contains(contextAccessor.WorkContext.CurrentCustomer.StaffStoreId) &&
product.Stores.Count == 1))
continue;
await DeleteProduct(product);
@@ -850,7 +850,7 @@ public class ProductViewModelService(
ProductModel.AddProductModel model, int pageIndex, int pageSize)
{
//limit for store manager
- model.SearchStoreId = workContextAccessor.WorkContext.CurrentCustomer.StaffStoreId;
+ model.SearchStoreId = contextAccessor.WorkContext.CurrentCustomer.StaffStoreId;
var products = await productService.PrepareProductList(model.SearchCategoryId, model.SearchBrandId,
model.SearchCollectionId, model.SearchStoreId, model.SearchVendorId, model.SearchProductTypeId,
@@ -1239,9 +1239,9 @@ public class ProductViewModelService(
new SelectListItem { Text = translationService.GetResource("Admin.Common.All"), Value = "0" });
// avaible stores
- if (await groupService.IsStaff(workContextAccessor.WorkContext.CurrentCustomer))
+ if (await groupService.IsStaff(contextAccessor.WorkContext.CurrentCustomer))
{
- storeId = workContextAccessor.WorkContext.CurrentCustomer.StaffStoreId;
+ storeId = contextAccessor.WorkContext.CurrentCustomer.StaffStoreId;
var store = (await storeService.GetAllStores()).FirstOrDefault(x => x.Id == storeId);
if (store != null)
model.AvailableStores.Add(new SelectListItem { Text = store.Shortcut, Value = store.Id });
@@ -1262,8 +1262,8 @@ public class ProductViewModelService(
PrepareBulkEditProductModel(BulkEditListModel model, int pageIndex, int pageSize)
{
var storeId = model.SearchStoreId;
- if (await groupService.IsStaff(workContextAccessor.WorkContext.CurrentCustomer))
- storeId = workContextAccessor.WorkContext.CurrentCustomer.StaffStoreId;
+ if (await groupService.IsStaff(contextAccessor.WorkContext.CurrentCustomer))
+ storeId = contextAccessor.WorkContext.CurrentCustomer.StaffStoreId;
var searchCategoryIds = new List<string>();
if (!string.IsNullOrEmpty(model.SearchCategoryId))
@@ -1305,8 +1305,8 @@ public class ProductViewModelService(
if (product != null)
{
//a staff can have access only to his products
- if (await groupService.IsStaff(workContextAccessor.WorkContext.CurrentCustomer))
- if (!product.AccessToEntityByStore(workContextAccessor.WorkContext.CurrentCustomer.StaffStoreId))
+ if (await groupService.IsStaff(contextAccessor.WorkContext.CurrentCustomer))
+ if (!product.AccessToEntityByStore(contextAccessor.WorkContext.CurrentCustomer.StaffStoreId))
continue;
var prevStockQuantity = stockQuantityService.GetTotalStockQuantity(product, total: true);
@@ -1340,8 +1340,8 @@ public class ProductViewModelService(
var product = await productService.GetProductById(pModel.Id, true);
if (product != null)
{
- if (await groupService.IsStaff(workContextAccessor.WorkContext.CurrentCustomer))
- if (!product.AccessToEntityByStore(workContextAccessor.WorkContext.CurrentCustomer.StaffStoreId))
+ if (await groupService.IsStaff(contextAccessor.WorkContext.CurrentCustomer))
+ if (!product.AccessToEntityByStore(contextAccessor.WorkContext.CurrentCustomer.StaffStoreId))
continue;
await productService.DeleteProduct(product);
@@ -1351,7 +1351,7 @@ public class ProductViewModelService(
public virtual async Task<IList<ProductModel.TierPriceModel>> PrepareTierPriceModel(Product product)
{
- var storeId = workContextAccessor.WorkContext.CurrentCustomer.StaffStoreId;
+ var storeId = contextAccessor.WorkContext.CurrentCustomer.StaffStoreId;
var items = new List<ProductModel.TierPriceModel>();
foreach (var x in product.TierPrices
@@ -1940,7 +1940,7 @@ public class ProductViewModelService(
foreach (var x in product.ProductAttributeCombinations)
{
var attributes = await productAttributeFormatter.FormatAttributes(product, x.Attributes,
- workContextAccessor.WorkContext.CurrentCustomer, "<br />", true, true, true, false, true, true);
+ contextAccessor.WorkContext.CurrentCustomer, "<br />", true, true, true, false, true, true);
var pacModel = new ProductModel.ProductAttributeCombinationModel {
Id = x.Id,
ProductId = product.Id,
@@ -1991,7 +1991,7 @@ public class ProductViewModelService(
model.WarehouseInventoryModels = wim;
model.ProductId = product.Id;
model.Attributes = await productAttributeFormatter.FormatAttributes(product, combination.Attributes,
- workContextAccessor.WorkContext.CurrentCustomer, "<br />", true, true, true, false);
+ contextAccessor.WorkContext.CurrentCustomer, "<br />", true, true, true, false);
if (model.UseMultipleWarehouses)
foreach (var _winv in combination.WarehouseInventory)
{
@@ -2610,7 +2610,7 @@ public class ProductViewModelService(
{
var model = new T();
- var storeId = workContextAccessor.WorkContext.CurrentCustomer.StaffStoreId;
+ var storeId = contextAccessor.WorkContext.CurrentCustomer.StaffStoreId;
//stores
model.AvailableStores.Add(new SelectListItem
diff --git a/src/Web/Grand.Web.Admin/Services/ShipmentViewModelService.cs b/src/Web/Grand.Web.Admin/Services/ShipmentViewModelService.cs
index 91019e518..09beb2f31 100644
--- a/src/Web/Grand.Web.Admin/Services/ShipmentViewModelService.cs
+++ b/src/Web/Grand.Web.Admin/Services/ShipmentViewModelService.cs
@@ -33,11 +33,11 @@ public class ShipmentViewModelService : IShipmentViewModelService
private readonly IStockQuantityService _stockQuantityService;
private readonly ITranslationService _translationService;
private readonly IWarehouseService _warehouseService;
- private readonly IWorkContextAccessor _workContextAccessor;
+ private readonly IContextAccessor _contextAccessor;
public ShipmentViewModelService(
IOrderService orderService,
- IWorkContextAccessor workContextAccessor,
+ IContextAccessor contextAccessor,
IProductService productService,
IShipmentService shipmentService,
IWarehouseService warehouseService,
@@ -53,7 +53,7 @@ public class ShipmentViewModelService : IShipmentViewModelService
ShippingProviderSettings shippingProviderSettings)
{
_orderService = orderService;
- _workContextAccessor = workContextAccessor;
+ _contextAccessor = contextAccessor;
_productService = productService;
_shipmentService = shipmentService;
_warehouseService = warehouseService;
@@ -163,7 +163,7 @@ public class ShipmentViewModelService : IShipmentViewModelService
await _countryService.GetCountryByTwoLetterIsoCode(shipmentEvent.CountryCode);
shipmentStatusEventModel.Country = shipmentEventCountry != null
? shipmentEventCountry.GetTranslation(x => x.Name,
- _workContextAccessor.WorkContext.WorkingLanguage.Id)
+ _contextAccessor.WorkContext.WorkingLanguage.Id)
: shipmentEvent.CountryCode;
shipmentStatusEventModel.Date = shipmentEvent.Date;
shipmentStatusEventModel.EventName = shipmentEvent.EventName;
diff --git a/src/Web/Grand.Web.Admin/Validators/Catalog/AddAssociatedProductModelValidator.cs b/src/Web/Grand.Web.Admin/Validators/Catalog/AddAssociatedProductModelValidator.cs
index 0717dcc06..75eaed0d4 100644
--- a/src/Web/Grand.Web.Admin/Validators/Catalog/AddAssociatedProductModelValidator.cs
+++ b/src/Web/Grand.Web.Admin/Validators/Catalog/AddAssociatedProductModelValidator.cs
@@ -1,29 +1,28 @@
-using FluentValidation;
-using Grand.Business.Core.Interfaces.Catalog.Products;
+using Grand.Business.Core.Interfaces.Catalog.Products;
using Grand.Business.Core.Interfaces.Common.Localization;
+using Grand.Domain.Catalog;
using Grand.Infrastructure;
using Grand.Infrastructure.Validators;
-using Grand.Web.Admin.Extensions;
using Grand.Web.Admin.Models.Catalog;
namespace Grand.Web.Admin.Validators.Catalog;
-public class AddAssociatedProductModelValidator : BaseGrandValidator<ProductModel.AddAssociatedProductModel>
+public class AddAssociatedProductModelValidator : BaseStoreAccessValidator<ProductModel.AddAssociatedProductModel, Product>
{
+ private readonly IProductService _productService;
+
public AddAssociatedProductModelValidator(
IEnumerable<IValidatorConsumer<ProductModel.AddAssociatedProductModel>> validators,
- ITranslationService translationService, IProductService productService, IWorkContextAccessor workContextAccessor)
- : base(validators)
+ ITranslationService translationService, IProductService productService, IContextAccessor contextAccessor)
+ : base(validators, translationService, contextAccessor)
{
- if (!string.IsNullOrEmpty(workContextAccessor.WorkContext.CurrentCustomer.StaffStoreId))
- RuleFor(x => x).MustAsync(async (x, _, _) =>
- {
- var product = await productService.GetProductById(x.ProductId);
- if (product != null)
- if (!product.AccessToEntityByStore(workContextAccessor.WorkContext.CurrentCustomer.StaffStoreId))
- return false;
-
- return true;
- }).WithMessage(translationService.GetResource("Admin.Catalog.Products.Permissions"));
+ _productService = productService;
+ }
+ protected override async Task<Product> GetEntity(ProductModel.AddAssociatedProductModel model)
+ {
+ return await _productService.GetProductById(model.ProductId);
}
+
+ protected override string GetPermissionsResourceKey => "Admin.Catalog.Products.Permissions";
+
}
\ No newline at end of file
diff --git a/src/Web/Grand.Web.Admin/Validators/Catalog/AddBundleProductModelValidator.cs b/src/Web/Grand.Web.Admin/Validators/Catalog/AddBundleProductModelValidator.cs
index 621db2a69..b38560ad5 100644
--- a/src/Web/Grand.Web.Admin/Validators/Catalog/AddBundleProductModelValidator.cs
+++ b/src/Web/Grand.Web.Admin/Validators/Catalog/AddBundleProductModelValidator.cs
@@ -1,29 +1,26 @@
-using FluentValidation;
-using Grand.Business.Core.Interfaces.Catalog.Products;
+using Grand.Business.Core.Interfaces.Catalog.Products;
using Grand.Business.Core.Interfaces.Common.Localization;
+using Grand.Domain.Catalog;
using Grand.Infrastructure;
using Grand.Infrastructure.Validators;
-using Grand.Web.Admin.Extensions;
using Grand.Web.Admin.Models.Catalog;
namespace Grand.Web.Admin.Validators.Catalog;
-public class AddBundleProductModelValidator : BaseGrandValidator<ProductModel.AddBundleProductModel>
+public class AddBundleProductModelValidator : BaseStoreAccessValidator<ProductModel.AddBundleProductModel, Product>
{
+ private readonly IProductService _productService;
public AddBundleProductModelValidator(
IEnumerable<IValidatorConsumer<ProductModel.AddBundleProductModel>> validators,
- ITranslationService translationService, IProductService productService, IWorkContextAccessor workContextAccessor)
- : base(validators)
+ ITranslationService translationService, IProductService productService, IContextAccessor contextAccessor)
+ : base(validators, translationService, contextAccessor)
{
- if (!string.IsNullOrEmpty(workContextAccessor.WorkContext.CurrentCustomer.StaffStoreId))
- RuleFor(x => x).MustAsync(async (x, _, _) =>
- {
- var product = await productService.GetProductById(x.ProductId);
- if (product != null)
- if (!product.AccessToEntityByStore(workContextAccessor.WorkContext.CurrentCustomer.StaffStoreId))
- return false;
-
- return true;
- }).WithMessage(translationService.GetResource("Admin.Catalog.Products.Permissions"));
+ _productService = productService;
+ }
+ protected override async Task<Product> GetEntity(ProductModel.AddBundleProductModel model)
+ {
+ return await _productService.GetProductById(model.ProductId);
}
+
+ protected override string GetPermissionsResourceKey => "Admin.Catalog.Products.Permissions";
}
\ No newline at end of file
diff --git a/src/Web/Grand.Web.Admin/Validators/Catalog/AddCategoryProductModelValidator.cs b/src/Web/Grand.Web.Admin/Validators/Catalog/AddCategoryProductModelValidator.cs
index 7daa52fa4..4b32d8775 100644
--- a/src/Web/Grand.Web.Admin/Validators/Catalog/AddCategoryProductModelValidator.cs
+++ b/src/Web/Grand.Web.Admin/Validators/Catalog/AddCategoryProductModelValidator.cs
@@ -1,29 +1,26 @@
-using FluentValidation;
-using Grand.Business.Core.Interfaces.Catalog.Categories;
+using Grand.Business.Core.Interfaces.Catalog.Categories;
using Grand.Business.Core.Interfaces.Common.Localization;
+using Grand.Domain.Catalog;
using Grand.Infrastructure;
using Grand.Infrastructure.Validators;
-using Grand.Web.Admin.Extensions;
using Grand.Web.Admin.Models.Catalog;
namespace Grand.Web.Admin.Validators.Catalog;
-public class AddCategoryProductModelValidator : BaseGrandValidator<CategoryModel.AddCategoryProductModel>
+public class AddCategoryProductModelValidator : BaseStoreAccessValidator<CategoryModel.AddCategoryProductModel, Category>
{
+ private readonly ICategoryService _categoryService;
public AddCategoryProductModelValidator(
IEnumerable<IValidatorConsumer<CategoryModel.AddCategoryProductModel>> validators,
- ITranslationService translationService, ICategoryService categoryService, IWorkContextAccessor workContextAccessor)
- : base(validators)
+ ITranslationService translationService, ICategoryService categoryService, IContextAccessor contextAccessor)
+ : base(validators, translationService, contextAccessor)
{
- if (!string.IsNullOrEmpty(workContextAccessor.WorkContext.CurrentCustomer.StaffStoreId))
- RuleFor(x => x).MustAsync(async (x, _, _) =>
- {
- var category = await categoryService.GetCategoryById(x.CategoryId);
- if (category != null)
- if (!category.AccessToEntityByStore(workContextAccessor.WorkContext.CurrentCustomer.StaffStoreId))
- return false;
-
- return true;
- }).WithMessage(translationService.GetResource("Admin.Catalog.Categories.Permissions"));
+ _categoryService = categoryService;
+ }
+ protected override async Task<Category> GetEntity(CategoryModel.AddCategoryProductModel model)
+ {
+ return await _categoryService.GetCategoryById(model.CategoryId);
}
+
+ protected override string GetPermissionsResourceKey => "Admin.Catalog.Categories.Permissions";
}
\ No newline at end of file
diff --git a/src/Web/Grand.Web.Admin/Validators/Catalog/AddCollectionProductModelValidator.cs b/src/Web/Grand.Web.Admin/Validators/Catalog/AddCollectionProductModelValidator.cs
index b6e005a86..b8c21a574 100644
--- a/src/Web/Grand.Web.Admin/Validators/Catalog/AddCollectionProductModelValidator.cs
+++ b/src/Web/Grand.Web.Admin/Validators/Catalog/AddCollectionProductModelValidator.cs
@@ -1,29 +1,25 @@
-using FluentValidation;
-using Grand.Business.Core.Interfaces.Catalog.Collections;
+using Grand.Business.Core.Interfaces.Catalog.Collections;
using Grand.Business.Core.Interfaces.Common.Localization;
+using Grand.Domain.Catalog;
using Grand.Infrastructure;
using Grand.Infrastructure.Validators;
-using Grand.Web.Admin.Extensions;
using Grand.Web.Admin.Models.Catalog;
namespace Grand.Web.Admin.Validators.Catalog;
-public class AddCollectionProductModelValidator : BaseGrandValidator<CollectionModel.AddCollectionProductModel>
+public class AddCollectionProductModelValidator : BaseStoreAccessValidator<CollectionModel.AddCollectionProductModel, Collection>
{
+ private readonly ICollectionService _collectionService;
public AddCollectionProductModelValidator(
IEnumerable<IValidatorConsumer<CollectionModel.AddCollectionProductModel>> validators,
- ITranslationService translationService, ICollectionService collectionService, IWorkContextAccessor workContextAccessor)
- : base(validators)
+ ITranslationService translationService, ICollectionService collectionService, IContextAccessor contextAccessor)
+ : base(validators, translationService, contextAccessor)
{
- if (!string.IsNullOrEmpty(workContextAccessor.WorkContext.CurrentCustomer.StaffStoreId))
- RuleFor(x => x).MustAsync(async (x, _, _) =>
- {
- var collection = await collectionService.GetCollectionById(x.CollectionId);
- if (collection != null)
- if (!collection.AccessToEntityByStore(workContextAccessor.WorkContext.CurrentCustomer.StaffStoreId))
- return false;
-
- return true;
- }).WithMessage(translationService.GetResource("Admin.Catalog.Products.Permissions"));
+ _collectionService = collectionService;
+ }
+ protected override async Task<Collection> GetEntity(CollectionModel.AddCollectionProductModel model)
+ {
+ return await _collectionService.GetCollectionById(model.CollectionId);
}
+ protected override string GetPermissionsResourceKey => "Admin.Catalog.Products.Permissions";
}
\ No newline at end of file
diff --git a/src/Web/Grand.Web.Admin/Validators/Catalog/AddCrossSellProductModelValidator.cs b/src/Web/Grand.Web.Admin/Validators/Catalog/AddCrossSellProductModelValidator.cs
index 2dab4877b..cb27b00ff 100644
--- a/src/Web/Grand.Web.Admin/Validators/Catalog/AddCrossSellProductModelValidator.cs
+++ b/src/Web/Grand.Web.Admin/Validators/Catalog/AddCrossSellProductModelValidator.cs
@@ -1,29 +1,27 @@
-using FluentValidation;
-using Grand.Business.Core.Interfaces.Catalog.Products;
+using Grand.Business.Core.Interfaces.Catalog.Products;
using Grand.Business.Core.Interfaces.Common.Localization;
+using Grand.Domain.Catalog;
using Grand.Infrastructure;
using Grand.Infrastructure.Validators;
-using Grand.Web.Admin.Extensions;
using Grand.Web.Admin.Models.Catalog;
namespace Grand.Web.Admin.Validators.Catalog;
-public class AddCrossSellProductModelValidator : BaseGrandValidator<ProductModel.AddCrossSellProductModel>
+public class AddCrossSellProductModelValidator : BaseStoreAccessValidator<ProductModel.AddCrossSellProductModel, Product>
{
+ private readonly IProductService _productService;
public AddCrossSellProductModelValidator(
IEnumerable<IValidatorConsumer<ProductModel.AddCrossSellProductModel>> validators,
- ITranslationService translationService, IProductService productService, IWorkContextAccessor workContextAccessor)
- : base(validators)
+ ITranslationService translationService, IProductService productService, IContextAccessor contextAccessor)
+ : base(validators, translationService, contextAccessor)
{
- if (!string.IsNullOrEmpty(workContextAccessor.WorkContext.CurrentCustomer.StaffStoreId))
- RuleFor(x => x).MustAsync(async (x, _, _) =>
- {
- var product = await productService.GetProductById(x.ProductId);
- if (product != null)
- if (!product.AccessToEntityByStore(workContextAccessor.WorkContext.CurrentCustomer.StaffStoreId))
- return false;
+ _productService = productService;
+ }
- return true;
- }).WithMessage(translationService.GetResource("Admin.Catalog.Products.Permissions"));
+ protected override async Task<Product> GetEntity(ProductModel.AddCrossSellProductModel model)
+ {
+ return await _productService.GetProductById(model.ProductId);
}
+
+ protected override string GetPermissionsResourceKey => "Admin.Catalog.Products.Permissions";
}
\ No newline at end of file
diff --git a/src/Web/Grand.Web.Admin/Validators/Catalog/AddProductPriceModelValidator.cs b/src/Web/Grand.Web.Admin/Validators/Catalog/AddProductPriceModelValidator.cs
new file mode 100644
index 000000000..a4b31eeb1
--- /dev/null
+++ b/src/Web/Grand.Web.Admin/Validators/Catalog/AddProductPriceModelValidator.cs
@@ -0,0 +1,27 @@
+using Grand.Business.Core.Interfaces.Catalog.Products;
+using Grand.Business.Core.Interfaces.Common.Localization;
+using Grand.Domain.Catalog;
+using Grand.Infrastructure;
+using Grand.Infrastructure.Validators;
+using Grand.Web.Admin.Models.Catalog;
+
+namespace Grand.Web.Admin.Validators.Catalog;
+
+public class AddProductPriceModelValidator : BaseStoreAccessValidator<ProductModel.ProductPriceModel, Product>
+{
+ private readonly IProductService _productService;
+ public AddProductPriceModelValidator(
+ IEnumerable<IValidatorConsumer<ProductModel.ProductPriceModel>> validators,
+ ITranslationService translationService, IProductService productService, IContextAccessor contextAccessor)
+ : base(validators, translationService, contextAccessor)
+ {
+ _productService = productService;
+ }
+
+ protected override async Task<Product> GetEntity(ProductModel.ProductPriceModel model)
+ {
+ return await _productService.GetProductById(model.ProductId);
+ }
+
+ protected override string GetPermissionsResourceKey => "Admin.Catalog.Products.Permissions";
+}
\ No newline at end of file
diff --git a/src/Web/Grand.Web.Admin/Validators/Catalog/AddProductSpecificationAttributeModelValidator.cs b/src/Web/Grand.Web.Admin/Validators/Catalog/AddProductSpecificationAttributeModelValidator.cs
index 6b26ec7be..9055ac318 100644
--- a/src/Web/Grand.Web.Admin/Validators/Catalog/AddProductSpecificationAttributeModelValidator.cs
+++ b/src/Web/Grand.Web.Admin/Validators/Catalog/AddProductSpecificationAttributeModelValidator.cs
@@ -4,31 +4,21 @@ using Grand.Business.Core.Interfaces.Common.Localization;
using Grand.Domain.Catalog;
using Grand.Infrastructure;
using Grand.Infrastructure.Validators;
-using Grand.Web.Admin.Extensions;
using Grand.Web.Admin.Models.Catalog;
namespace Grand.Web.Admin.Validators.Catalog;
-public class
- AddProductSpecificationAttributeModelValidator : BaseGrandValidator<
- ProductModel.AddProductSpecificationAttributeModel>
+public class AddProductSpecificationAttributeModelValidator : BaseStoreAccessValidator<ProductModel.AddProductSpecificationAttributeModel, Product>
{
+ private readonly IProductService _productService;
public AddProductSpecificationAttributeModelValidator(
IEnumerable<IValidatorConsumer<ProductModel.AddProductSpecificationAttributeModel>> validators,
- ITranslationService translationService, IProductService productService, IWorkContextAccessor workContextAccessor,
+ ITranslationService translationService, IProductService productService, IContextAccessor contextAccessor,
ISpecificationAttributeService specificationAttributeService)
- : base(validators)
+ : base(validators, translationService, contextAccessor)
{
- if (!string.IsNullOrEmpty(workContextAccessor.WorkContext.CurrentCustomer.StaffStoreId))
- RuleFor(x => x).MustAsync(async (x, _, _) =>
- {
- var product = await productService.GetProductById(x.ProductId);
- if (product != null)
- if (!product.AccessToEntityByStore(workContextAccessor.WorkContext.CurrentCustomer.StaffStoreId))
- return false;
+ _productService = productService;
- return true;
- }).WithMessage(translationService.GetResource("Admin.Catalog.Products.Permissions"));
RuleFor(x => x).MustAsync(async (x, _, _) =>
{
if (x.AttributeTypeId == SpecificationAttributeType.Option)
@@ -56,4 +46,10 @@ public class
return true;
}).WithMessage(translationService.GetResource("Admin.Catalog.Products.SpecificationAttributes.Validate"));
}
+ protected override async Task<Product> GetEntity(ProductModel.AddProductSpecificationAttributeModel model)
+ {
+ return await _productService.GetProductById(model.ProductId);
+ }
+
+ protected override string GetPermissionsResourceKey => "Admin.Catalog.Products.Permissions";
}
\ No newline at end of file
diff --git a/src/Web/Grand.Web.Admin/Validators/Catalog/AddRecomendedProductModelValidator.cs b/src/Web/Grand.Web.Admin/Validators/Catalog/AddRecomendedProductModelValidator.cs
new file mode 100644
index 000000000..bd1f3e942
--- /dev/null
+++ b/src/Web/Grand.Web.Admin/Validators/Catalog/AddRecomendedProductModelValidator.cs
@@ -0,0 +1,27 @@
+using Grand.Business.Core.Interfaces.Catalog.Products;
+using Grand.Business.Core.Interfaces.Common.Localization;
+using Grand.Domain.Catalog;
+using Grand.Infrastructure;
+using Grand.Infrastructure.Validators;
+using Grand.Web.Admin.Models.Catalog;
+
+namespace Grand.Web.Admin.Validators.Catalog;
+
+public class AddRecomendedProductModelValidator : BaseStoreAccessValidator<ProductModel.AddRecommendedProductModel, Product>
+{
+ private readonly IProductService _productService;
+ public AddRecomendedProductModelValidator(
+ IEnumerable<IValidatorConsumer<ProductModel.AddRecommendedProductModel>> validators,
+ ITranslationService translationService, IProductService productService, IContextAccessor contextAccessor)
+ : base(validators, translationService, contextAccessor)
+ {
+ _productService = productService;
+ }
+
+ protected override async Task<Product> GetEntity(ProductModel.AddRecommendedProductModel model)
+ {
+ return await _productService.GetProductById(model.ProductId);
+ }
+
+ protected override string GetPermissionsResourceKey => "Admin.Catalog.Products.Permissions";
+}
\ No newline at end of file
diff --git a/src/Web/Grand.Web.Admin/Validators/Catalog/AddRelatedProductModelValidator.cs b/src/Web/Grand.Web.Admin/Validators/Catalog/AddRelatedProductModelValidator.cs
index 4e6204fb5..01c53103b 100644
--- a/src/Web/Grand.Web.Admin/Validators/Catalog/AddRelatedProductModelValidator.cs
+++ b/src/Web/Grand.Web.Admin/Validators/Catalog/AddRelatedProductModelValidator.cs
@@ -1,29 +1,27 @@
-using FluentValidation;
-using Grand.Business.Core.Interfaces.Catalog.Products;
+using Grand.Business.Core.Interfaces.Catalog.Products;
using Grand.Business.Core.Interfaces.Common.Localization;
+using Grand.Domain.Catalog;
using Grand.Infrastructure;
using Grand.Infrastructure.Validators;
-using Grand.Web.Admin.Extensions;
using Grand.Web.Admin.Models.Catalog;
namespace Grand.Web.Admin.Validators.Catalog;
-public class AddRelatedProductModelValidator : BaseGrandValidator<ProductModel.AddRelatedProductModel>
+public class AddRelatedProductModelValidator : BaseStoreAccessValidator<ProductModel.AddRelatedProductModel, Product>
{
+ private readonly IProductService _productService;
public AddRelatedProductModelValidator(
IEnumerable<IValidatorConsumer<ProductModel.AddRelatedProductModel>> validators,
- ITranslationService translationService, IProductService productService, IWorkContextAccessor workContextAccessor)
- : base(validators)
+ ITranslationService translationService, IProductService productService, IContextAccessor contextAccessor)
+ : base(validators, translationService, contextAccessor)
{
- if (!string.IsNullOrEmpty(workContextAccessor.WorkContext.CurrentCustomer.StaffStoreId))
- RuleFor(x => x).MustAsync(async (x, _, _) =>
- {
- var product = await productService.GetProductById(x.ProductId);
- if (product != null)
- if (!product.AccessToEntityByStore(workContextAccessor.WorkContext.CurrentCustomer.StaffStoreId))
- return false;
+ _productService = productService;
+ }
- return true;
- }).WithMessage(translationService.GetResource("Admin.Catalog.Products.Permissions"));
+ protected override async Task<Product> GetEntity(ProductModel.AddRelatedProductModel model)
+ {
+ return await _productService.GetProductById(model.ProductId);
}
+
+ protected override string GetPermissionsResourceKey => "Admin.Catalog.Products.Permissions";
}
\ No newline at end of file
diff --git a/src/Web/Grand.Web.Admin/Validators/Catalog/AddSimilarProductModelValidator.cs b/src/Web/Grand.Web.Admin/Validators/Catalog/AddSimilarProductModelValidator.cs
index c602fcf87..77ba13457 100644
--- a/src/Web/Grand.Web.Admin/Validators/Catalog/AddSimilarProductModelValidator.cs
+++ b/src/Web/Grand.Web.Admin/Validators/Catalog/AddSimilarProductModelValidator.cs
@@ -1,29 +1,27 @@
-using FluentValidation;
-using Grand.Business.Core.Interfaces.Catalog.Products;
+using Grand.Business.Core.Interfaces.Catalog.Products;
using Grand.Business.Core.Interfaces.Common.Localization;
+using Grand.Domain.Catalog;
using Grand.Infrastructure;
using Grand.Infrastructure.Validators;
-using Grand.Web.Admin.Extensions;
using Grand.Web.Admin.Models.Catalog;
namespace Grand.Web.Admin.Validators.Catalog;
-public class AddSimilarProductModelValidator : BaseGrandValidator<ProductModel.AddSimilarProductModel>
+public class AddSimilarProductModelValidator : BaseStoreAccessValidator<ProductModel.AddSimilarProductModel, Product>
{
+ private readonly IProductService _productService;
public AddSimilarProductModelValidator(
IEnumerable<IValidatorConsumer<ProductModel.AddSimilarProductModel>> validators,
- ITranslationService translationService, IProductService productService, IWorkContextAccessor workContextAccessor)
- : base(validators)
+ ITranslationService translationService, IProductService productService, IContextAccessor contextAccessor)
+ : base(validators, translationService, contextAccessor)
{
- if (!string.IsNullOrEmpty(workContextAccessor.WorkContext.CurrentCustomer.StaffStoreId))
- RuleFor(x => x).MustAsync(async (x, _, _) =>
- {
- var product = await productService.GetProductById(x.ProductId);
- if (product != null)
- if (!product.AccessToEntityByStore(workContextAccessor.WorkContext.CurrentCustomer.StaffStoreId))
- return false;
+ _productService = productService;
+ }
- return true;
- }).WithMessage(translationService.GetResource("Admin.Catalog.Products.Permissions"));
+ protected override async Task<Product> GetEntity(ProductModel.AddSimilarProductModel model)
+ {
+ return await _productService.GetProductById(model.ProductId);
}
+
+ protected override string GetPermissionsResourceKey => "Admin.Catalog.Products.Permissions";
}
\ No newline at end of file
diff --git a/src/Web/Grand.Web.Admin/Validators/Catalog/AssociatedProductModelValidator.cs b/src/Web/Grand.Web.Admin/Validators/Catalog/AssociatedProductModelValidator.cs
index cba14971c..a859f35cb 100644
--- a/src/Web/Grand.Web.Admin/Validators/Catalog/AssociatedProductModelValidator.cs
+++ b/src/Web/Grand.Web.Admin/Validators/Catalog/AssociatedProductModelValidator.cs
@@ -1,29 +1,26 @@
-using FluentValidation;
-using Grand.Business.Core.Interfaces.Catalog.Products;
+using Grand.Business.Core.Interfaces.Catalog.Products;
using Grand.Business.Core.Interfaces.Common.Localization;
+using Grand.Domain.Catalog;
using Grand.Infrastructure;
using Grand.Infrastructure.Validators;
-using Grand.Web.Admin.Extensions;
using Grand.Web.Admin.Models.Catalog;
namespace Grand.Web.Admin.Validators.Catalog;
-public class AssociatedProductModelValidator : BaseGrandValidator<ProductModel.AssociatedProductModel>
+public class AssociatedProductModelValidator : BaseStoreAccessValidator<ProductModel.AssociatedProductModel, Product>
{
+ private readonly IProductService _productService;
public AssociatedProductModelValidator(
IEnumerable<IValidatorConsumer<ProductModel.AssociatedProductModel>> validators,
- ITranslationService translationService, IProductService productService, IWorkContextAccessor workContextAccessor)
- : base(validators)
+ ITranslationService translationService, IProductService productService, IContextAccessor contextAccessor)
+ : base(validators, translationService, contextAccessor)
{
- if (!string.IsNullOrEmpty(workContextAccessor.WorkContext.CurrentCustomer.StaffStoreId))
- RuleFor(x => x).MustAsync(async (x, _, _) =>
- {
- var product = await productService.GetProductById(x.ProductId);
- if (product != null)
- if (!product.AccessToEntityByStore(workContextAccessor.WorkContext.CurrentCustomer.StaffStoreId))
- return false;
-
- return true;
- }).WithMessage(translationService.GetResource("Admin.Catalog.Products.Permissions"));
+ _productService = productService;
+ }
+ protected override async Task<Product> GetEntity(ProductModel.AssociatedProductModel model)
+ {
+ return await _productService.GetProductById(model.ProductId);
}
+
+ protected override string GetPermissionsResourceKey => "Admin.Catalog.Products.Permissions";
}
\ No newline at end of file
diff --git a/src/Web/Grand.Web.Admin/Validators/Catalog/BaseStoreAccessValidator.cs b/src/Web/Grand.Web.Admin/Validators/Catalog/BaseStoreAccessValidator.cs
new file mode 100644
index 000000000..4235a98c7
--- /dev/null
+++ b/src/Web/Grand.Web.Admin/Validators/Catalog/BaseStoreAccessValidator.cs
@@ -0,0 +1,39 @@
+using Grand.Business.Core.Interfaces.Common.Localization;
+using Grand.Infrastructure.Validators;
+using Grand.Infrastructure;
+using FluentValidation;
+using Grand.Domain;
+using Grand.Domain.Stores;
+using Grand.Web.Admin.Extensions;
+
+namespace Grand.Web.Admin.Validators.Catalog
+{
+ public abstract class BaseStoreAccessValidator<TModel, TEntity> : BaseGrandValidator<TModel> where TEntity : BaseEntity, IStoreLinkEntity where TModel : class
+ {
+ protected readonly IContextAccessor _contextAccessor;
+ protected readonly ITranslationService _translationService;
+
+ protected BaseStoreAccessValidator(
+ IEnumerable<IValidatorConsumer<TModel>> validators,
+ ITranslationService translationService,
+ IContextAccessor contextAccessor)
+ : base(validators)
+ {
+ _contextAccessor = contextAccessor;
+ _translationService = translationService;
+
+ if (!string.IsNullOrEmpty(_contextAccessor.WorkContext.CurrentCustomer.StaffStoreId))
+ {
+ RuleFor(x => x).MustAsync(async (model, cancellationToken) =>
+ {
+ var entity = await GetEntity(model);
+ if (entity != null && !entity.AccessToEntityByStore(_contextAccessor.WorkContext.CurrentCustomer.StaffStoreId))
+ return false;
+ return true;
+ }).WithMessage(_translationService.GetResource(GetPermissionsResourceKey));
+ }
+ }
+ protected abstract Task<TEntity> GetEntity(TModel model);
+ protected abstract string GetPermissionsResourceKey { get; }
+ }
+}
diff --git a/src/Web/Grand.Web.Admin/Validators/Catalog/BundleProductModelValidator.cs b/src/Web/Grand.Web.Admin/Validators/Catalog/BundleProductModelValidator.cs
index c15665671..45858681a 100644
--- a/src/Web/Grand.Web.Admin/Validators/Catalog/BundleProductModelValidator.cs
+++ b/src/Web/Grand.Web.Admin/Validators/Catalog/BundleProductModelValidator.cs
@@ -1,6 +1,8 @@
using FluentValidation;
+using Grand.Business.Catalog.Services.Products;
using Grand.Business.Core.Interfaces.Catalog.Products;
using Grand.Business.Core.Interfaces.Common.Localization;
+using Grand.Domain.Catalog;
using Grand.Infrastructure;
using Grand.Infrastructure.Validators;
using Grand.Web.Admin.Extensions;
@@ -8,22 +10,20 @@ using Grand.Web.Admin.Models.Catalog;
namespace Grand.Web.Admin.Validators.Catalog;
-public class BundleProductModelValidator : BaseGrandValidator<ProductModel.BundleProductModel>
+public class BundleProductModelValidator : BaseStoreAccessValidator<ProductModel.BundleProductModel, Product>
{
+ private readonly IProductService _productService;
public BundleProductModelValidator(
IEnumerable<IValidatorConsumer<ProductModel.BundleProductModel>> validators,
- ITranslationService translationService, IProductService productService, IWorkContextAccessor workContextAccessor)
- : base(validators)
+ ITranslationService translationService, IProductService productService, IContextAccessor contextAccessor)
+ : base(validators, translationService, contextAccessor)
{
- if (!string.IsNullOrEmpty(workContextAccessor.WorkContext.CurrentCustomer.StaffStoreId))
- RuleFor(x => x).MustAsync(async (x, _, _) =>
- {
- var product = await productService.GetProductById(x.ProductBundleId);
- if (product != null)
- if (!product.AccessToEntityByStore(workContextAccessor.WorkContext.CurrentCustomer.StaffStoreId))
- return false;
-
- return true;
- }).WithMessage(translationService.GetResource("Admin.Catalog.Products.Permissions"));
+ _productService = productService;
+ }
+ protected override async Task<Product> GetEntity(ProductModel.BundleProductModel model)
+ {
+ return await _productService.GetProductById(model.ProductId);
}
+
+ protected override string GetPermissionsResourceKey => "Admin.Catalog.Products.Permissions";
}
\ No newline at end of file
diff --git a/src/Web/Grand.Web.Admin/Validators/Catalog/CategoryProductModelValidator.cs b/src/Web/Grand.Web.Admin/Validators/Catalog/CategoryProductModelValidator.cs
index e8c992a00..87b515222 100644
--- a/src/Web/Grand.Web.Admin/Validators/Catalog/CategoryProductModelValidator.cs
+++ b/src/Web/Grand.Web.Admin/Validators/Catalog/CategoryProductModelValidator.cs
@@ -1,29 +1,26 @@
-using FluentValidation;
-using Grand.Business.Core.Interfaces.Catalog.Categories;
+using Grand.Business.Core.Interfaces.Catalog.Categories;
using Grand.Business.Core.Interfaces.Common.Localization;
+using Grand.Domain.Catalog;
using Grand.Infrastructure;
using Grand.Infrastructure.Validators;
-using Grand.Web.Admin.Extensions;
using Grand.Web.Admin.Models.Catalog;
namespace Grand.Web.Admin.Validators.Catalog;
-public class CategoryProductModelValidator : BaseGrandValidator<CategoryModel.CategoryProductModel>
+public class CategoryProductModelValidator : BaseStoreAccessValidator<CategoryModel.CategoryProductModel, Category>
{
+ private readonly ICategoryService _categoryService;
public CategoryProductModelValidator(
IEnumerable<IValidatorConsumer<CategoryModel.CategoryProductModel>> validators,
- ITranslationService translationService, ICategoryService categoryService, IWorkContextAccessor workContextAccessor)
- : base(validators)
+ ITranslationService translationService, ICategoryService categoryService, IContextAccessor contextAccessor)
+ : base(validators, translationService, contextAccessor)
{
- if (!string.IsNullOrEmpty(workContextAccessor.WorkContext.CurrentCustomer.StaffStoreId))
- RuleFor(x => x).MustAsync(async (x, _, _) =>
- {
- var category = await categoryService.GetCategoryById(x.CategoryId);
- if (category != null)
- if (!category.AccessToEntityByStore(workContextAccessor.WorkContext.CurrentCustomer.StaffStoreId))
- return false;
-
- return true;
- }).WithMessage(translationService.GetResource("Admin.Catalog.Categories.Permissions"));
+ _categoryService = categoryService;
+ }
+ protected override async Task<Category> GetEntity(CategoryModel.CategoryProductModel model)
+ {
+ return await _categoryService.GetCategoryById(model.CategoryId);
}
+
+ protected override string GetPermissionsResourceKey => "Admin.Catalog.Categories.Permissions";
}
\ No newline at end of file
diff --git a/src/Web/Grand.Web.Admin/Validators/Catalog/CollectionProductModelValidator.cs b/src/Web/Grand.Web.Admin/Validators/Catalog/CollectionProductModelValidator.cs
index ba7c67c8c..48e18385b 100644
--- a/src/Web/Grand.Web.Admin/Validators/Catalog/CollectionProductModelValidator.cs
+++ b/src/Web/Grand.Web.Admin/Validators/Catalog/CollectionProductModelValidator.cs
@@ -1,29 +1,26 @@
-using FluentValidation;
-using Grand.Business.Core.Interfaces.Catalog.Collections;
+using Grand.Business.Core.Interfaces.Catalog.Collections;
using Grand.Business.Core.Interfaces.Common.Localization;
+using Grand.Domain.Catalog;
using Grand.Infrastructure;
using Grand.Infrastructure.Validators;
-using Grand.Web.Admin.Extensions;
using Grand.Web.Admin.Models.Catalog;
namespace Grand.Web.Admin.Validators.Catalog;
-public class CollectionProductModelValidator : BaseGrandValidator<CollectionModel.CollectionProductModel>
+public class CollectionProductModelValidator : BaseStoreAccessValidator<CollectionModel.CollectionProductModel, Collection>
{
+ private readonly ICollectionService _collectionService;
public CollectionProductModelValidator(
IEnumerable<IValidatorConsumer<CollectionModel.CollectionProductModel>> validators,
- ITranslationService translationService, ICollectionService collectionService, IWorkContextAccessor workContextAccessor)
- : base(validators)
+ ITranslationService translationService, ICollectionService collectionService, IContextAccessor contextAccessor)
+ : base(validators, translationService, contextAccessor)
{
- if (!string.IsNullOrEmpty(workContextAccessor.WorkContext.CurrentCustomer.StaffStoreId))
- RuleFor(x => x).MustAsync(async (x, _, _) =>
- {
- var collection = await collectionService.GetCollectionById(x.CollectionId);
- if (collection != null)
- if (!collection.AccessToEntityByStore(workContextAccessor.WorkContext.CurrentCustomer.StaffStoreId))
- return false;
-
- return true;
- }).WithMessage(translationService.GetResource("Admin.Catalog.Collections.Permissions"));
+ _collectionService = collectionService;
+ }
+ protected override async Task<Collection> GetEntity(CollectionModel.CollectionProductModel model)
+ {
+ return await _collectionService.GetCollectionById(model.CollectionId);
}
+
+ protected override string GetPermissionsResourceKey => "Admin.Catalog.Collections.Permissions";
}
\ No newline at end of file
diff --git a/src/Web/Grand.Web.Admin/Validators/Catalog/CrossSellProductModelValidator.cs b/src/Web/Grand.Web.Admin/Validators/Catalog/CrossSellProductModelValidator.cs
index 3d896c230..ccd0526a9 100644
--- a/src/Web/Grand.Web.Admin/Validators/Catalog/CrossSellProductModelValidator.cs
+++ b/src/Web/Grand.Web.Admin/Validators/Catalog/CrossSellProductModelValidator.cs
@@ -1,29 +1,27 @@
-using FluentValidation;
-using Grand.Business.Core.Interfaces.Catalog.Products;
+using Grand.Business.Core.Interfaces.Catalog.Products;
using Grand.Business.Core.Interfaces.Common.Localization;
+using Grand.Domain.Catalog;
using Grand.Infrastructure;
using Grand.Infrastructure.Validators;
-using Grand.Web.Admin.Extensions;
using Grand.Web.Admin.Models.Catalog;
namespace Grand.Web.Admin.Validators.Catalog;
-public class CrossSellProductModelValidator : BaseGrandValidator<ProductModel.CrossSellProductModel>
+public class CrossSellProductModelValidator : BaseStoreAccessValidator<ProductModel.CrossSellProductModel, Product>
{
+ private readonly IProductService _productService;
+
public CrossSellProductModelValidator(
IEnumerable<IValidatorConsumer<ProductModel.CrossSellProductModel>> validators,
- ITranslationService translationService, IProductService productService, IWorkContextAccessor workContextAccessor)
- : base(validators)
+ ITranslationService translationService, IProductService productService, IContextAccessor contextAccessor)
+ : base(validators, translationService, contextAccessor)
{
- if (!string.IsNullOrEmpty(workContextAccessor.WorkContext.CurrentCustomer.StaffStoreId))
- RuleFor(x => x).MustAsync(async (x, _, _) =>
- {
- var product = await productService.GetProductById(x.ProductId);
- if (product != null)
- if (!product.AccessToEntityByStore(workContextAccessor.WorkContext.CurrentCustomer.StaffStoreId))
- return false;
-
- return true;
- }).WithMessage(translationService.GetResource("Admin.Catalog.Products.Permissions"));
+ _productService = productService;
}
+ protected override async Task<Product> GetEntity(ProductModel.CrossSellProductModel model)
+ {
+ return await _productService.GetProductById(model.ProductId);
+ }
+
+ protected override string GetPermissionsResourceKey => "Admin.Catalog.Products.Permissions";
}
\ No newline at end of file
diff --git a/src/Web/Grand.Web.Admin/Validators/Catalog/ProductAttributeMappingModelValidator.cs b/src/Web/Grand.Web.Admin/Validators/Catalog/ProductAttributeMappingModelValidator.cs
index f93f26d4e..0c7a440ae 100644
--- a/src/Web/Grand.Web.Admin/Validators/Catalog/ProductAttributeMappingModelValidator.cs
+++ b/src/Web/Grand.Web.Admin/Validators/Catalog/ProductAttributeMappingModelValidator.cs
@@ -1,29 +1,27 @@
-using FluentValidation;
-using Grand.Business.Core.Interfaces.Catalog.Products;
+using Grand.Business.Core.Interfaces.Catalog.Products;
using Grand.Business.Core.Interfaces.Common.Localization;
+using Grand.Domain.Catalog;
using Grand.Infrastructure;
using Grand.Infrastructure.Validators;
-using Grand.Web.Admin.Extensions;
using Grand.Web.Admin.Models.Catalog;
namespace Grand.Web.Admin.Validators.Catalog;
-public class ProductAttributeMappingModelValidator : BaseGrandValidator<ProductModel.ProductAttributeMappingModel>
+public class ProductAttributeMappingModelValidator : BaseStoreAccessValidator<ProductModel.ProductAttributeMappingModel, Product>
{
+ private readonly IProductService _productService;
+
public ProductAttributeMappingModelValidator(
IEnumerable<IValidatorConsumer<ProductModel.ProductAttributeMappingModel>> validators,
- ITranslationService translationService, IProductService productService, IWorkContextAccessor workContextAccessor)
- : base(validators)
+ ITranslationService translationService, IProductService productService, IContextAccessor contextAccessor)
+ : base(validators, translationService, contextAccessor)
{
- if (!string.IsNullOrEmpty(workContextAccessor.WorkContext.CurrentCustomer.StaffStoreId))
- RuleFor(x => x).MustAsync(async (x, _, _) =>
- {
- var product = await productService.GetProductById(x.ProductId);
- if (product != null)
- if (!product.AccessToEntityByStore(workContextAccessor.WorkContext.CurrentCustomer.StaffStoreId))
- return false;
-
- return true;
- }).WithMessage(translationService.GetResource("Admin.Catalog.Products.Permissions"));
+ _productService = productService;
}
+ protected override async Task<Product> GetEntity(ProductModel.ProductAttributeMappingModel model)
+ {
+ return await _productService.GetProductById(model.ProductId);
+ }
+
+ protected override string GetPermissionsResourceKey => "Admin.Catalog.Products.Permissions";
}
\ No newline at end of file
diff --git a/src/Web/Grand.Web.Admin/Validators/Catalog/ProductAttributeValueModelValidator.cs b/src/Web/Grand.Web.Admin/Validators/Catalog/ProductAttributeValueModelValidator.cs
index fffe45682..c5661441a 100644
--- a/src/Web/Grand.Web.Admin/Validators/Catalog/ProductAttributeValueModelValidator.cs
+++ b/src/Web/Grand.Web.Admin/Validators/Catalog/ProductAttributeValueModelValidator.cs
@@ -4,18 +4,19 @@ using Grand.Business.Core.Interfaces.Common.Localization;
using Grand.Domain.Catalog;
using Grand.Infrastructure;
using Grand.Infrastructure.Validators;
-using Grand.Web.Admin.Extensions;
using Grand.Web.Admin.Models.Catalog;
namespace Grand.Web.Admin.Validators.Catalog;
-public class ProductAttributeValueModelValidator : BaseGrandValidator<ProductModel.ProductAttributeValueModel>
+public class ProductAttributeValueModelValidator : BaseStoreAccessValidator<ProductModel.ProductAttributeValueModel, Product>
{
+ private readonly IProductService _productService;
public ProductAttributeValueModelValidator(
IEnumerable<IValidatorConsumer<ProductModel.ProductAttributeValueModel>> validators,
- ITranslationService translationService, IProductService productService, IWorkContextAccessor workContextAccessor)
- : base(validators)
+ ITranslationService translationService, IProductService productService, IContextAccessor contextAccessor)
+ : base(validators, translationService, contextAccessor)
{
+ _productService = productService;
RuleFor(x => x.Name)
.NotEmpty()
.WithMessage(
@@ -28,16 +29,6 @@ public class ProductAttributeValueModelValidator : BaseGrandValidator<ProductMod
"Admin.Catalog.Products.ProductAttributes.Attributes.Values.Fields.Quantity.GreaterThanOrEqualTo1"))
.When(x => x.AttributeValueTypeId == AttributeValueType.AssociatedToProduct);
- if (!string.IsNullOrEmpty(workContextAccessor.WorkContext.CurrentCustomer.StaffStoreId))
- RuleFor(x => x).MustAsync(async (x, _, _) =>
- {
- var product = await productService.GetProductById(x.ProductId);
- if (product != null)
- if (!product.AccessToEntityByStore(workContextAccessor.WorkContext.CurrentCustomer.StaffStoreId))
- return false;
-
- return true;
- }).WithMessage(translationService.GetResource("Admin.Catalog.Products.Permissions"));
RuleFor(x => x).CustomAsync(async (x, context, _) =>
{
var product = await productService.GetProductById(x.ProductId);
@@ -46,17 +37,24 @@ public class ProductAttributeValueModelValidator : BaseGrandValidator<ProductMod
switch (productAttributeMapping?.AttributeControlTypeId)
{
case AttributeControlType.ColorSquares:
- {
- //ensure valid color is chosen/entered
- if (string.IsNullOrEmpty(x.ColorSquaresRgb))
- context.AddFailure("Color is required");
- break;
- }
+ {
+ //ensure valid color is chosen/entered
+ if (string.IsNullOrEmpty(x.ColorSquaresRgb))
+ context.AddFailure("Color is required");
+ break;
+ }
//ensure a picture is uploaded
case AttributeControlType.ImageSquares when string.IsNullOrEmpty(x.ImageSquaresPictureId):
context.AddFailure("Image is required");
break;
}
});
+
}
+ protected override async Task<Product> GetEntity(ProductModel.ProductAttributeValueModel model)
+ {
+ return await _productService.GetProductById(model.ProductId);
+ }
+
+ protected override string GetPermissionsResourceKey => "Admin.Catalog.Products.Permissions";
}
\ No newline at end of file
diff --git a/src/Web/Grand.Web.Admin/Validators/Catalog/ProductCategoryModelValidator.cs b/src/Web/Grand.Web.Admin/Validators/Catalog/ProductCategoryModelValidator.cs
index 44ae43e6e..718b73402 100644
--- a/src/Web/Grand.Web.Admin/Validators/Catalog/ProductCategoryModelValidator.cs
+++ b/src/Web/Grand.Web.Admin/Validators/Catalog/ProductCategoryModelValidator.cs
@@ -1,29 +1,27 @@
-using FluentValidation;
-using Grand.Business.Core.Interfaces.Catalog.Products;
+using Grand.Business.Core.Interfaces.Catalog.Products;
using Grand.Business.Core.Interfaces.Common.Localization;
+using Grand.Domain.Catalog;
using Grand.Infrastructure;
using Grand.Infrastructure.Validators;
-using Grand.Web.Admin.Extensions;
using Grand.Web.Admin.Models.Catalog;
namespace Grand.Web.Admin.Validators.Catalog;
-public class ProductCategoryModelValidator : BaseGrandValidator<ProductModel.ProductCategoryModel>
+public class ProductCategoryModelValidator : BaseStoreAccessValidator<ProductModel.ProductCategoryModel, Product>
{
+ private readonly IProductService _productService;
+
public ProductCategoryModelValidator(
IEnumerable<IValidatorConsumer<ProductModel.ProductCategoryModel>> validators,
- ITranslationService translationService, IProductService productService, IWorkContextAccessor workContextAccessor)
- : base(validators)
+ ITranslationService translationService, IProductService productService, IContextAccessor contextAccessor)
+ : base(validators, translationService, contextAccessor)
{
- if (!string.IsNullOrEmpty(workContextAccessor.WorkContext.CurrentCustomer.StaffStoreId))
- RuleFor(x => x).MustAsync(async (x, _, _) =>
- {
- var product = await productService.GetProductById(x.ProductId);
- if (product != null)
- if (!product.AccessToEntityByStore(workContextAccessor.WorkContext.CurrentCustomer.StaffStoreId))
- return false;
-
- return true;
- }).WithMessage(translationService.GetResource("Admin.Catalog.Products.Permissions"));
+ _productService = productService;
}
+ protected override async Task<Product> GetEntity(ProductModel.ProductCategoryModel model)
+ {
+ return await _productService.GetProductById(model.ProductId);
+ }
+
+ protected override string GetPermissionsResourceKey => "Admin.Catalog.Products.Permissions";
}
\ No newline at end of file
diff --git a/src/Web/Grand.Web.Admin/Validators/Catalog/ProductCollectionModelValidator.cs b/src/Web/Grand.Web.Admin/Validators/Catalog/ProductCollectionModelValidator.cs
index 9ee02b72f..5fe838c39 100644
--- a/src/Web/Grand.Web.Admin/Validators/Catalog/ProductCollectionModelValidator.cs
+++ b/src/Web/Grand.Web.Admin/Validators/Catalog/ProductCollectionModelValidator.cs
@@ -1,29 +1,26 @@
-using FluentValidation;
-using Grand.Business.Core.Interfaces.Catalog.Products;
+using Grand.Business.Core.Interfaces.Catalog.Products;
using Grand.Business.Core.Interfaces.Common.Localization;
+using Grand.Domain.Catalog;
using Grand.Infrastructure;
using Grand.Infrastructure.Validators;
-using Grand.Web.Admin.Extensions;
using Grand.Web.Admin.Models.Catalog;
namespace Grand.Web.Admin.Validators.Catalog;
-public class ProductCollectionModelValidator : BaseGrandValidator<ProductModel.ProductCollectionModel>
+public class ProductCollectionModelValidator : BaseStoreAccessValidator<ProductModel.ProductCollectionModel, Product>
{
+ private readonly IProductService _productService;
+
public ProductCollectionModelValidator(
IEnumerable<IValidatorConsumer<ProductModel.ProductCollectionModel>> validators,
- ITranslationService translationService, IProductService productService, IWorkContextAccessor workContextAccessor)
- : base(validators)
+ ITranslationService translationService, IProductService productService, IContextAccessor contextAccessor)
+ : base(validators, translationService, contextAccessor)
{
- if (!string.IsNullOrEmpty(workContextAccessor.WorkContext.CurrentCustomer.StaffStoreId))
- RuleFor(x => x).MustAsync(async (x, _, _) =>
- {
- var product = await productService.GetProductById(x.ProductId);
- if (product != null)
- if (!product.AccessToEntityByStore(workContextAccessor.WorkContext.CurrentCustomer.StaffStoreId))
- return false;
-
- return true;
- }).WithMessage(translationService.GetResource("Admin.Catalog.Products.Permissions"));
+ _productService = productService;
+ }
+ protected override async Task<Product> GetEntity(ProductModel.ProductCollectionModel model)
+ {
+ return await _productService.GetProductById(model.ProductId);
}
-}
\ No newline at end of file
+ protected override string GetPermissionsResourceKey => "Admin.Catalog.Products.Permissions";
+}
diff --git a/src/Web/Grand.Web.Admin/Validators/Catalog/ProductPictureModelValidator.cs b/src/Web/Grand.Web.Admin/Validators/Catalog/ProductPictureModelValidator.cs
index bf3ff9342..c31775908 100644
--- a/src/Web/Grand.Web.Admin/Validators/Catalog/ProductPictureModelValidator.cs
+++ b/src/Web/Grand.Web.Admin/Validators/Catalog/ProductPictureModelValidator.cs
@@ -1,29 +1,26 @@
-using FluentValidation;
-using Grand.Business.Core.Interfaces.Catalog.Products;
+using Grand.Business.Core.Interfaces.Catalog.Products;
using Grand.Business.Core.Interfaces.Common.Localization;
+using Grand.Domain.Catalog;
using Grand.Infrastructure;
using Grand.Infrastructure.Validators;
-using Grand.Web.Admin.Extensions;
using Grand.Web.Admin.Models.Catalog;
namespace Grand.Web.Admin.Validators.Catalog;
-public class ProductPictureModelValidator : BaseGrandValidator<ProductModel.ProductPictureModel>
+public class ProductPictureModelValidator : BaseStoreAccessValidator<ProductModel.ProductPictureModel, Product>
{
+ private readonly IProductService _productService;
+
public ProductPictureModelValidator(
IEnumerable<IValidatorConsumer<ProductModel.ProductPictureModel>> validators,
- ITranslationService translationService, IProductService productService, IWorkContextAccessor workContextAccessor)
- : base(validators)
+ ITranslationService translationService, IProductService productService, IContextAccessor contextAccessor)
+ : base(validators, translationService, contextAccessor)
{
- if (!string.IsNullOrEmpty(workContextAccessor.WorkContext.CurrentCustomer.StaffStoreId))
- RuleFor(x => x).MustAsync(async (x, _, _) =>
- {
- var product = await productService.GetProductById(x.ProductId);
- if (product != null)
- if (!product.AccessToEntityByStore(workContextAccessor.WorkContext.CurrentCustomer.StaffStoreId))
- return false;
-
- return true;
- }).WithMessage(translationService.GetResource("Admin.Catalog.Products.Permissions"));
+ _productService = productService;
+ }
+ protected override async Task<Product> GetEntity(ProductModel.ProductPictureModel model)
+ {
+ return await _productService.GetProductById(model.ProductId);
}
-}
\ No newline at end of file
+ protected override string GetPermissionsResourceKey => "Admin.Catalog.Products.Permissions";
+}
diff --git a/src/Web/Grand.Web.Admin/Validators/Catalog/ProductSpecificationAttributeModelValidator.cs b/src/Web/Grand.Web.Admin/Validators/Catalog/ProductSpecificationAttributeModelValidator.cs
index 50892e588..a38eb3eed 100644
--- a/src/Web/Grand.Web.Admin/Validators/Catalog/ProductSpecificationAttributeModelValidator.cs
+++ b/src/Web/Grand.Web.Admin/Validators/Catalog/ProductSpecificationAttributeModelValidator.cs
@@ -1,29 +1,26 @@
-using FluentValidation;
-using Grand.Business.Core.Interfaces.Catalog.Products;
+using Grand.Business.Core.Interfaces.Catalog.Products;
using Grand.Business.Core.Interfaces.Common.Localization;
+using Grand.Domain.Catalog;
using Grand.Infrastructure;
using Grand.Infrastructure.Validators;
-using Grand.Web.Admin.Extensions;
using Grand.Web.Admin.Models.Catalog;
namespace Grand.Web.Admin.Validators.Catalog;
-public class ProductSpecificationAttributeModelValidator : BaseGrandValidator<ProductSpecificationAttributeModel>
+public class ProductSpecificationAttributeModelValidator : BaseStoreAccessValidator<ProductSpecificationAttributeModel, Product>
{
+ private readonly IProductService _productService;
+
public ProductSpecificationAttributeModelValidator(
IEnumerable<IValidatorConsumer<ProductSpecificationAttributeModel>> validators,
- ITranslationService translationService, IProductService productService, IWorkContextAccessor workContextAccessor)
- : base(validators)
+ ITranslationService translationService, IProductService productService, IContextAccessor contextAccessor)
+ : base(validators, translationService, contextAccessor)
{
- if (!string.IsNullOrEmpty(workContextAccessor.WorkContext.CurrentCustomer.StaffStoreId))
- RuleFor(x => x).MustAsync(async (x, _, _) =>
- {
- var product = await productService.GetProductById(x.ProductId);
- if (product != null)
- if (!product.AccessToEntityByStore(workContextAccessor.WorkContext.CurrentCustomer.StaffStoreId))
- return false;
-
- return true;
- }).WithMessage(translationService.GetResource("Admin.Catalog.Products.Permissions"));
+ _productService = productService;
+ }
+ protected override async Task<Product> GetEntity(ProductSpecificationAttributeModel model)
+ {
+ return await _productService.GetProductById(model.ProductId);
}
+ protected override string GetPermissionsResourceKey => "Admin.Catalog.Products.Permissions";
}
\ No newline at end of file
diff --git a/src/Web/Grand.Web.Admin/Validators/Catalog/RecomendedProductModelValidator.cs b/src/Web/Grand.Web.Admin/Validators/Catalog/RecomendedProductModelValidator.cs
new file mode 100644
index 000000000..7fb87c2ba
--- /dev/null
+++ b/src/Web/Grand.Web.Admin/Validators/Catalog/RecomendedProductModelValidator.cs
@@ -0,0 +1,26 @@
+using Grand.Business.Core.Interfaces.Catalog.Products;
+using Grand.Business.Core.Interfaces.Common.Localization;
+using Grand.Domain.Catalog;
+using Grand.Infrastructure;
+using Grand.Infrastructure.Validators;
+using Grand.Web.Admin.Models.Catalog;
+
+namespace Grand.Web.Admin.Validators.Catalog;
+
+public class RecomendedProductModelValidator : BaseStoreAccessValidator<ProductModel.RecommendedProductModel, Product>
+{
+ private readonly IProductService _productService;
+
+ public RecomendedProductModelValidator(
+ IEnumerable<IValidatorConsumer<ProductModel.RecommendedProductModel>> validators,
+ ITranslationService translationService, IProductService productService, IContextAccessor contextAccessor)
+ : base(validators, translationService, contextAccessor)
+ {
+ _productService = productService;
+ }
+ protected override async Task<Product> GetEntity(ProductModel.RecommendedProductModel model)
+ {
+ return await _productService.GetProductById(model.ProductId);
+ }
+ protected override string GetPermissionsResourceKey => "Admin.Catalog.Products.Permissions";
+}
diff --git a/src/Web/Grand.Web.Admin/Validators/Catalog/RelatedProductModelValidator.cs b/src/Web/Grand.Web.Admin/Validators/Catalog/RelatedProductModelValidator.cs
index a39cdf3c7..0f160bd41 100644
--- a/src/Web/Grand.Web.Admin/Validators/Catalog/RelatedProductModelValidator.cs
+++ b/src/Web/Grand.Web.Admin/Validators/Catalog/RelatedProductModelValidator.cs
@@ -1,29 +1,26 @@
-using FluentValidation;
-using Grand.Business.Core.Interfaces.Catalog.Products;
+using Grand.Business.Core.Interfaces.Catalog.Products;
using Grand.Business.Core.Interfaces.Common.Localization;
+using Grand.Domain.Catalog;
using Grand.Infrastructure;
using Grand.Infrastructure.Validators;
-using Grand.Web.Admin.Extensions;
using Grand.Web.Admin.Models.Catalog;
namespace Grand.Web.Admin.Validators.Catalog;
-public class RelatedProductModelValidator : BaseGrandValidator<ProductModel.RelatedProductModel>
+public class RelatedProductModelValidator : BaseStoreAccessValidator<ProductModel.RelatedProductModel, Product>
{
+ private readonly IProductService _productService;
+
public RelatedProductModelValidator(
IEnumerable<IValidatorConsumer<ProductModel.RelatedProductModel>> validators,
- ITranslationService translationService, IProductService productService, IWorkContextAccessor workContextAccessor)
- : base(validators)
+ ITranslationService translationService, IProductService productService, IContextAccessor contextAccessor)
+ : base(validators, translationService, contextAccessor)
{
- if (!string.IsNullOrEmpty(workContextAccessor.WorkContext.CurrentCustomer.StaffStoreId))
- RuleFor(x => x).MustAsync(async (x, _, _) =>
- {
- var product = await productService.GetProductById(x.ProductId1);
- if (product != null)
- if (!product.AccessToEntityByStore(workContextAccessor.WorkContext.CurrentCustomer.StaffStoreId))
- return false;
-
- return true;
- }).WithMessage(translationService.GetResource("Admin.Catalog.Products.Permissions"));
+ _productService = productService;
+ }
+ protected override async Task<Product> GetEntity(ProductModel.RelatedProductModel model)
+ {
+ return await _productService.GetProductById(model.ProductId1);
}
-}
\ No newline at end of file
+ protected override string GetPermissionsResourceKey => "Admin.Catalog.Products.Permissions";
+}
diff --git a/src/Web/Grand.Web.Admin/Validators/Catalog/SimilarProductModelValidator.cs b/src/Web/Grand.Web.Admin/Validators/Catalog/SimilarProductModelValidator.cs
index b91a580b0..4af8124b5 100644
--- a/src/Web/Grand.Web.Admin/Validators/Catalog/SimilarProductModelValidator.cs
+++ b/src/Web/Grand.Web.Admin/Validators/Catalog/SimilarProductModelValidator.cs
@@ -1,29 +1,26 @@
-using FluentValidation;
-using Grand.Business.Core.Interfaces.Catalog.Products;
+using Grand.Business.Core.Interfaces.Catalog.Products;
using Grand.Business.Core.Interfaces.Common.Localization;
+using Grand.Domain.Catalog;
using Grand.Infrastructure;
using Grand.Infrastructure.Validators;
-using Grand.Web.Admin.Extensions;
using Grand.Web.Admin.Models.Catalog;
namespace Grand.Web.Admin.Validators.Catalog;
-public class SimilarProductModelValidator : BaseGrandValidator<ProductModel.SimilarProductModel>
+public class SimilarProductModelValidator : BaseStoreAccessValidator<ProductModel.SimilarProductModel, Product>
{
+ private readonly IProductService _productService;
+
public SimilarProductModelValidator(
IEnumerable<IValidatorConsumer<ProductModel.SimilarProductModel>> validators,
- ITranslationService translationService, IProductService productService, IWorkContextAccessor workContextAccessor)
- : base(validators)
+ ITranslationService translationService, IProductService productService, IContextAccessor contextAccessor)
+ : base(validators, translationService, contextAccessor)
{
- if (!string.IsNullOrEmpty(workContextAccessor.WorkContext.CurrentCustomer.StaffStoreId))
- RuleFor(x => x).MustAsync(async (x, _, _) =>
- {
- var product = await productService.GetProductById(x.ProductId1);
- if (product != null)
- if (!product.AccessToEntityByStore(workContextAccessor.WorkContext.CurrentCustomer.StaffStoreId))
- return false;
-
- return true;
- }).WithMessage(translationService.GetResource("Admin.Catalog.Products.Permissions"));
+ _productService = productService;
+ }
+ protected override async Task<Product> GetEntity(ProductModel.SimilarProductModel model)
+ {
+ return await _productService.GetProductById(model.ProductId1);
}
+ protected override string GetPermissionsResourceKey => "Admin.Catalog.Products.Permissions";
}
\ No newline at end of file
diff --git a/src/Web/Grand.Web.Admin/Validators/Catalog/TierPriceModelValidator.cs b/src/Web/Grand.Web.Admin/Validators/Catalog/TierPriceModelValidator.cs
index 7efd11096..a7c38ad07 100644
--- a/src/Web/Grand.Web.Admin/Validators/Catalog/TierPriceModelValidator.cs
+++ b/src/Web/Grand.Web.Admin/Validators/Catalog/TierPriceModelValidator.cs
@@ -1,49 +1,44 @@
-using FluentValidation;
-using Grand.Business.Core.Interfaces.Catalog.Products;
+using Grand.Business.Core.Interfaces.Catalog.Products;
using Grand.Business.Core.Interfaces.Common.Localization;
+using Grand.Domain.Catalog;
using Grand.Infrastructure;
using Grand.Infrastructure.Validators;
-using Grand.Web.Admin.Extensions;
using Grand.Web.Admin.Models.Catalog;
namespace Grand.Web.Admin.Validators.Catalog;
-public class TierPriceModelValidator : BaseGrandValidator<ProductModel.TierPriceModel>
+public class TierPriceModelValidator : BaseStoreAccessValidator<ProductModel.TierPriceModel, Product>
{
+ private readonly IProductService _productService;
+
public TierPriceModelValidator(
IEnumerable<IValidatorConsumer<ProductModel.TierPriceModel>> validators,
- ITranslationService translationService, IProductService productService, IWorkContextAccessor workContextAccessor)
- : base(validators)
+ ITranslationService translationService, IProductService productService, IContextAccessor contextAccessor)
+ : base(validators, translationService, contextAccessor)
{
- if (!string.IsNullOrEmpty(workContextAccessor.WorkContext.CurrentCustomer.StaffStoreId))
- RuleFor(x => x).MustAsync(async (x, _, _) =>
- {
- var product = await productService.GetProductById(x.ProductId);
- if (product != null)
- if (!product.AccessToEntityByStore(workContextAccessor.WorkContext.CurrentCustomer.StaffStoreId))
- return false;
-
- return true;
- }).WithMessage(translationService.GetResource("Admin.Catalog.Products.Permissions"));
+ _productService = productService;
+ }
+ protected override async Task<Product> GetEntity(ProductModel.TierPriceModel model)
+ {
+ return await _productService.GetProductById(model.ProductId);
}
+ protected override string GetPermissionsResourceKey => "Admin.Catalog.Products.Permissions";
}
-public class TierPriceDeleteModelValidator : BaseGrandValidator<ProductModel.TierPriceDeleteModel>
+public class TierPriceDeleteModelValidator : BaseStoreAccessValidator<ProductModel.TierPriceDeleteModel, Product>
{
+ private readonly IProductService _productService;
+
public TierPriceDeleteModelValidator(
IEnumerable<IValidatorConsumer<ProductModel.TierPriceDeleteModel>> validators,
- ITranslationService translationService, IProductService productService, IWorkContextAccessor workContextAccessor)
- : base(validators)
+ ITranslationService translationService, IProductService productService, IContextAccessor contextAccessor)
+ : base(validators, translationService, contextAccessor)
{
- if (!string.IsNullOrEmpty(workContextAccessor.WorkContext.CurrentCustomer.StaffStoreId))
- RuleFor(x => x).MustAsync(async (x, _, _) =>
- {
- var product = await productService.GetProductById(x.ProductId);
- if (product != null)
- if (!product.AccessToEntityByStore(workContextAccessor.WorkContext.CurrentCustomer.StaffStoreId))
- return false;
-
- return true;
- }).WithMessage(translationService.GetResource("Admin.Catalog.Products.Permissions"));
+ _productService = productService;
+ }
+ protected override async Task<Product> GetEntity(ProductModel.TierPriceDeleteModel model)
+ {
+ return await _productService.GetProductById(model.ProductId);
}
+ protected override string GetPermissionsResourceKey => "Admin.Catalog.Products.Permissions";
}
\ No newline at end of file
diff --git a/src/Web/Grand.Web.Admin/Validators/Customers/CustomerValidator.cs b/src/Web/Grand.Web.Admin/Validators/Customers/CustomerValidator.cs
index 4534f3633..ca1ae983f 100644
--- a/src/Web/Grand.Web.Admin/Validators/Customers/CustomerValidator.cs
+++ b/src/Web/Grand.Web.Admin/Validators/Customers/CustomerValidator.cs
@@ -17,7 +17,7 @@ public class CustomerValidator : BaseGrandValidator<CustomerModel>
IEnumerable<IValidatorConsumer<CustomerModel>> validators,
ITranslationService translationService,
ICountryService countryService,
- IWorkContextAccessor workContextAccessor,
+ IContextAccessor contextAccessor,
ICustomerService customerService,
IGroupService groupService,
CustomerSettings customerSettings)
@@ -118,11 +118,11 @@ public class CustomerValidator : BaseGrandValidator<CustomerModel>
return "Add the customer to 'Guests' or 'Registered' customer group";
}
- if (await groupService.IsSalesManager(workContextAccessor.WorkContext.CurrentCustomer) &&
+ if (await groupService.IsSalesManager(contextAccessor.WorkContext.CurrentCustomer) &&
(isInGuestsGroup || customerGroups.Count != 1))
return "Sales manager can assign role 'Registered' only";
- if (!await groupService.IsAdmin(workContextAccessor.WorkContext.CurrentCustomer) && isAdminGroup)
+ if (!await groupService.IsAdmin(contextAccessor.WorkContext.CurrentCustomer) && isAdminGroup)
return "Only administrators can assign role 'Administrators'";
switch (isAdminGroup)
@@ -230,8 +230,8 @@ public class CustomerValidator : BaseGrandValidator<CustomerModel>
}
var customer = await customerService.GetCustomerById(x.Id);
- if (await groupService.IsSalesManager(workContextAccessor.WorkContext.CurrentCustomer) &&
- customer?.Id == workContextAccessor.WorkContext.CurrentCustomer.Id)
+ if (await groupService.IsSalesManager(contextAccessor.WorkContext.CurrentCustomer) &&
+ customer?.Id == contextAccessor.WorkContext.CurrentCustomer.Id)
context.AddFailure("You can't edit own data from admin panel");
if (customer != null && customer.Email != x.Email.ToLower())
diff --git a/src/Web/Grand.Web.Common/WorkContextAccessor.cs b/src/Web/Grand.Web.Common/ContextAccessor.cs
similarity index 51%
rename from src/Web/Grand.Web.Common/WorkContextAccessor.cs
rename to src/Web/Grand.Web.Common/ContextAccessor.cs
index 68bad61c4..c1bd8b79d 100644
--- a/src/Web/Grand.Web.Common/WorkContextAccessor.cs
+++ b/src/Web/Grand.Web.Common/ContextAccessor.cs
@@ -2,12 +2,17 @@
namespace Grand.Web.Common;
-public class WorkContextAccessor : IWorkContextAccessor
+public class ContextAccessor : IContextAccessor
{
private static readonly AsyncLocal<IWorkContext> _asyncLocalWorkContext = new();
+ private static readonly AsyncLocal<IStoreContext> _asyncLocalStoreContext = new();
public IWorkContext WorkContext {
get => _asyncLocalWorkContext.Value;
set => _asyncLocalWorkContext.Value = value;
}
+ public IStoreContext StoreContext {
+ get => _asyncLocalStoreContext.Value;
+ set => _asyncLocalStoreContext.Value = value;
+ }
}
diff --git a/src/Web/Grand.Web.Common/Extensions/HttpContextExtensions.cs b/src/Web/Grand.Web.Common/Extensions/HttpContextExtensions.cs
new file mode 100644
index 000000000..f48590309
--- /dev/null
+++ b/src/Web/Grand.Web.Common/Extensions/HttpContextExtensions.cs
@@ -0,0 +1,12 @@
+using Grand.SharedKernel.Extensions;
+using Microsoft.AspNetCore.Http;
+
+namespace Grand.Web.Common.Extensions;
+
+public static class HttpContextExtensions
+{
+ public static string GetStoreCookie(this HttpContext httpContext)
+ {
+ return httpContext?.Request.Cookies[CommonHelper.StoreCookieName];
+ }
+}
\ No newline at end of file
diff --git a/src/Web/Grand.Web.Common/Filters/AffiliateAttribute.cs b/src/Web/Grand.Web.Common/Filters/AffiliateAttribute.cs
index 15eee301d..f5c01d75f 100644
--- a/src/Web/Grand.Web.Common/Filters/AffiliateAttribute.cs
+++ b/src/Web/Grand.Web.Common/Filters/AffiliateAttribute.cs
@@ -30,11 +30,11 @@ public class AffiliateAttribute : TypeFilterAttribute
public AffiliateFilter(IAffiliateService affiliateService,
ICustomerService customerService,
- IWorkContextAccessor workContextAccessor)
+ IContextAccessor contextAccessor)
{
_affiliateService = affiliateService;
_customerService = customerService;
- _workContextAccessor = workContextAccessor;
+ _contextAccessor = contextAccessor;
}
#endregion
@@ -92,13 +92,13 @@ public class AffiliateAttribute : TypeFilterAttribute
if (affiliate is not { Active: true })
return;
- if (affiliate.Id == _workContextAccessor.WorkContext.CurrentCustomer.AffiliateId)
+ if (affiliate.Id == _contextAccessor.WorkContext.CurrentCustomer.AffiliateId)
return;
//update affiliate identifier
- _workContextAccessor.WorkContext.CurrentCustomer.AffiliateId = affiliate.Id;
- await _customerService.UpdateCustomerField(_workContextAccessor.WorkContext.CurrentCustomer.Id, x => x.AffiliateId,
- _workContextAccessor.WorkContext.CurrentCustomer.AffiliateId);
+ _contextAccessor.WorkContext.CurrentCustomer.AffiliateId = affiliate.Id;
+ await _customerService.UpdateCustomerField(_contextAccessor.WorkContext.CurrentCustomer.Id, x => x.AffiliateId,
+ _contextAccessor.WorkContext.CurrentCustomer.AffiliateId);
}
#endregion
@@ -114,7 +114,7 @@ public class AffiliateAttribute : TypeFilterAttribute
private readonly IAffiliateService _affiliateService;
private readonly ICustomerService _customerService;
- private readonly IWorkContextAccessor _workContextAccessor;
+ private readonly IContextAccessor _contextAccessor;
#endregion
}
diff --git a/src/Web/Grand.Web.Common/Filters/AuthorizeAdminAttribute.cs b/src/Web/Grand.Web.Common/Filters/AuthorizeAdminAttribute.cs
index b022986b5..e908a1635 100644
--- a/src/Web/Grand.Web.Common/Filters/AuthorizeAdminAttribute.cs
+++ b/src/Web/Grand.Web.Common/Filters/AuthorizeAdminAttribute.cs
@@ -37,12 +37,12 @@ public class AuthorizeAdminAttribute : TypeFilterAttribute
#region Ctor
public AuthorizeAdminFilter(bool ignoreFilter, IPermissionService permissionService,
- SecuritySettings securitySettings, IWorkContextAccessor workContextAccessor, IGroupService groupService)
+ SecuritySettings securitySettings, IContextAccessor contextAccessor, IGroupService groupService)
{
_ignoreFilter = ignoreFilter;
_permissionService = permissionService;
_securitySettings = securitySettings;
- _workContextAccessor = workContextAccessor;
+ _contextAccessor = contextAccessor;
_groupService = groupService;
}
@@ -78,8 +78,8 @@ public class AuthorizeAdminAttribute : TypeFilterAttribute
filterContext.Result = new RedirectToRouteResult("AdminLogin", new RouteValueDictionary());
//whether current customer is vendor
- if (await _groupService.IsVendor(_workContextAccessor.WorkContext.CurrentCustomer) ||
- _workContextAccessor.WorkContext.CurrentVendor is not null)
+ if (await _groupService.IsVendor(_contextAccessor.WorkContext.CurrentCustomer) ||
+ _contextAccessor.WorkContext.CurrentVendor is not null)
filterContext.Result = new RedirectToRouteResult("AdminLogin", new RouteValueDictionary());
//get allowed IP addresses
@@ -102,7 +102,7 @@ public class AuthorizeAdminAttribute : TypeFilterAttribute
private readonly bool _ignoreFilter;
private readonly IPermissionService _permissionService;
- private readonly IWorkContextAccessor _workContextAccessor;
+ private readonly IContextAccessor _contextAccessor;
private readonly IGroupService _groupService;
private readonly SecuritySettings _securitySettings;
diff --git a/src/Web/Grand.Web.Common/Filters/AuthorizeMenuAttribute.cs b/src/Web/Grand.Web.Common/Filters/AuthorizeMenuAttribute.cs
index 4bc964c8f..8f33194bc 100644
--- a/src/Web/Grand.Web.Common/Filters/AuthorizeMenuAttribute.cs
+++ b/src/Web/Grand.Web.Common/Filters/AuthorizeMenuAttribute.cs
@@ -40,13 +40,13 @@ public class AuthorizeMenuAttribute : TypeFilterAttribute
bool ignoreFilter,
IPermissionService permissionService,
IAdminSiteMapService adminSiteMapService,
- IWorkContextAccessor workContextAccessor,
+ IContextAccessor contextAccessor,
SecurityConfig securityConfig)
{
_ignoreFilter = ignoreFilter;
_permissionService = permissionService;
_adminSiteMapService = adminSiteMapService;
- _workContextAccessor = workContextAccessor;
+ _contextAccessor = contextAccessor;
_securityConfig = securityConfig;
}
@@ -57,7 +57,7 @@ public class AuthorizeMenuAttribute : TypeFilterAttribute
private readonly bool _ignoreFilter;
private readonly IPermissionService _permissionService;
private readonly IAdminSiteMapService _adminSiteMapService;
- private readonly IWorkContextAccessor _workContextAccessor;
+ private readonly IContextAccessor _contextAccessor;
private readonly SecurityConfig _securityConfig;
#endregion
@@ -103,13 +103,13 @@ public class AuthorizeMenuAttribute : TypeFilterAttribute
if (menuSiteMap.AllPermissions)
{
if (!await menuSiteMap.PermissionNames.AllAsync(async x =>
- await _permissionService.Authorize(x, _workContextAccessor.WorkContext.CurrentCustomer)))
+ await _permissionService.Authorize(x, _contextAccessor.WorkContext.CurrentCustomer)))
filterContext.Result = new ForbidResult();
}
else
{
if (!await menuSiteMap.PermissionNames.AnyAsync(async x =>
- await _permissionService.Authorize(x, _workContextAccessor.WorkContext.CurrentCustomer)))
+ await _permissionService.Authorize(x, _contextAccessor.WorkContext.CurrentCustomer)))
filterContext.Result = new ForbidResult();
}
}
diff --git a/src/Web/Grand.Web.Common/Filters/AuthorizeVendorAttribute.cs b/src/Web/Grand.Web.Common/Filters/AuthorizeVendorAttribute.cs
index b79c92a34..e733e0949 100644
--- a/src/Web/Grand.Web.Common/Filters/AuthorizeVendorAttribute.cs
+++ b/src/Web/Grand.Web.Common/Filters/AuthorizeVendorAttribute.cs
@@ -37,11 +37,11 @@ public class AuthorizeVendorAttribute : TypeFilterAttribute
{
#region Ctor
- public AuthorizeVendorFilter(bool ignoreFilter, IWorkContextAccessor workContextAccessor, IGroupService groupService,
+ public AuthorizeVendorFilter(bool ignoreFilter, IContextAccessor contextAccessor, IGroupService groupService,
IPermissionService permissionService)
{
_ignoreFilter = ignoreFilter;
- _workContextAccessor = workContextAccessor;
+ _contextAccessor = contextAccessor;
_groupService = groupService;
_permissionService = permissionService;
}
@@ -76,7 +76,7 @@ public class AuthorizeVendorAttribute : TypeFilterAttribute
context.Result = new RedirectToRouteResult("VendorLogin", new RouteValueDictionary());
//ensure that this user has active vendor record associated
- if (!await _groupService.IsVendor(_workContextAccessor.WorkContext.CurrentCustomer) || _workContextAccessor.WorkContext.CurrentVendor == null)
+ if (!await _groupService.IsVendor(_contextAccessor.WorkContext.CurrentCustomer) || _contextAccessor.WorkContext.CurrentVendor == null)
context.Result = new RedirectToRouteResult("VendorLogin", new RouteValueDictionary());
}
@@ -86,7 +86,7 @@ public class AuthorizeVendorAttribute : TypeFilterAttribute
private readonly bool _ignoreFilter;
private readonly IPermissionService _permissionService;
- private readonly IWorkContextAccessor _workContextAccessor;
+ private readonly IContextAccessor _contextAccessor;
private readonly IGroupService _groupService;
#endregion
diff --git a/src/Web/Grand.Web.Common/Filters/ClosedStoreAttribute.cs b/src/Web/Grand.Web.Common/Filters/ClosedStoreAttribute.cs
index 2240f0d64..29cda80b7 100644
--- a/src/Web/Grand.Web.Common/Filters/ClosedStoreAttribute.cs
+++ b/src/Web/Grand.Web.Common/Filters/ClosedStoreAttribute.cs
@@ -39,13 +39,13 @@ public class ClosedStoreAttribute : TypeFilterAttribute
public CheckAccessClosedStoreFilter(bool ignoreFilter,
IPermissionService permissionService,
- IWorkContextAccessor workContextAccessor,
+ IContextAccessor contextAccessor,
IPageService pageService,
StoreInformationSettings storeInformationSettings)
{
_ignoreFilter = ignoreFilter;
_permissionService = permissionService;
- _workContextAccessor = workContextAccessor;
+ _contextAccessor = contextAccessor;
_pageService = pageService;
_storeInformationSettings = storeInformationSettings;
}
@@ -104,7 +104,7 @@ public class ClosedStoreAttribute : TypeFilterAttribute
{
//get identifiers of pages are accessible when a store is closed
var now = DateTime.UtcNow;
- var allowedPageIds = (await _pageService.GetAllPages(_workContextAccessor.WorkContext.CurrentStore.Id))
+ var allowedPageIds = (await _pageService.GetAllPages(_contextAccessor.StoreContext.CurrentStore.Id))
.Where(t => t.AccessibleWhenStoreClosed &&
(!t.StartDateUtc.HasValue || t.StartDateUtc < now) &&
(!t.EndDateUtc.HasValue || t.EndDateUtc > now))
@@ -136,7 +136,7 @@ public class ClosedStoreAttribute : TypeFilterAttribute
private readonly bool _ignoreFilter;
private readonly IPermissionService _permissionService;
- private readonly IWorkContextAccessor _workContextAccessor;
+ private readonly IContextAccessor _contextAccessor;
private readonly IPageService _pageService;
private readonly StoreInformationSettings _storeInformationSettings;
diff --git a/src/Web/Grand.Web.Common/Filters/CustomerActivityAttribute.cs b/src/Web/Grand.Web.Common/Filters/CustomerActivityAttribute.cs
index 5db6f14a7..68e63a201 100644
--- a/src/Web/Grand.Web.Common/Filters/CustomerActivityAttribute.cs
+++ b/src/Web/Grand.Web.Common/Filters/CustomerActivityAttribute.cs
@@ -32,11 +32,11 @@ public class CustomerActivityAttribute : TypeFilterAttribute
public CustomerActivityFilter(
ICustomerService customerService,
- IWorkContextAccessor workContextAccessor,
+ IContextAccessor contextAccessor,
CustomerSettings customerSettings)
{
_customerService = customerService;
- _workContextAccessor = workContextAccessor;
+ _contextAccessor = contextAccessor;
_customerSettings = customerSettings;
}
@@ -65,8 +65,8 @@ public class CustomerActivityAttribute : TypeFilterAttribute
return;
//update last activity date
- if (_workContextAccessor.WorkContext.CurrentCustomer.LastActivityDateUtc.AddMinutes(3.0) < DateTime.UtcNow)
- await _customerService.UpdateCustomerField(_workContextAccessor.WorkContext.CurrentCustomer, x => x.LastActivityDateUtc,
+ if (_contextAccessor.WorkContext.CurrentCustomer.LastActivityDateUtc.AddMinutes(3.0) < DateTime.UtcNow)
+ await _customerService.UpdateCustomerField(_contextAccessor.WorkContext.CurrentCustomer, x => x.LastActivityDateUtc,
DateTime.UtcNow);
//get current IP address
@@ -74,11 +74,11 @@ public class CustomerActivityAttribute : TypeFilterAttribute
//update customer's IP address
if (!string.IsNullOrEmpty(currentIpAddress) &&
- !currentIpAddress.Equals(_workContextAccessor.WorkContext.CurrentCustomer.LastIpAddress,
+ !currentIpAddress.Equals(_contextAccessor.WorkContext.CurrentCustomer.LastIpAddress,
StringComparison.OrdinalIgnoreCase))
{
- _workContextAccessor.WorkContext.CurrentCustomer.LastIpAddress = currentIpAddress;
- await _customerService.UpdateCustomerField(_workContextAccessor.WorkContext.CurrentCustomer, x => x.LastIpAddress,
+ _contextAccessor.WorkContext.CurrentCustomer.LastIpAddress = currentIpAddress;
+ await _customerService.UpdateCustomerField(_contextAccessor.WorkContext.CurrentCustomer, x => x.LastIpAddress,
currentIpAddress);
}
@@ -88,10 +88,10 @@ public class CustomerActivityAttribute : TypeFilterAttribute
return;
//save new one if don't match
- if (!pageUrl.Equals(_workContextAccessor.WorkContext.CurrentCustomer.LastVisitedPage, StringComparison.OrdinalIgnoreCase))
+ if (!pageUrl.Equals(_contextAccessor.WorkContext.CurrentCustomer.LastVisitedPage, StringComparison.OrdinalIgnoreCase))
{
- _workContextAccessor.WorkContext.CurrentCustomer.LastVisitedPage = pageUrl;
- await _customerService.UpdateCustomerField(_workContextAccessor.WorkContext.CurrentCustomer, x => x.LastVisitedPage, pageUrl);
+ _contextAccessor.WorkContext.CurrentCustomer.LastVisitedPage = pageUrl;
+ await _customerService.UpdateCustomerField(_contextAccessor.WorkContext.CurrentCustomer, x => x.LastVisitedPage, pageUrl);
}
}
@@ -100,7 +100,7 @@ public class CustomerActivityAttribute : TypeFilterAttribute
#region Fields
private readonly ICustomerService _customerService;
- private readonly IWorkContextAccessor _workContextAccessor;
+ private readonly IContextAccessor _contextAccessor;
private readonly CustomerSettings _customerSettings;
#endregion
diff --git a/src/Web/Grand.Web.Common/Filters/DenySystemAccountAttribute.cs b/src/Web/Grand.Web.Common/Filters/DenySystemAccountAttribute.cs
index 4c2ef74a2..25dbc14ec 100644
--- a/src/Web/Grand.Web.Common/Filters/DenySystemAccountAttribute.cs
+++ b/src/Web/Grand.Web.Common/Filters/DenySystemAccountAttribute.cs
@@ -33,10 +33,10 @@ public class DenySystemAccountAttribute : TypeFilterAttribute
{
#region Ctor
- public DenySystemAccountFilter(bool ignoreFilter, IWorkContextAccessor workContextAccessor)
+ public DenySystemAccountFilter(bool ignoreFilter, IContextAccessor contextAccessor)
{
_ignoreFilter = ignoreFilter;
- _workContextAccessor = workContextAccessor;
+ _contextAccessor = contextAccessor;
}
#endregion
@@ -63,7 +63,7 @@ public class DenySystemAccountAttribute : TypeFilterAttribute
if (!DataSettingsManager.DatabaseIsInstalled())
return Task.CompletedTask;
- if (_workContextAccessor.WorkContext.CurrentCustomer.IsSystemAccount())
+ if (_contextAccessor.WorkContext.CurrentCustomer.IsSystemAccount())
context.Result = new RedirectToRouteResult("HomePage", new RouteValueDictionary());
return Task.CompletedTask;
@@ -74,7 +74,7 @@ public class DenySystemAccountAttribute : TypeFilterAttribute
#region Fields
private readonly bool _ignoreFilter;
- private readonly IWorkContextAccessor _workContextAccessor;
+ private readonly IContextAccessor _contextAccessor;
#endregion
}
diff --git a/src/Web/Grand.Web.Common/Filters/LanguageAttribute.cs b/src/Web/Grand.Web.Common/Filters/LanguageAttribute.cs
index 158b06258..a9df12e06 100644
--- a/src/Web/Grand.Web.Common/Filters/LanguageAttribute.cs
+++ b/src/Web/Grand.Web.Common/Filters/LanguageAttribute.cs
@@ -34,10 +34,10 @@ public class LanguageAttribute : TypeFilterAttribute
#region Ctor
public LanguageSeoCodeFilter(
- IWorkContextAccessor workContextAccessor, ILanguageService languageService,
+ IContextAccessor contextAccessor, ILanguageService languageService,
AppConfig config)
{
- _workContextAccessor = workContextAccessor;
+ _contextAccessor = contextAccessor;
_languageService = languageService;
_config = config;
}
@@ -46,7 +46,7 @@ public class LanguageAttribute : TypeFilterAttribute
#region Fields
- private readonly IWorkContextAccessor _workContextAccessor;
+ private readonly IContextAccessor _contextAccessor;
private readonly ILanguageService _languageService;
private readonly AppConfig _config;
@@ -96,7 +96,7 @@ public class LanguageAttribute : TypeFilterAttribute
return;
}
- pageUrl = AddLanguageSeo(pageUrl, _workContextAccessor.WorkContext.WorkingLanguage);
+ pageUrl = AddLanguageSeo(pageUrl, _contextAccessor.WorkContext.WorkingLanguage);
context.Result = new RedirectResult(pageUrl, false);
}
diff --git a/src/Web/Grand.Web.Common/Filters/PasswordExpiredAttribute.cs b/src/Web/Grand.Web.Common/Filters/PasswordExpiredAttribute.cs
index 276cb27f3..7139b848e 100644
--- a/src/Web/Grand.Web.Common/Filters/PasswordExpiredAttribute.cs
+++ b/src/Web/Grand.Web.Common/Filters/PasswordExpiredAttribute.cs
@@ -30,9 +30,9 @@ public class PasswordExpiredAttribute : TypeFilterAttribute
{
#region Ctor
- public PasswordFilter(IWorkContextAccessor workContextAccessor, IMediator mediator)
+ public PasswordFilter(IContextAccessor contextAccessor, IMediator mediator)
{
- _workContextAccessor = workContextAccessor;
+ _contextAccessor = contextAccessor;
_mediator = mediator;
}
@@ -67,7 +67,7 @@ public class PasswordExpiredAttribute : TypeFilterAttribute
{
//check password expiration
var passwordIsExpired = await _mediator.Send(new GetPasswordIsExpiredQuery
- { Customer = _workContextAccessor.WorkContext.CurrentCustomer });
+ { Customer = _contextAccessor.WorkContext.CurrentCustomer });
if (passwordIsExpired)
//redirect to ChangePassword page if expires
context.Result = new RedirectToRouteResult("CustomerChangePassword", new RouteValueDictionary());
@@ -78,7 +78,7 @@ public class PasswordExpiredAttribute : TypeFilterAttribute
#region Fields
- private readonly IWorkContextAccessor _workContextAccessor;
+ private readonly IContextAccessor _contextAccessor;
private readonly IMediator _mediator;
#endregion
diff --git a/src/Web/Grand.Web.Common/Helpers/AdminStoreService.cs b/src/Web/Grand.Web.Common/Helpers/AdminStoreService.cs
new file mode 100644
index 000000000..1e71c7dd5
--- /dev/null
+++ b/src/Web/Grand.Web.Common/Helpers/AdminStoreService.cs
@@ -0,0 +1,35 @@
+using Grand.Business.Core.Interfaces.Common.Stores;
+using Grand.Domain.Customers;
+using Grand.Infrastructure;
+using Grand.Domain.Common;
+
+namespace Grand.Web.Common.Helpers;
+
+public interface IAdminStoreService
+{
+ Task<string> GetActiveStore();
+}
+
+public class AdminStoreService : IAdminStoreService
+{
+ private readonly IStoreService _storeService;
+ private readonly IContextAccessor _contextAccessor;
+
+ public AdminStoreService(IStoreService storeService, IContextAccessor contextAccessor)
+ {
+ _storeService = storeService;
+ _contextAccessor = contextAccessor;
+ }
+
+ public async Task<string> GetActiveStore()
+ {
+ var stores = await _storeService.GetAllStores();
+ if (stores.Count < 2)
+ return stores.FirstOrDefault()!.Id;
+
+ var storeId = _contextAccessor.WorkContext.CurrentCustomer.GetUserFieldFromEntity<string>(SystemCustomerFieldNames.AdminAreaStoreScopeConfiguration);
+ var store = await _storeService.GetStoreById(storeId);
+
+ return store != null ? store.Id : "";
+ }
+}
\ No newline at end of file
diff --git a/src/Web/Grand.Web.Common/Helpers/QuantityHelper.cs b/src/Web/Grand.Web.Common/Helpers/QuantityHelper.cs
new file mode 100644
index 000000000..ea912231e
--- /dev/null
+++ b/src/Web/Grand.Web.Common/Helpers/QuantityHelper.cs
@@ -0,0 +1,6 @@
+namespace Grand.Web.Common.Helpers;
+
+public static class QuantityHelper
+{
+ public static int MaxQuantity(this int quantity) => Math.Min(quantity, 100);
+}
\ No newline at end of file
diff --git a/src/Web/Grand.Web.Common/Infrastructure/BackgroundServiceTask.cs b/src/Web/Grand.Web.Common/Infrastructure/BackgroundServiceTask.cs
index 13e07696c..49044b08c 100644
--- a/src/Web/Grand.Web.Common/Infrastructure/BackgroundServiceTask.cs
+++ b/src/Web/Grand.Web.Common/Infrastructure/BackgroundServiceTask.cs
@@ -106,8 +106,12 @@ public class BackgroundServiceTask : BackgroundService
private async Task WorkContext(IServiceProvider serviceProvider, ScheduleTask scheduleTask)
{
- var workContextAccessor = serviceProvider.GetRequiredService<IWorkContextAccessor>();
+ var contextAccessor = serviceProvider.GetRequiredService<IContextAccessor>();
+
+ var storeContext = serviceProvider.GetRequiredService<IStoreContextSetter>();
+ contextAccessor.StoreContext = await storeContext.InitializeStoreContext(scheduleTask.StoreId);
+
var workContext = serviceProvider.GetRequiredService<IWorkContextSetter>();
- workContextAccessor.WorkContext = await workContext.InitializeWorkContext(scheduleTask.StoreId);
+ contextAccessor.WorkContext = await workContext.InitializeWorkContext(scheduleTask.StoreId);
}
}
\ No newline at end of file
diff --git a/src/Web/Grand.Web.Common/Infrastructure/ServiceCollectionExtensions.cs b/src/Web/Grand.Web.Common/Infrastructure/ServiceCollectionExtensions.cs
index c9204151e..701ada3e7 100644
--- a/src/Web/Grand.Web.Common/Infrastructure/ServiceCollectionExtensions.cs
+++ b/src/Web/Grand.Web.Common/Infrastructure/ServiceCollectionExtensions.cs
@@ -9,6 +9,7 @@ using Grand.Infrastructure;
using Grand.Infrastructure.Configuration;
using Grand.Infrastructure.Plugins;
using Grand.Infrastructure.TypeSearch;
+using Grand.SharedKernel.Extensions;
using Grand.Web.Common.View;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.DataProtection;
@@ -120,7 +121,7 @@ public static class ServiceCollectionExtensions
else
{
var securityConfig = new SecurityConfig();
- configuration.GetSection("Security").Bind(securityConfig);
+ configuration.GetSection("Security").Bind(securityConfig);
var keyPersistenceLocation = string.IsNullOrEmpty(securityConfig.KeyPersistenceLocation)
? "/App_Data/DataProtectionKeys" : securityConfig.KeyPersistenceLocation;
var dataProtectionKeysFolder = new DirectoryInfo(keyPersistenceLocation);
@@ -253,9 +254,9 @@ public static class ServiceCollectionExtensions
var type = item.GetType();
var storeId = "";
var settingService = x.GetRequiredService<ISettingService>();
- var store = x.GetRequiredService<IWorkContextAccessor>().WorkContext?.CurrentStore;
- if (store != null)
- storeId = store.Id;
+ var contextAccessor = x.GetRequiredService<IContextAccessor>();
+ if (contextAccessor.StoreContext != null)
+ storeId = contextAccessor.StoreContext.CurrentStore.Id;
return settingService.LoadSetting(type, storeId);
});
diff --git a/src/Web/Grand.Web.Common/Localization/IEnumTranslationService.cs b/src/Web/Grand.Web.Common/Localization/IEnumTranslationService.cs
index 630e8064b..f000d653a 100644
--- a/src/Web/Grand.Web.Common/Localization/IEnumTranslationService.cs
+++ b/src/Web/Grand.Web.Common/Localization/IEnumTranslationService.cs
@@ -12,7 +12,7 @@ public interface IEnumTranslationService
string GetTranslationEnum<T>(T enumValue) where T : struct;
}
-public class EnumTranslationService(ITranslationService translationService, IWorkContextAccessor workContextAccessor) : IEnumTranslationService
+public class EnumTranslationService(ITranslationService translationService, IContextAccessor contextAccessor) : IEnumTranslationService
{
public SelectList ToSelectList<TEnum>(TEnum enumObj, bool markCurrentAsSelected = true, int[] valuesToExclude = null)
where TEnum : struct
@@ -41,7 +41,7 @@ public class EnumTranslationService(ITranslationService translationService, IWor
//Translation value
var resourceName = $"Enums.{typeof(T)}.{enumValue.ToString()}";
- var result = translationService.GetResource(resourceName, workContextAccessor.WorkContext.WorkingLanguage.Id, "", true);
+ var result = translationService.GetResource(resourceName, contextAccessor.WorkContext.WorkingLanguage.Id, "", true);
//set default value if required
if (string.IsNullOrEmpty(result))
diff --git a/src/Web/Grand.Web.Common/Middleware/ContextLoggingMiddleware.cs b/src/Web/Grand.Web.Common/Middleware/ContextLoggingMiddleware.cs
index ba326730d..e9b0f9ece 100644
--- a/src/Web/Grand.Web.Common/Middleware/ContextLoggingMiddleware.cs
+++ b/src/Web/Grand.Web.Common/Middleware/ContextLoggingMiddleware.cs
@@ -17,15 +17,15 @@ public class ContextLoggingMiddleware
_next = next;
}
- public async Task InvokeAsync(HttpContext context, IWorkContextAccessor workContextAccessor)
+ public async Task InvokeAsync(HttpContext context, IContextAccessor contextAccessor)
{
- var workContext = workContextAccessor.WorkContext;
-
+ var workContext = contextAccessor.WorkContext;
+ var storeContext = contextAccessor.StoreContext;
Activity activity = Activity.Current;
if (activity != null)
{
activity.AddTag(CustomerPropertyName, workContext?.CurrentCustomer?.Email);
- activity.AddTag(StorePropertyName, workContext?.CurrentStore?.Name);
+ activity.AddTag(StorePropertyName, storeContext?.CurrentStore?.Name);
activity.AddTag(CurrencyPropertyName, workContext?.WorkingCurrency?.Name);
activity.AddTag(LanguagePropertyName, workContext?.WorkingLanguage?.Name);
}
diff --git a/src/Web/Grand.Web.Common/Middleware/WorkContextMiddleware.cs b/src/Web/Grand.Web.Common/Middleware/ContextMiddleware.cs
similarity index 59%
rename from src/Web/Grand.Web.Common/Middleware/WorkContextMiddleware.cs
rename to src/Web/Grand.Web.Common/Middleware/ContextMiddleware.cs
index 06750a594..ca9f54fee 100644
--- a/src/Web/Grand.Web.Common/Middleware/WorkContextMiddleware.cs
+++ b/src/Web/Grand.Web.Common/Middleware/ContextMiddleware.cs
@@ -1,10 +1,18 @@
-using Grand.Infrastructure;
+using Grand.Business.Core.Interfaces.Common.Stores;
+using Grand.Infrastructure;
+using Grand.Web.Common.Extensions;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Routing;
+using Microsoft.Extensions.DependencyInjection;
+using Grand.Business.Core.Extensions;
+using Grand.SharedKernel.Extensions;
+using Grand.Domain.Tasks;
+using Scryber;
+using DotLiquid.Util;
namespace Grand.Web.Common.Middleware;
-public class WorkContextMiddleware
+public class ContextMiddleware
{
#region Fields
@@ -20,7 +28,7 @@ public class WorkContextMiddleware
/// Ctor
/// </summary>
/// <param name="next">Next</param>
- public WorkContextMiddleware(RequestDelegate next)
+ public ContextMiddleware(RequestDelegate next)
{
_next = next;
}
@@ -35,7 +43,7 @@ public class WorkContextMiddleware
/// <param name="context">HTTP context</param>
/// <param name="workContext">workContext</param>
/// <returns>Task</returns>
- public async Task InvokeAsync(HttpContext context, IWorkContextSetter workContextSetter, IWorkContextAccessor workContextAccessor)
+ public async Task InvokeAsync(HttpContext context, IContextAccessor contextAccessor)
{
if (context?.Request == null) return;
@@ -50,9 +58,11 @@ public class WorkContextMiddleware
}
}
- //set current context
- var workContext = await workContextSetter.InitializeWorkContext();
- workContextAccessor.WorkContext = workContext;
+ var storeContext = context.RequestServices.GetRequiredService<IStoreContextSetter>();
+ contextAccessor.StoreContext = await storeContext.InitializeStoreContext();
+
+ var workContextSetter = context.RequestServices.GetRequiredService<IWorkContextSetter>();
+ contextAccessor.WorkContext = await workContextSetter.InitializeWorkContext(contextAccessor.StoreContext.CurrentStore.Id);
//call the next middleware in the request pipeline
await _next(context);
diff --git a/src/Web/Grand.Web.Common/Middleware/CultureSettingMiddleware.cs b/src/Web/Grand.Web.Common/Middleware/CultureSettingMiddleware.cs
index 1b82e3231..c999e0a47 100644
--- a/src/Web/Grand.Web.Common/Middleware/CultureSettingMiddleware.cs
+++ b/src/Web/Grand.Web.Common/Middleware/CultureSettingMiddleware.cs
@@ -13,11 +13,11 @@ public class CultureSettingMiddleware
_next = next;
}
- public async Task InvokeAsync(HttpContext context, IWorkContextAccessor workContextAccessor)
+ public async Task InvokeAsync(HttpContext context, IContextAccessor contextAccessor)
{
- if (workContextAccessor.WorkContext?.WorkingLanguage != null)
+ if (contextAccessor.WorkContext?.WorkingLanguage != null)
{
- var culture = new CultureInfo(workContextAccessor.WorkContext.WorkingLanguage.LanguageCulture);
+ var culture = new CultureInfo(contextAccessor.WorkContext.WorkingLanguage.LanguageCulture);
CultureInfo.CurrentCulture = culture;
CultureInfo.CurrentUICulture = culture;
diff --git a/src/Web/Grand.Web.Common/Security/Authorization/CustomerGroupAuthorizeAttribute.cs b/src/Web/Grand.Web.Common/Security/Authorization/CustomerGroupAuthorizeAttribute.cs
index 8cb68eb40..332f3b319 100644
--- a/src/Web/Grand.Web.Common/Security/Authorization/CustomerGroupAuthorizeAttribute.cs
+++ b/src/Web/Grand.Web.Common/Security/Authorization/CustomerGroupAuthorizeAttribute.cs
@@ -24,7 +24,7 @@ public class CustomerGroupAuthorizeAttribute : Attribute, IAsyncAuthorizationFil
return;
var groupService = context.HttpContext.RequestServices.GetRequiredService<IGroupService>();
- var workContext = context.HttpContext.RequestServices.GetRequiredService<IWorkContextAccessor>().WorkContext;
+ var workContext = context.HttpContext.RequestServices.GetRequiredService<IContextAccessor>().WorkContext;
if (await groupService.IsInCustomerGroup(workContext.CurrentCustomer, GroupName))
return;
diff --git a/src/Web/Grand.Web.Common/Startup/AuthenticationStartup.cs b/src/Web/Grand.Web.Common/Startup/AuthenticationStartup.cs
index c0626ea0a..a3a27a108 100644
--- a/src/Web/Grand.Web.Common/Startup/AuthenticationStartup.cs
+++ b/src/Web/Grand.Web.Common/Startup/AuthenticationStartup.cs
@@ -44,7 +44,7 @@ public class AuthenticationStartup : IStartupApplication
application.UseGrandAuthentication();
//set work context
- application.UseMiddleware<WorkContextMiddleware>();
+ application.UseMiddleware<ContextMiddleware>();
//set culture
application.UseMiddleware<CultureSettingMiddleware>();
}
diff --git a/src/Web/Grand.Web.Common/Startup/StartupApplication.cs b/src/Web/Grand.Web.Common/Startup/StartupApplication.cs
index 141cfe93e..1b31ddc8c 100644
--- a/src/Web/Grand.Web.Common/Startup/StartupApplication.cs
+++ b/src/Web/Grand.Web.Common/Startup/StartupApplication.cs
@@ -7,6 +7,7 @@ using Grand.Infrastructure.Caching.Message;
using Grand.Infrastructure.Caching.Redis;
using Grand.Infrastructure.Configuration;
using Grand.Infrastructure.Validators;
+using Grand.Web.Common.Helpers;
using Grand.Web.Common.Localization;
using Grand.Web.Common.Menu;
using Grand.Web.Common.Middleware;
@@ -73,9 +74,10 @@ public class StartupApplication : IStartupApplication
private void RegisterContextService(IServiceCollection serviceCollection)
{
//work context
- serviceCollection.AddSingleton<IWorkContextAccessor, WorkContextAccessor>();
+ serviceCollection.AddSingleton<IContextAccessor, ContextAccessor>();
serviceCollection.AddScoped<IWorkContextSetter, WorkContextSetter>();
-
+ serviceCollection.AddScoped<IStoreContextSetter, StoreContextSetter>();
+ serviceCollection.AddScoped<IAdminStoreService, AdminStoreService>();
//View factory
serviceCollection.AddScoped<IViewFactory, ViewFactory>();
diff --git a/src/Web/Grand.Web.Common/StoreContextSetter.cs b/src/Web/Grand.Web.Common/StoreContextSetter.cs
new file mode 100644
index 000000000..337ed8f26
--- /dev/null
+++ b/src/Web/Grand.Web.Common/StoreContextSetter.cs
@@ -0,0 +1,92 @@
+using Grand.Business.Core.Interfaces.Common.Stores;
+using Grand.Domain.Stores;
+using Grand.Infrastructure;
+using Grand.Web.Common.Extensions;
+using Microsoft.AspNetCore.Http;
+
+namespace Grand.Web.Common;
+
+public class StoreContextSetter : IStoreContextSetter
+{
+ private readonly IStoreService _storeService;
+ private readonly IHttpContextAccessor _httpContextAccessor;
+
+ public StoreContextSetter(IStoreService storeService, IHttpContextAccessor httpContextAccessor)
+ {
+ _storeService = storeService;
+ _httpContextAccessor = httpContextAccessor;
+ }
+
+ public async Task<IStoreContext> InitializeStoreContext(string storeId = null)
+ {
+ var store = await CurrentStore(storeId);
+ var storeContext = new CurrentStoreContext {
+ CurrentStore = store,
+ CurrentHost = CurrentHost(store)
+ };
+
+ return storeContext;
+ }
+ protected async Task<Store> CurrentStore(string id = null)
+ {
+ var httpContext = _httpContextAccessor.HttpContext;
+
+ // Attempt to load store by provided id
+ if (!string.IsNullOrEmpty(id))
+ {
+ var storeById = await _storeService.GetStoreById(id);
+ if (storeById != null)
+ return storeById;
+ }
+
+ // Attempt to load store by cookie value
+ var storeCookie = httpContext?.GetStoreCookie();
+ if (!string.IsNullOrEmpty(storeCookie))
+ {
+ var storeByCookie = await _storeService.GetStoreById(storeCookie);
+ if (storeByCookie != null)
+ return storeByCookie;
+ }
+
+ // Attempt to load store by host from request
+ var host = httpContext?.Request.Host.Host;
+ if (!string.IsNullOrEmpty(host))
+ {
+ var storeByHost = await _storeService.GetStoreByHost(host);
+ if (storeByHost != null)
+ return storeByHost;
+ }
+
+ // Fallback: return the first available store
+ return (await _storeService.GetAllStores()).FirstOrDefault();
+ }
+
+ /// <summary>
+ /// Gets the current domain host
+ /// </summary>
+ protected DomainHost CurrentHost(Store store)
+ {
+ //try to determine the current HOST header
+ var host = _httpContextAccessor.HttpContext?.Request.GetTypedHeaders().Host.ToString();
+ if (store != null)
+ return store.HostValue(host) ?? new DomainHost {
+ Id = int.MinValue.ToString(),
+ Url = store.SslEnabled ? store.SecureUrl : store.Url,
+ HostName = "temporary-store"
+ };
+
+ return new DomainHost {
+ Id = int.MinValue.ToString(),
+ Url = host,
+ HostName = "temporary"
+ };
+ }
+ private sealed class CurrentStoreContext : IStoreContext
+ {
+ public Store CurrentStore { get; set; }
+
+ public DomainHost CurrentHost { get; set; }
+ }
+}
+
+
diff --git a/src/Web/Grand.Web.Common/TagHelpers/Admin/AdminLabelTagHelper.cs b/src/Web/Grand.Web.Common/TagHelpers/Admin/AdminLabelTagHelper.cs
index d858d12c6..5d660758e 100644
--- a/src/Web/Grand.Web.Common/TagHelpers/Admin/AdminLabelTagHelper.cs
+++ b/src/Web/Grand.Web.Common/TagHelpers/Admin/AdminLabelTagHelper.cs
@@ -14,12 +14,12 @@ public class LabelRequiredTagHelper : LabelTagHelper
private const string RequiredAttributeName = "asp-required";
private readonly ITranslationService _translationService;
- private readonly IWorkContextAccessor _workContextAccessor;
+ private readonly IContextAccessor _contextAccessor;
- public LabelRequiredTagHelper(IHtmlGenerator generator, IWorkContextAccessor workContextAccessor,
+ public LabelRequiredTagHelper(IHtmlGenerator generator, IContextAccessor contextAccessor,
ITranslationService translationService) : base(generator)
{
- _workContextAccessor = workContextAccessor;
+ _contextAccessor = contextAccessor;
_translationService = translationService;
}
@@ -42,7 +42,7 @@ public class LabelRequiredTagHelper : LabelTagHelper
var resourceDisplayName = For.Metadata.GetDisplayName();
- var langId = _workContextAccessor.WorkContext.WorkingLanguage.Id;
+ var langId = _contextAccessor.WorkContext.WorkingLanguage.Id;
var resource = _translationService.GetResource(
resourceDisplayName.ToLowerInvariant(), langId, returnEmptyIfNotFound: true);
diff --git a/src/Web/Grand.Web.Common/TagHelpers/HtmlTagHelper.cs b/src/Web/Grand.Web.Common/TagHelpers/HtmlTagHelper.cs
index 86a72ff2f..0c7b3dcc3 100644
--- a/src/Web/Grand.Web.Common/TagHelpers/HtmlTagHelper.cs
+++ b/src/Web/Grand.Web.Common/TagHelpers/HtmlTagHelper.cs
@@ -10,11 +10,11 @@ public class HtmlTagHelper : TagHelper
private const string ForAttributeName = "use-lang";
private readonly IPageHeadBuilder _pageHeadBuilder;
- private readonly IWorkContextAccessor _workContextAccessor;
+ private readonly IContextAccessor _contextAccessor;
- public HtmlTagHelper(IWorkContextAccessor workContextAccessor, IPageHeadBuilder pageHeadBuilder)
+ public HtmlTagHelper(IContextAccessor contextAccessor, IPageHeadBuilder pageHeadBuilder)
{
- _workContextAccessor = workContextAccessor;
+ _contextAccessor = contextAccessor;
_pageHeadBuilder = pageHeadBuilder;
}
@@ -24,8 +24,8 @@ public class HtmlTagHelper : TagHelper
{
if (UseLanguage)
{
- output.Attributes.Add("lang", _workContextAccessor.WorkContext.WorkingLanguage.UniqueSeoCode);
- if (_workContextAccessor.WorkContext.WorkingLanguage.Rtl)
+ output.Attributes.Add("lang", _contextAccessor.WorkContext.WorkingLanguage.UniqueSeoCode);
+ if (_contextAccessor.WorkContext.WorkingLanguage.Rtl)
output.Attributes.Add("dir", "rtl");
}
diff --git a/src/Web/Grand.Web.Common/WorkContextSetter.cs b/src/Web/Grand.Web.Common/WorkContextSetter.cs
index aeafa29aa..8c57fefea 100644
--- a/src/Web/Grand.Web.Common/WorkContextSetter.cs
+++ b/src/Web/Grand.Web.Common/WorkContextSetter.cs
@@ -13,7 +13,6 @@ using Grand.Domain.Tax;
using Grand.Domain.Vendors;
using Grand.Infrastructure;
using Grand.Infrastructure.Configuration;
-using Grand.SharedKernel.Extensions;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Localization;
@@ -27,6 +26,24 @@ namespace Grand.Web.Common;
/// </summary>
public class WorkContextSetter : IWorkContextSetter
{
+ #region Fields
+
+ private readonly IHttpContextAccessor _httpContextAccessor;
+ private readonly IGrandAuthenticationService _authenticationService;
+ private readonly ICurrencyService _currencyService;
+ private readonly ICustomerService _customerService;
+ private readonly IGroupService _groupService;
+ private readonly ILanguageService _languageService;
+ private readonly IStoreService _storeService;
+ private readonly IAclService _aclService;
+ private readonly IVendorService _vendorService;
+
+ private readonly TaxSettings _taxSettings;
+ private readonly AppConfig _config;
+
+ private Customer _originalCustomerIfImpersonated;
+
+ #endregion
#region Ctor
public WorkContextSetter(
@@ -57,25 +74,6 @@ public class WorkContextSetter : IWorkContextSetter
#endregion
- #region Fields
-
- private readonly IHttpContextAccessor _httpContextAccessor;
- private readonly IGrandAuthenticationService _authenticationService;
- private readonly ICurrencyService _currencyService;
- private readonly ICustomerService _customerService;
- private readonly IGroupService _groupService;
- private readonly ILanguageService _languageService;
- private readonly IStoreService _storeService;
- private readonly IAclService _aclService;
- private readonly IVendorService _vendorService;
-
- private readonly TaxSettings _taxSettings;
- private readonly AppConfig _config;
-
- private Customer _originalCustomerIfImpersonated;
-
- #endregion
-
#region Utilities
/// <summary>
@@ -149,19 +147,16 @@ public class WorkContextSetter : IWorkContextSetter
public virtual async Task<IWorkContext> InitializeWorkContext(string storeId = null)
{
var currentStore = await CurrentStore(storeId);
- var workContext = new CurrentWorkContext {
- CurrentStore = currentStore,
- CurrentHost = CurrentHost(currentStore),
+ var workContext = new CurrentWorkContext {
CurrentCustomer = await CurrentCustomer(currentStore)
};
-
if (workContext.CurrentCustomer != null)
{
workContext.CurrentVendor = await CurrentVendor(workContext.CurrentCustomer);
workContext.OriginalCustomerIfImpersonated = _originalCustomerIfImpersonated;
- workContext.WorkingLanguage = await WorkingLanguage(workContext.CurrentCustomer, workContext.CurrentStore);
- workContext.WorkingCurrency = await WorkingCurrency(workContext.CurrentCustomer, workContext.WorkingLanguage, workContext.CurrentStore);
- workContext.TaxDisplayType = await TaxDisplayType(workContext.CurrentCustomer, workContext.CurrentStore);
+ workContext.WorkingLanguage = await WorkingLanguage(workContext.CurrentCustomer, currentStore);
+ workContext.WorkingCurrency = await WorkingCurrency(workContext.CurrentCustomer, workContext.WorkingLanguage, currentStore);
+ workContext.TaxDisplayType = await TaxDisplayType(workContext.CurrentCustomer, currentStore);
}
return workContext;
}
@@ -189,7 +184,7 @@ public class WorkContextSetter : IWorkContextSetter
customer = await GetApiUserCustomer();
if (customer != null) return customer;
-
+
//create guest if not exists
customer = await CreateCustomerGuest(store);
@@ -416,67 +411,16 @@ public class WorkContextSetter : IWorkContextSetter
return await Task.FromResult(taxDisplayType);
}
- private string GetStoreCookie()
- {
- return _httpContextAccessor.HttpContext?.Request.Cookies[CommonHelper.StoreCookieName];
- }
protected async Task<Store> CurrentStore(string id = null)
{
if (!string.IsNullOrEmpty(id))
return await _storeService.GetStoreById(id);
- var host = _httpContextAccessor.HttpContext?.Request.Host.Host;
-
- var allStores = await _storeService.GetAllStores();
- var stores = allStores.Where(s => s.ContainsHostValue(host)).ToList();
- if (!stores.Any())
- return allStores.FirstOrDefault();
- else
- switch (stores.Count)
- {
- case 1:
- return stores.FirstOrDefault();
- case > 1:
- {
- var cookie = GetStoreCookie();
- if (!string.IsNullOrEmpty(cookie))
- {
- var storeCookie = stores.FirstOrDefault(x => x.Id == cookie);
- return storeCookie ?? stores.FirstOrDefault();
- }
- else
- {
- return stores.FirstOrDefault();
- }
- }
- }
-
- throw new Exception("No store could be loaded");
+ return (await _storeService.GetAllStores()).FirstOrDefault();
}
- /// <summary>
- /// Gets the current domain host
- /// </summary>
- protected DomainHost CurrentHost(Store store)
- {
- //try to determine the current HOST header
- var host = _httpContextAccessor.HttpContext?.Request.GetTypedHeaders().Host.ToString();
- if (store != null)
- return store.HostValue(host) ?? new DomainHost {
- Id = int.MinValue.ToString(),
- Url = store.SslEnabled ? store.SecureUrl : store.Url,
- HostName = "temporary-store"
- };
-
- return new DomainHost {
- Id = int.MinValue.ToString(),
- Url = host,
- HostName = "temporary"
- };
- }
-
- private class CurrentWorkContext : IWorkContext
+ private sealed class CurrentWorkContext : IWorkContext
{
public Customer CurrentCustomer { get; set; }
@@ -489,9 +433,6 @@ public class WorkContextSetter : IWorkContextSetter
public Currency WorkingCurrency { get; set; }
public TaxDisplayType TaxDisplayType { get; set; }
-
- public Store CurrentStore { get; set; }
- public DomainHost CurrentHost { get; set; }
}
#endregion
diff --git a/src/Web/Grand.Web.Vendor/Areas/Vendor/Views/Home/Index.cshtml b/src/Web/Grand.Web.Vendor/Areas/Vendor/Views/Home/Index.cshtml
index e4925855a..8a4792bfe 100644
--- a/src/Web/Grand.Web.Vendor/Areas/Vendor/Views/Home/Index.cshtml
+++ b/src/Web/Grand.Web.Vendor/Areas/Vendor/Views/Home/Index.cshtml
@@ -1,4 +1,4 @@
-@inject IWorkContextAccessor workContextAccessor;
+@inject IContextAccessor contextAccessor;
@{
//page title
ViewBag.Title = Loc["Vendor.Dashboard"];
@@ -9,7 +9,7 @@
<div class="col-md-12">
<div class="x_panel">
<div class="x_title">
- <h2>@Loc["Vendor.Dashboard.Summary"] - @workContextAccessor.WorkContext.CurrentVendor.Name</h2>
+ <h2>@Loc["Vendor.Dashboard.Summary"] - @contextAccessor.WorkContext.CurrentVendor.Name</h2>
<div class="filter">
<div class="page-bar" style="height:43px;">
<div class="page-toolbar">
diff --git a/src/Web/Grand.Web.Vendor/Areas/Vendor/Views/PdfTemplates/ShipmentPdfTemplate.cshtml b/src/Web/Grand.Web.Vendor/Areas/Vendor/Views/PdfTemplates/ShipmentPdfTemplate.cshtml
index 30ff7550d..7e1f5bc81 100644
--- a/src/Web/Grand.Web.Vendor/Areas/Vendor/Views/PdfTemplates/ShipmentPdfTemplate.cshtml
+++ b/src/Web/Grand.Web.Vendor/Areas/Vendor/Views/PdfTemplates/ShipmentPdfTemplate.cshtml
@@ -6,12 +6,12 @@
@inject IOrderService _orderService
@inject IProductService _productService
@inject ICountryService _countryService
-@inject IWorkContextAccessor _workContextAccessor
+@inject IContextAccessor _contextAccessor
@inject ITranslationService _translationService
@{
- var companyName = _workContextAccessor.WorkContext.CurrentStore.CompanyName;
- var limitbyVendor = _workContextAccessor.WorkContext.CurrentVendor != null;
+ var companyName = _contextAccessor.StoreContext.CurrentStore.CompanyName;
+ var limitbyVendor = _contextAccessor.WorkContext.CurrentVendor != null;
}
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
@@ -118,7 +118,7 @@
@foreach (var item in shipment.ShipmentItems)
{
var orderItem = order.OrderItems.FirstOrDefault(x => x.Id == item.OrderItemId);
- if (orderItem != null && (orderItem.VendorId == _workContextAccessor.WorkContext.CurrentVendor?.Id || !limitbyVendor))
+ if (orderItem != null && (orderItem.VendorId == _contextAccessor.WorkContext.CurrentVendor?.Id || !limitbyVendor))
{
<tr>
<td colspan="2">
diff --git a/src/Web/Grand.Web.Vendor/Areas/Vendor/Views/Shared/Partials/HeadVendor.cshtml b/src/Web/Grand.Web.Vendor/Areas/Vendor/Views/Shared/Partials/HeadVendor.cshtml
index 8fe69c0a7..4ebd6bd3c 100644
--- a/src/Web/Grand.Web.Vendor/Areas/Vendor/Views/Shared/Partials/HeadVendor.cshtml
+++ b/src/Web/Grand.Web.Vendor/Areas/Vendor/Views/Shared/Partials/HeadVendor.cshtml
@@ -1,12 +1,12 @@
@using Grand.Domain.Localization
@using Constants = Grand.SharedUIResources.Constants
@inject LanguageSettings languageSettings
-@inject IWorkContextAccessor workContextAccessor
+@inject IContextAccessor contextAccessor
<script>
const wwwrootpath = '@(Constants.WwwRoot)';
</script>
@{
- var supportRtl = workContextAccessor.WorkContext.WorkingLanguage.Rtl &&
+ var supportRtl = contextAccessor.WorkContext.WorkingLanguage.Rtl &&
!languageSettings.IgnoreRtlPropertyForAdminArea;
var kendoVersion = "2021.3.914";
diff --git a/src/Web/Grand.Web.Vendor/Areas/Vendor/Views/Shared/_VendorLayout.cshtml b/src/Web/Grand.Web.Vendor/Areas/Vendor/Views/Shared/_VendorLayout.cshtml
index b22fd9e83..e73dc5693 100644
--- a/src/Web/Grand.Web.Vendor/Areas/Vendor/Views/Shared/_VendorLayout.cshtml
+++ b/src/Web/Grand.Web.Vendor/Areas/Vendor/Views/Shared/_VendorLayout.cshtml
@@ -4,13 +4,13 @@
@using Grand.Web.Vendor.Components
@using Microsoft.AspNetCore.Mvc.TagHelpers
@using Constants = Grand.SharedUIResources.Constants
-@inject IWorkContextAccessor workContextAccessor
+@inject IContextAccessor contextAccessor
@inject LanguageSettings languageSettings
@inject VendorSettings vendorSettings
@{
- var currentCustomer = workContextAccessor.WorkContext.CurrentCustomer;
+ var currentCustomer = contextAccessor.WorkContext.CurrentCustomer;
var currentVersion = GrandVersion.FullVersion;
- var supportRtl = workContextAccessor.WorkContext.WorkingLanguage.Rtl &&
+ var supportRtl = contextAccessor.WorkContext.WorkingLanguage.Rtl &&
!languageSettings.IgnoreRtlPropertyForAdminArea;
//page title
diff --git a/src/Web/Grand.Web.Vendor/Components/VendorWidget.cs b/src/Web/Grand.Web.Vendor/Components/VendorWidget.cs
index ef2e9fb71..50fd0ebb6 100644
--- a/src/Web/Grand.Web.Vendor/Components/VendorWidget.cs
+++ b/src/Web/Grand.Web.Vendor/Components/VendorWidget.cs
@@ -10,10 +10,10 @@ public class VendorWidgetViewComponent : BaseVendorViewComponent
{
#region Constructors
- public VendorWidgetViewComponent(IWidgetService widgetService, IWorkContextAccessor workContextAccessor)
+ public VendorWidgetViewComponent(IWidgetService widgetService, IContextAccessor contextAccessor)
{
_widgetService = widgetService;
- _workContextAccessor = workContextAccessor;
+ _contextAccessor = contextAccessor;
}
#endregion
@@ -24,8 +24,8 @@ public class VendorWidgetViewComponent : BaseVendorViewComponent
{
var model = new List<VendorWidgetModel>();
- var widgets = await _widgetService.LoadActiveWidgetsByWidgetZone(widgetZone, _workContextAccessor.WorkContext.CurrentStore.Id,
- _workContextAccessor.WorkContext.CurrentCustomer);
+ var widgets = await _widgetService.LoadActiveWidgetsByWidgetZone(widgetZone, _contextAccessor.StoreContext.CurrentStore.Id,
+ _contextAccessor.WorkContext.CurrentCustomer);
foreach (var item in widgets)
{
var viewComponentName = await item.GetPublicViewComponentName(widgetZone);
@@ -51,7 +51,7 @@ public class VendorWidgetViewComponent : BaseVendorViewComponent
#region Fields
private readonly IWidgetService _widgetService;
- private readonly IWorkContextAccessor _workContextAccessor;
+ private readonly IContextAccessor _contextAccessor;
#endregion
}
\ No newline at end of file
diff --git a/src/Web/Grand.Web.Vendor/Controllers/HomeController.cs b/src/Web/Grand.Web.Vendor/Controllers/HomeController.cs
index b27f74ea5..57f1e9ec5 100644
--- a/src/Web/Grand.Web.Vendor/Controllers/HomeController.cs
+++ b/src/Web/Grand.Web.Vendor/Controllers/HomeController.cs
@@ -13,11 +13,11 @@ public class HomeController : BaseVendorController
#region Ctor
public HomeController(
- IWorkContextAccessor workContextAccessor,
+ IContextAccessor contextAccessor,
ILogger<HomeController> logger,
IGrandAuthenticationService authenticationService)
{
- _workContextAccessor = workContextAccessor;
+ _contextAccessor = contextAccessor;
_logger = logger;
_authenticationService = authenticationService;
}
@@ -26,7 +26,7 @@ public class HomeController : BaseVendorController
#region Fields
- private readonly IWorkContextAccessor _workContextAccessor;
+ private readonly IContextAccessor _contextAccessor;
private readonly ILogger<HomeController> _logger;
private readonly IGrandAuthenticationService _authenticationService;
@@ -46,7 +46,7 @@ public class HomeController : BaseVendorController
public IActionResult AccessDenied()
{
- _logger.LogInformation("Access denied to user #{CurrentCustomerEmail}", _workContextAccessor.WorkContext.CurrentCustomer.Email);
+ _logger.LogInformation("Access denied to user #{CurrentCustomerEmail}", _contextAccessor.WorkContext.CurrentCustomer.Email);
return View();
}
diff --git a/src/Web/Grand.Web.Vendor/Controllers/LoginController.cs b/src/Web/Grand.Web.Vendor/Controllers/LoginController.cs
index 08a040689..2739d00b8 100644
--- a/src/Web/Grand.Web.Vendor/Controllers/LoginController.cs
+++ b/src/Web/Grand.Web.Vendor/Controllers/LoginController.cs
@@ -28,7 +28,7 @@ public class LoginController : BaseController
private readonly IMediator _mediator;
private readonly IMessageProviderService _messageProviderService;
private readonly ITranslationService _translationService;
- private readonly IWorkContextAccessor _workContextAccessor;
+ private readonly IContextAccessor _contextAccessor;
public LoginController(
CustomerSettings customerSettings,
@@ -38,7 +38,7 @@ public class LoginController : BaseController
ICustomerService customerService,
IGrandAuthenticationService authenticationService,
IMessageProviderService messageProviderService,
- IWorkContextAccessor workContextAccessor,
+ IContextAccessor contextAccessor,
IMediator mediator)
{
_customerSettings = customerSettings;
@@ -48,7 +48,7 @@ public class LoginController : BaseController
_customerService = customerService;
_authenticationService = authenticationService;
_messageProviderService = messageProviderService;
- _workContextAccessor = workContextAccessor;
+ _contextAccessor = contextAccessor;
_mediator = mediator;
}
@@ -128,11 +128,11 @@ public class LoginController : BaseController
if (_customerSettings.TwoFactorAuthenticationType != TwoFactorAuthenticationType.AppVerification)
{
- await twoFactorAuthenticationService.GenerateCodeSetup("", customer, _workContextAccessor.WorkContext.WorkingLanguage,
+ await twoFactorAuthenticationService.GenerateCodeSetup("", customer, _contextAccessor.WorkContext.WorkingLanguage,
_customerSettings.TwoFactorAuthenticationType);
if (_customerSettings.TwoFactorAuthenticationType == TwoFactorAuthenticationType.EmailVerification)
await _messageProviderService.SendCustomerEmailTokenValidationMessage(customer,
- _workContextAccessor.WorkContext.CurrentStore, _workContextAccessor.WorkContext.WorkingLanguage.Id);
+ _contextAccessor.StoreContext.CurrentStore, _contextAccessor.WorkContext.WorkingLanguage.Id);
}
return View();
diff --git a/src/Web/Grand.Web.Vendor/Controllers/MerchandiseReturnController.cs b/src/Web/Grand.Web.Vendor/Controllers/MerchandiseReturnController.cs
index 5a2fa0784..e02f4db27 100644
--- a/src/Web/Grand.Web.Vendor/Controllers/MerchandiseReturnController.cs
+++ b/src/Web/Grand.Web.Vendor/Controllers/MerchandiseReturnController.cs
@@ -24,12 +24,12 @@ public class MerchandiseReturnController : BaseVendorController
IMerchandiseReturnViewModelService merchandiseReturnViewModelService,
ITranslationService translationService,
IMerchandiseReturnService merchandiseReturnService,
- IWorkContextAccessor workContextAccessor)
+ IContextAccessor contextAccessor)
{
_merchandiseReturnViewModelService = merchandiseReturnViewModelService;
_translationService = translationService;
_merchandiseReturnService = merchandiseReturnService;
- _workContextAccessor = workContextAccessor;
+ _contextAccessor = contextAccessor;
}
#endregion
@@ -39,7 +39,7 @@ public class MerchandiseReturnController : BaseVendorController
private readonly IMerchandiseReturnViewModelService _merchandiseReturnViewModelService;
private readonly ITranslationService _translationService;
private readonly IMerchandiseReturnService _merchandiseReturnService;
- private readonly IWorkContextAccessor _workContextAccessor;
+ private readonly IContextAccessor _contextAccessor;
#endregion Fields
@@ -77,7 +77,7 @@ public class MerchandiseReturnController : BaseVendorController
public async Task<IActionResult> GoToId(MerchandiseReturnListModel model)
{
var merchandiseReturn = await _merchandiseReturnService.GetMerchandiseReturnById(model.GoDirectlyToId);
- if (merchandiseReturn == null || merchandiseReturn.VendorId != _workContextAccessor.WorkContext.CurrentVendor.Id)
+ if (merchandiseReturn == null || merchandiseReturn.VendorId != _contextAccessor.WorkContext.CurrentVendor.Id)
//not found
return RedirectToAction("List", "MerchandiseReturn");
@@ -89,7 +89,7 @@ public class MerchandiseReturnController : BaseVendorController
public async Task<IActionResult> ProductsForMerchandiseReturn(string merchandiseReturnId)
{
var merchandiseReturn = await _merchandiseReturnService.GetMerchandiseReturnById(merchandiseReturnId);
- if (merchandiseReturn == null || merchandiseReturn.VendorId != _workContextAccessor.WorkContext.CurrentVendor.Id)
+ if (merchandiseReturn == null || merchandiseReturn.VendorId != _contextAccessor.WorkContext.CurrentVendor.Id)
return ErrorForKendoGridJson("Merchandise return not found");
var items = await _merchandiseReturnViewModelService.PrepareMerchandiseReturnItemModel(merchandiseReturnId);
@@ -106,7 +106,7 @@ public class MerchandiseReturnController : BaseVendorController
public async Task<IActionResult> Edit(string id)
{
var merchandiseReturn = await _merchandiseReturnService.GetMerchandiseReturnById(id);
- if (merchandiseReturn == null || merchandiseReturn.VendorId != _workContextAccessor.WorkContext.CurrentVendor.Id)
+ if (merchandiseReturn == null || merchandiseReturn.VendorId != _contextAccessor.WorkContext.CurrentVendor.Id)
//No merchandise return found with the specified id
return RedirectToAction("List");
@@ -125,7 +125,7 @@ public class MerchandiseReturnController : BaseVendorController
)
{
var merchandiseReturn = await _merchandiseReturnService.GetMerchandiseReturnById(model.Id);
- if (merchandiseReturn == null || merchandiseReturn.VendorId != _workContextAccessor.WorkContext.CurrentVendor.Id)
+ if (merchandiseReturn == null || merchandiseReturn.VendorId != _contextAccessor.WorkContext.CurrentVendor.Id)
//No merchandise return found with the specified id
return RedirectToAction("List");
@@ -157,7 +157,7 @@ public class MerchandiseReturnController : BaseVendorController
public async Task<IActionResult> Delete(string id)
{
var merchandiseReturn = await _merchandiseReturnService.GetMerchandiseReturnById(id);
- if (merchandiseReturn == null || merchandiseReturn.VendorId != _workContextAccessor.WorkContext.CurrentVendor.Id)
+ if (merchandiseReturn == null || merchandiseReturn.VendorId != _contextAccessor.WorkContext.CurrentVendor.Id)
//No merchandise return found with the specified id
return RedirectToAction("List");
@@ -181,7 +181,7 @@ public class MerchandiseReturnController : BaseVendorController
public async Task<IActionResult> MerchandiseReturnNotesSelect(string merchandiseReturnId)
{
var merchandiseReturn = await _merchandiseReturnService.GetMerchandiseReturnById(merchandiseReturnId);
- if (merchandiseReturn == null || merchandiseReturn.VendorId != _workContextAccessor.WorkContext.CurrentVendor.Id)
+ if (merchandiseReturn == null || merchandiseReturn.VendorId != _contextAccessor.WorkContext.CurrentVendor.Id)
throw new ArgumentException("No merchandise return found with the specified id");
//merchandise return notes
@@ -199,7 +199,7 @@ public class MerchandiseReturnController : BaseVendorController
string message)
{
var merchandiseReturn = await _merchandiseReturnService.GetMerchandiseReturnById(merchandiseReturnId);
- if (merchandiseReturn == null || merchandiseReturn.VendorId != _workContextAccessor.WorkContext.CurrentVendor.Id)
+ if (merchandiseReturn == null || merchandiseReturn.VendorId != _contextAccessor.WorkContext.CurrentVendor.Id)
return Json(new { Result = false });
await _merchandiseReturnViewModelService.InsertMerchandiseReturnNote(merchandiseReturn, displayToCustomer,
@@ -213,7 +213,7 @@ public class MerchandiseReturnController : BaseVendorController
public async Task<IActionResult> MerchandiseReturnNoteDelete(string id, string merchandiseReturnId)
{
var merchandiseReturn = await _merchandiseReturnService.GetMerchandiseReturnById(merchandiseReturnId);
- if (merchandiseReturn == null || merchandiseReturn.VendorId != _workContextAccessor.WorkContext.CurrentVendor.Id)
+ if (merchandiseReturn == null || merchandiseReturn.VendorId != _contextAccessor.WorkContext.CurrentVendor.Id)
throw new ArgumentException("No merchandise return found with the specified id");
await _merchandiseReturnViewModelService.DeleteMerchandiseReturnNote(merchandiseReturn, id);
diff --git a/src/Web/Grand.Web.Vendor/Controllers/OrderController.cs b/src/Web/Grand.Web.Vendor/Controllers/OrderController.cs
index f1293a516..66a810779 100644
--- a/src/Web/Grand.Web.Vendor/Controllers/OrderController.cs
+++ b/src/Web/Grand.Web.Vendor/Controllers/OrderController.cs
@@ -23,13 +23,13 @@ public class OrderController : BaseVendorController
IOrderViewModelService orderViewModelService,
IOrderService orderService,
ITranslationService translationService,
- IWorkContextAccessor workContextAccessor,
+ IContextAccessor contextAccessor,
IPdfService pdfService)
{
_orderViewModelService = orderViewModelService;
_orderService = orderService;
_translationService = translationService;
- _workContextAccessor = workContextAccessor;
+ _contextAccessor = contextAccessor;
_pdfService = pdfService;
}
@@ -40,7 +40,7 @@ public class OrderController : BaseVendorController
private readonly IOrderViewModelService _orderViewModelService;
private readonly IOrderService _orderService;
private readonly ITranslationService _translationService;
- private readonly IWorkContextAccessor _workContextAccessor;
+ private readonly IContextAccessor _contextAccessor;
private readonly IPdfService _pdfService;
#endregion
@@ -71,7 +71,7 @@ public class OrderController : BaseVendorController
//products
const int productNumber = 15;
var products = (await productService.SearchProducts(
- vendorId: _workContextAccessor.WorkContext.CurrentVendor.Id,
+ vendorId: _contextAccessor.WorkContext.CurrentVendor.Id,
keywords: term,
pageSize: productNumber,
showHidden: true)).products;
@@ -133,7 +133,7 @@ public class OrderController : BaseVendorController
public async Task<IActionResult> Edit(string id)
{
var order = await _orderService.GetOrderById(id);
- if (order == null || order.Deleted || !_workContextAccessor.WorkContext.HasAccessToOrder(order))
+ if (order == null || order.Deleted || !_contextAccessor.WorkContext.HasAccessToOrder(order))
//No order found with the specified id
return RedirectToAction("List");
@@ -147,7 +147,7 @@ public class OrderController : BaseVendorController
{
var order = await _orderService.GetOrderById(orderId);
//No order found with the specified id
- if (order == null || order.Deleted || !_workContextAccessor.WorkContext.HasAccessToOrder(order)) return RedirectToAction("List");
+ if (order == null || order.Deleted || !_contextAccessor.WorkContext.HasAccessToOrder(order)) return RedirectToAction("List");
var orders = new List<Order> {
order
@@ -155,8 +155,8 @@ public class OrderController : BaseVendorController
byte[] bytes;
using (var stream = new MemoryStream())
{
- await _pdfService.PrintOrdersToPdf(stream, orders, _workContextAccessor.WorkContext.WorkingLanguage.Id,
- _workContextAccessor.WorkContext.CurrentVendor.Id);
+ await _pdfService.PrintOrdersToPdf(stream, orders, _contextAccessor.WorkContext.WorkingLanguage.Id,
+ _contextAccessor.WorkContext.CurrentVendor.Id);
bytes = stream.ToArray();
}
@@ -172,8 +172,8 @@ public class OrderController : BaseVendorController
byte[] bytes;
using (var stream = new MemoryStream())
{
- await _pdfService.PrintOrdersToPdf(stream, orders, _workContextAccessor.WorkContext.WorkingLanguage.Id,
- _workContextAccessor.WorkContext.CurrentVendor.Id);
+ await _pdfService.PrintOrdersToPdf(stream, orders, _contextAccessor.WorkContext.WorkingLanguage.Id,
+ _contextAccessor.WorkContext.CurrentVendor.Id);
bytes = stream.ToArray();
}
@@ -195,7 +195,7 @@ public class OrderController : BaseVendorController
}
//a vendor should have access only to his products
- orders = orders.Where(_workContextAccessor.WorkContext.HasAccessToOrder).ToList();
+ orders = orders.Where(_contextAccessor.WorkContext.HasAccessToOrder).ToList();
//ensure that we at least one order selected
if (orders.Count == 0)
@@ -207,8 +207,8 @@ public class OrderController : BaseVendorController
byte[] bytes;
using (var stream = new MemoryStream())
{
- await _pdfService.PrintOrdersToPdf(stream, orders, _workContextAccessor.WorkContext.WorkingLanguage.Id,
- _workContextAccessor.WorkContext.CurrentVendor.Id);
+ await _pdfService.PrintOrdersToPdf(stream, orders, _contextAccessor.WorkContext.WorkingLanguage.Id,
+ _contextAccessor.WorkContext.CurrentVendor.Id);
bytes = stream.ToArray();
}
diff --git a/src/Web/Grand.Web.Vendor/Controllers/ProductController.cs b/src/Web/Grand.Web.Vendor/Controllers/ProductController.cs
index 94bba619e..202d45ab3 100644
--- a/src/Web/Grand.Web.Vendor/Controllers/ProductController.cs
+++ b/src/Web/Grand.Web.Vendor/Controllers/ProductController.cs
@@ -22,6 +22,7 @@ using Grand.Web.Vendor.Models.Orders;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.Rendering;
using Microsoft.AspNetCore.StaticFiles;
+using Grand.Web.Common.Helpers;
namespace Grand.Web.Vendor.Controllers;
@@ -34,7 +35,7 @@ public class ProductController : BaseVendorController
IProductViewModelService productViewModelService,
IProductService productService,
IInventoryManageService inventoryManageService,
- IWorkContextAccessor workContextAccessor,
+ IContextAccessor contextAccessor,
ILanguageService languageService,
ITranslationService translationService,
IProductReservationService productReservationService,
@@ -46,7 +47,7 @@ public class ProductController : BaseVendorController
_productViewModelService = productViewModelService;
_productService = productService;
_inventoryManageService = inventoryManageService;
- _workContextAccessor = workContextAccessor;
+ _contextAccessor = contextAccessor;
_languageService = languageService;
_translationService = translationService;
_productReservationService = productReservationService;
@@ -63,7 +64,7 @@ public class ProductController : BaseVendorController
private readonly IProductViewModelService _productViewModelService;
private readonly IProductService _productService;
private readonly IInventoryManageService _inventoryManageService;
- private readonly IWorkContextAccessor _workContextAccessor;
+ private readonly IContextAccessor _contextAccessor;
private readonly ILanguageService _languageService;
private readonly ITranslationService _translationService;
private readonly IProductReservationService _productReservationService;
@@ -81,7 +82,7 @@ public class ProductController : BaseVendorController
if (product == null) return Task.FromResult((false, "Product not exists"));
//a vendor should have access only to his products
- return product.VendorId != _workContextAccessor.WorkContext.CurrentVendor.Id
+ return product.VendorId != _contextAccessor.WorkContext.CurrentVendor.Id
? Task.FromResult((false, "This is not your product"))
: Task.FromResult<(bool allow, string message)>((true, null));
}
@@ -161,7 +162,7 @@ public class ProductController : BaseVendorController
public async Task<IActionResult> Edit(string id)
{
var product = await _productService.GetProductById(id, true);
- if (product == null || product.VendorId != _workContextAccessor.WorkContext.CurrentVendor.Id)
+ if (product == null || product.VendorId != _contextAccessor.WorkContext.CurrentVendor.Id)
//No product found with the specified id
return RedirectToAction("List");
@@ -189,7 +190,7 @@ public class ProductController : BaseVendorController
public async Task<IActionResult> Edit(ProductModel model, bool continueEditing)
{
var product = await _productService.GetProductById(model.Id, true);
- if (product == null || product.VendorId != _workContextAccessor.WorkContext.CurrentVendor.Id)
+ if (product == null || product.VendorId != _contextAccessor.WorkContext.CurrentVendor.Id)
//No product found with the specified id
return RedirectToAction("List");
@@ -226,7 +227,7 @@ public class ProductController : BaseVendorController
public async Task<IActionResult> Delete(string id)
{
var product = await _productService.GetProductById(id, true);
- if (product == null || product.VendorId != _workContextAccessor.WorkContext.CurrentVendor.Id)
+ if (product == null || product.VendorId != _contextAccessor.WorkContext.CurrentVendor.Id)
//No product found with the specified id
return RedirectToAction("List");
@@ -260,7 +261,7 @@ public class ProductController : BaseVendorController
{
var originalProduct = await _productService.GetProductById(copyModel.Id, true);
//a vendor should have access only to his products
- if (originalProduct == null || originalProduct.VendorId != _workContextAccessor.WorkContext.CurrentVendor.Id)
+ if (originalProduct == null || originalProduct.VendorId != _contextAccessor.WorkContext.CurrentVendor.Id)
return RedirectToAction("List");
var newProduct = await copyProductService.CopyProduct(originalProduct,
@@ -321,7 +322,7 @@ public class ProductController : BaseVendorController
var products = await _productService.GetProductsByIds(Enumerable.ToArray(rangeArray), true);
for (var i = 0; i <= products.Count - 1; i++)
{
- if (products[i].VendorId != _workContextAccessor.WorkContext.CurrentVendor.Id) continue;
+ if (products[i].VendorId != _contextAccessor.WorkContext.CurrentVendor.Id) continue;
result += products[i].Name;
if (i != products.Count - 1)
@@ -972,7 +973,7 @@ public class ProductController : BaseVendorController
return ErrorForKendoGridJson(permission.message);
var vendorId = "";
- if (_workContextAccessor.WorkContext.CurrentVendor != null) vendorId = _workContextAccessor.WorkContext.CurrentVendor.Id;
+ if (_contextAccessor.WorkContext.CurrentVendor != null) vendorId = _contextAccessor.WorkContext.CurrentVendor.Id;
var associatedProducts = await _productService.GetAssociatedProducts(productId,
vendorId: vendorId,
@@ -1001,7 +1002,7 @@ public class ProductController : BaseVendorController
if (ModelState.IsValid)
{
var associatedProduct = await _productService.GetProductById(model.Id);
- if (associatedProduct == null || associatedProduct.VendorId != _workContextAccessor.WorkContext.CurrentVendor.Id)
+ if (associatedProduct == null || associatedProduct.VendorId != _contextAccessor.WorkContext.CurrentVendor.Id)
throw new ArgumentException("No associated product found with the specified id");
associatedProduct.DisplayOrder = model.DisplayOrder;
@@ -1020,7 +1021,7 @@ public class ProductController : BaseVendorController
if (ModelState.IsValid)
{
var product = await _productService.GetProductById(model.Id);
- if (product == null || product.VendorId != _workContextAccessor.WorkContext.CurrentVendor.Id)
+ if (product == null || product.VendorId != _contextAccessor.WorkContext.CurrentVendor.Id)
throw new ArgumentException("No associated product found with the specified id");
await _productViewModelService.DeleteAssociatedProduct(product);
@@ -1102,7 +1103,7 @@ public class ProductController : BaseVendorController
var product = await _productService.GetProductById(objectId);
//a vendor should have access only to his products
- if (product.VendorId != _workContextAccessor.WorkContext.CurrentVendor.Id)
+ if (product.VendorId != _contextAccessor.WorkContext.CurrentVendor.Id)
return Json(new {
success = false,
message = "Access denied - vendor permissions"
@@ -1446,7 +1447,7 @@ public class ProductController : BaseVendorController
}
//a vendor should have access only to his products
- products = products.Where(p => p.VendorId == _workContextAccessor.WorkContext.CurrentVendor.Id).ToList();
+ products = products.Where(p => p.VendorId == _contextAccessor.WorkContext.CurrentVendor.Id).ToList();
var bytes = await exportManager.Export(products);
return File(bytes, "text/xls", "products.xlsx");
@@ -1672,7 +1673,7 @@ public class ProductController : BaseVendorController
return Content("Empty tier price");
//a vendor should have access only to his products
- if (product.VendorId != _workContextAccessor.WorkContext.CurrentVendor.Id)
+ if (product.VendorId != _contextAccessor.WorkContext.CurrentVendor.Id)
return Content("This is not your product");
var model = tierPrice.ToModel(_dateTimeService);
@@ -1803,7 +1804,7 @@ public class ProductController : BaseVendorController
throw new ArgumentException("No product attribute mapping found with the specified id");
//a vendor should have access only to his products
- if (product.VendorId != _workContextAccessor.WorkContext.CurrentVendor.Id)
+ if (product.VendorId != _contextAccessor.WorkContext.CurrentVendor.Id)
return Content("This is not your product");
await productAttributeService.DeleteProductAttributeMapping(productAttributeMapping, product.Id);
@@ -1909,7 +1910,7 @@ public class ProductController : BaseVendorController
[FromServices] IProductAttributeService productAttributeService)
{
var product = await _productService.GetProductById(productId);
- if (product == null || product.VendorId != _workContextAccessor.WorkContext.CurrentVendor.Id)
+ if (product == null || product.VendorId != _contextAccessor.WorkContext.CurrentVendor.Id)
throw new ArgumentException("No product found with the specified id");
var productAttributeMapping =
@@ -2036,7 +2037,7 @@ public class ProductController : BaseVendorController
ProductModel.ProductAttributeValueModel model)
{
var product = await _productService.GetProductById(productId);
- if (product == null || product.VendorId != _workContextAccessor.WorkContext.CurrentVendor.Id)
+ if (product == null || product.VendorId != _contextAccessor.WorkContext.CurrentVendor.Id)
throw new ArgumentException("No product found with the specified id");
var pav = product.ProductAttributeMappings.FirstOrDefault(x => x.Id == model.ProductAttributeMappingId)
@@ -2063,7 +2064,7 @@ public class ProductController : BaseVendorController
[FromServices] IProductAttributeService productAttributeService)
{
var product = await _productService.GetProductById(productId);
- if (product == null || product.VendorId != _workContextAccessor.WorkContext.CurrentVendor.Id)
+ if (product == null || product.VendorId != _contextAccessor.WorkContext.CurrentVendor.Id)
throw new ArgumentException("No product found with the specified id");
var pav = product.ProductAttributeMappings.FirstOrDefault(x => x.Id == pam)?.ProductAttributeValues
@@ -2106,7 +2107,7 @@ public class ProductController : BaseVendorController
ProductModel.ProductAttributeValueModel.AssociateProductToAttributeValueModel model)
{
var associatedProduct = await _productService.GetProductById(model.AssociatedToProductId);
- if (associatedProduct == null || associatedProduct.VendorId != _workContextAccessor.WorkContext.CurrentVendor.Id)
+ if (associatedProduct == null || associatedProduct.VendorId != _contextAccessor.WorkContext.CurrentVendor.Id)
return Content("Cannot load a product");
return Content("");
@@ -2140,7 +2141,7 @@ public class ProductController : BaseVendorController
[FromServices] IProductAttributeService productAttributeService)
{
var product = await _productService.GetProductById(productId);
- if (product == null || product.VendorId != _workContextAccessor.WorkContext.CurrentVendor.Id)
+ if (product == null || product.VendorId != _contextAccessor.WorkContext.CurrentVendor.Id)
throw new ArgumentException("No product found with the specified id");
var combination = product.ProductAttributeCombinations.FirstOrDefault(x => x.Id == id);
@@ -2181,7 +2182,7 @@ public class ProductController : BaseVendorController
ProductAttributeCombinationModel model)
{
var product = await _productService.GetProductById(productId);
- if (product == null || product.VendorId != _workContextAccessor.WorkContext.CurrentVendor.Id)
+ if (product == null || product.VendorId != _contextAccessor.WorkContext.CurrentVendor.Id)
//No product found with the specified id
return RedirectToAction("List", "Product");
@@ -2200,7 +2201,7 @@ public class ProductController : BaseVendorController
public async Task<IActionResult> GenerateAllAttributeCombinations(string productId)
{
var product = await _productService.GetProductById(productId);
- if (product == null || product.VendorId != _workContextAccessor.WorkContext.CurrentVendor.Id)
+ if (product == null || product.VendorId != _contextAccessor.WorkContext.CurrentVendor.Id)
throw new ArgumentException("No product found with the specified id");
await _productViewModelService.GenerateAllAttributeCombinations(product);
@@ -2213,7 +2214,7 @@ public class ProductController : BaseVendorController
public async Task<IActionResult> ClearAllAttributeCombinations(string productId)
{
var product = await _productService.GetProductById(productId);
- if (product == null || product.VendorId != _workContextAccessor.WorkContext.CurrentVendor.Id)
+ if (product == null || product.VendorId != _contextAccessor.WorkContext.CurrentVendor.Id)
throw new ArgumentException("No product found with the specified id");
if (ModelState.IsValid)
@@ -2304,7 +2305,7 @@ public class ProductController : BaseVendorController
string productAttributeCombinationId, string id)
{
var product = await _productService.GetProductById(productId);
- if (product == null || product.VendorId != _workContextAccessor.WorkContext.CurrentVendor.Id)
+ if (product == null || product.VendorId != _contextAccessor.WorkContext.CurrentVendor.Id)
throw new ArgumentException("No product found with the specified id");
var combination =
@@ -2363,7 +2364,7 @@ public class ProductController : BaseVendorController
public async Task<IActionResult> GenerateCalendar(ProductModel.GenerateCalendarModel model)
{
var product = await _productService.GetProductById(model.ProductId);
- if (product == null || product.VendorId != _workContextAccessor.WorkContext.CurrentVendor.Id)
+ if (product == null || product.VendorId != _contextAccessor.WorkContext.CurrentVendor.Id)
throw new ArgumentException("No product found with the specified id");
var reservations =
@@ -2455,7 +2456,7 @@ public class ProductController : BaseVendorController
(iterator.DayOfWeek == DayOfWeek.Sunday && !model.Sunday))
continue;
- for (var i = 0; i < model.Quantity; i++)
+ for (var i = 0; i < model.Quantity.MaxQuantity(); i++)
{
dates.Add(iterator);
try
@@ -2494,7 +2495,7 @@ public class ProductController : BaseVendorController
public async Task<IActionResult> ClearCalendar(string productId)
{
var product = await _productService.GetProductById(productId);
- if (product == null || product.VendorId != _workContextAccessor.WorkContext.CurrentVendor.Id)
+ if (product == null || product.VendorId != _contextAccessor.WorkContext.CurrentVendor.Id)
throw new ArgumentException("No product found with the specified id");
var toDelete = await _productReservationService.GetProductReservationsByProductId(productId, true, null);
@@ -2507,7 +2508,7 @@ public class ProductController : BaseVendorController
public async Task<IActionResult> ClearOld(string productId)
{
var product = await _productService.GetProductById(productId);
- if (product == null || product.VendorId != _workContextAccessor.WorkContext.CurrentVendor.Id)
+ if (product == null || product.VendorId != _contextAccessor.WorkContext.CurrentVendor.Id)
throw new ArgumentException("No product found with the specified id");
var toDelete =
@@ -2523,7 +2524,7 @@ public class ProductController : BaseVendorController
public async Task<IActionResult> ProductReservationDelete(ProductModel.ReservationModel model)
{
var product = await _productService.GetProductById(model.ProductId);
- if (product == null || product.VendorId != _workContextAccessor.WorkContext.CurrentVendor.Id)
+ if (product == null || product.VendorId != _contextAccessor.WorkContext.CurrentVendor.Id)
throw new ArgumentException("No product found with the specified id");
var toDelete = await _productReservationService.GetProductReservation(model.ReservationId);
@@ -2550,7 +2551,7 @@ public class ProductController : BaseVendorController
public async Task<IActionResult> ListBids(DataSourceRequest command, string productId)
{
var product = await _productService.GetProductById(productId);
- if (product == null || product.VendorId != _workContextAccessor.WorkContext.CurrentVendor.Id)
+ if (product == null || product.VendorId != _contextAccessor.WorkContext.CurrentVendor.Id)
throw new ArgumentException("No product found with the specified id");
var (bidModels, totalCount) =
@@ -2567,7 +2568,7 @@ public class ProductController : BaseVendorController
public async Task<IActionResult> BidDelete(ProductModel.BidModel model)
{
var product = await _productService.GetProductById(model.ProductId);
- if (product == null || product.VendorId != _workContextAccessor.WorkContext.CurrentVendor.Id)
+ if (product == null || product.VendorId != _contextAccessor.WorkContext.CurrentVendor.Id)
throw new ArgumentException("No product found with the specified id");
var toDelete = await _auctionService.GetBid(model.BidId);
diff --git a/src/Web/Grand.Web.Vendor/Controllers/ReportsController.cs b/src/Web/Grand.Web.Vendor/Controllers/ReportsController.cs
index 1bafab70f..6e2133656 100644
--- a/src/Web/Grand.Web.Vendor/Controllers/ReportsController.cs
+++ b/src/Web/Grand.Web.Vendor/Controllers/ReportsController.cs
@@ -34,12 +34,12 @@ public class ReportsController : BaseVendorController
private readonly IProductsReportService _productsReportService;
private readonly IStockQuantityService _stockQuantityService;
private readonly ITranslationService _translationService;
- private readonly IWorkContextAccessor _workContextAccessor;
+ private readonly IContextAccessor _contextAccessor;
private readonly IEnumTranslationService _enumTranslationService;
public ReportsController(IOrderReportService orderReportService,
IProductsReportService productsReportService,
ICustomerReportService customerReportService,
- IWorkContextAccessor workContextAccessor,
+ IContextAccessor contextAccessor,
IPriceFormatter priceFormatter,
IProductService productService,
IProductAttributeFormatter productAttributeFormatter,
@@ -55,7 +55,7 @@ public class ReportsController : BaseVendorController
_orderReportService = orderReportService;
_productsReportService = productsReportService;
_customerReportService = customerReportService;
- _workContextAccessor = workContextAccessor;
+ _contextAccessor = contextAccessor;
_priceFormatter = priceFormatter;
_productService = productService;
_productAttributeFormatter = productAttributeFormatter;
@@ -74,7 +74,7 @@ public class ReportsController : BaseVendorController
int pageSize, int orderBy)
{
var items = await _orderReportService.BestSellersReport(
- vendorId: _workContextAccessor.WorkContext.CurrentVendor.Id,
+ vendorId: _contextAccessor.WorkContext.CurrentVendor.Id,
orderBy: orderBy,
pageIndex: pageIndex,
pageSize: pageSize,
@@ -156,7 +156,7 @@ public class ReportsController : BaseVendorController
ps: paymentStatus,
billingCountryId: model.BillingCountryId,
orderBy: 2,
- vendorId: _workContextAccessor.WorkContext.CurrentVendor.Id,
+ vendorId: _contextAccessor.WorkContext.CurrentVendor.Id,
pageIndex: command.Page - 1,
pageSize: command.PageSize,
showHidden: true,
@@ -174,9 +174,9 @@ public class ReportsController : BaseVendorController
var product = await _productService.GetProductById(x.ProductId);
if (product != null)
m.ProductName = product.Name;
- if (_workContextAccessor.WorkContext.CurrentVendor != null)
+ if (_contextAccessor.WorkContext.CurrentVendor != null)
{
- if (product?.VendorId == _workContextAccessor.WorkContext.CurrentVendor.Id)
+ if (product?.VendorId == _contextAccessor.WorkContext.CurrentVendor.Id)
result.Add(m);
}
else
@@ -211,7 +211,7 @@ public class ReportsController : BaseVendorController
: _dateTimeService.ConvertToUtcTime(model.EndDate.Value, _dateTimeService.CurrentTimeZone).AddDays(1);
- var items = await _orderReportService.ProductsNeverSold("", _workContextAccessor.WorkContext.CurrentVendor.Id,
+ var items = await _orderReportService.ProductsNeverSold("", _contextAccessor.WorkContext.CurrentVendor.Id,
startDateValue, endDateValue,
command.Page - 1, command.PageSize, true);
var gridModel = new DataSourceResult {
@@ -253,7 +253,7 @@ public class ReportsController : BaseVendorController
var paymentStatus = model.PaymentStatusId > 0 ? (PaymentStatus?)model.PaymentStatusId : null;
var items = await _orderReportService.GetCountryReport(
- vendorId: _workContextAccessor.WorkContext.CurrentVendor.Id,
+ vendorId: _contextAccessor.WorkContext.CurrentVendor.Id,
ps: paymentStatus,
startTimeUtc: startDateValue,
endTimeUtc: endDateValue);
@@ -287,7 +287,7 @@ public class ReportsController : BaseVendorController
[HttpPost]
public async Task<IActionResult> LowStockReportList(DataSourceRequest command)
{
- var lowStockProducts = await _productsReportService.LowStockProducts(_workContextAccessor.WorkContext.CurrentVendor.Id);
+ var lowStockProducts = await _productsReportService.LowStockProducts(_contextAccessor.WorkContext.CurrentVendor.Id);
var models = new List<LowStockProductModel>();
//products
@@ -311,7 +311,7 @@ public class ReportsController : BaseVendorController
Id = product.Id,
Name = product.Name,
Attributes = await _productAttributeFormatter.FormatAttributes(product, combination.Attributes,
- _workContextAccessor.WorkContext.CurrentCustomer, "<br />", true, true, true, false),
+ _contextAccessor.WorkContext.CurrentCustomer, "<br />", true, true, true, false),
ManageInventoryMethod = _enumTranslationService.GetTranslationEnum(product.ManageInventoryMethodId),
StockQuantity = combination.StockQuantity,
Published = product.Published
@@ -357,7 +357,7 @@ public class ReportsController : BaseVendorController
var paymentStatus = model.PaymentStatusId > 0 ? (PaymentStatus?)model.PaymentStatusId : null;
- var items = _customerReportService.GetBestCustomersReport("", _workContextAccessor.WorkContext.CurrentVendor.Id, startDateValue,
+ var items = _customerReportService.GetBestCustomersReport("", _contextAccessor.WorkContext.CurrentVendor.Id, startDateValue,
endDateValue,
null, paymentStatus, null, 2, command.Page - 1, command.PageSize);
diff --git a/src/Web/Grand.Web.Vendor/Controllers/ShipmentController.cs b/src/Web/Grand.Web.Vendor/Controllers/ShipmentController.cs
index 00d026bd9..4fb395e44 100644
--- a/src/Web/Grand.Web.Vendor/Controllers/ShipmentController.cs
+++ b/src/Web/Grand.Web.Vendor/Controllers/ShipmentController.cs
@@ -27,7 +27,7 @@ public class ShipmentController : BaseVendorController
IShipmentViewModelService shipmentViewModelService,
IOrderService orderService,
ITranslationService translationService,
- IWorkContextAccessor workContextAccessor,
+ IContextAccessor contextAccessor,
IPdfService pdfService,
IShipmentService shipmentService,
IDateTimeService dateTimeService,
@@ -36,7 +36,7 @@ public class ShipmentController : BaseVendorController
_shipmentViewModelService = shipmentViewModelService;
_orderService = orderService;
_translationService = translationService;
- _workContextAccessor = workContextAccessor;
+ _contextAccessor = contextAccessor;
_pdfService = pdfService;
_shipmentService = shipmentService;
_dateTimeService = dateTimeService;
@@ -48,7 +48,7 @@ public class ShipmentController : BaseVendorController
private readonly IShipmentViewModelService _shipmentViewModelService;
private readonly IOrderService _orderService;
private readonly ITranslationService _translationService;
- private readonly IWorkContextAccessor _workContextAccessor;
+ private readonly IContextAccessor _contextAccessor;
private readonly IPdfService _pdfService;
private readonly IShipmentService _shipmentService;
private readonly IDateTimeService _dateTimeService;
@@ -85,14 +85,14 @@ public class ShipmentController : BaseVendorController
public async Task<IActionResult> ShipmentsByOrder(string orderId)
{
var order = await _orderService.GetOrderById(orderId);
- if (order == null || order.Deleted || !_workContextAccessor.WorkContext.HasAccessToOrder(order))
+ if (order == null || order.Deleted || !_contextAccessor.WorkContext.HasAccessToOrder(order))
throw new ArgumentException("No order found with the specified id");
//shipments
var shipmentModels = new List<ShipmentModel>();
var shipments = (await _shipmentService.GetShipmentsByOrder(orderId))
//a vendor should have access only to his products
- .Where(s => _workContextAccessor.WorkContext.HasAccessToShipment(s))
+ .Where(s => _contextAccessor.WorkContext.HasAccessToShipment(s))
.OrderBy(s => s.CreatedOnUtc)
.ToList();
@@ -111,7 +111,7 @@ public class ShipmentController : BaseVendorController
public async Task<IActionResult> ShipmentsItemsByShipmentId(string shipmentId)
{
var shipment = await _shipmentService.GetShipmentById(shipmentId);
- if (shipment == null || !_workContextAccessor.WorkContext.HasAccessToShipment(shipment))
+ if (shipment == null || !_contextAccessor.WorkContext.HasAccessToShipment(shipment))
throw new ArgumentException("No shipment found with the specified id");
//shipments
@@ -128,7 +128,7 @@ public class ShipmentController : BaseVendorController
public async Task<IActionResult> AddShipment(string orderId)
{
var order = await _orderService.GetOrderById(orderId);
- if (order == null || order.Deleted || !_workContextAccessor.WorkContext.HasAccessToOrder(order))
+ if (order == null || order.Deleted || !_contextAccessor.WorkContext.HasAccessToOrder(order))
//No order found with the specified id
return RedirectToAction("List");
@@ -145,12 +145,12 @@ public class ShipmentController : BaseVendorController
return RedirectToAction("AddShipment", new { orderId = model.OrderId });
var order = await _orderService.GetOrderById(model.OrderId);
- if (order == null || order.Deleted || !_workContextAccessor.WorkContext.HasAccessToOrder(order))
+ if (order == null || order.Deleted || !_contextAccessor.WorkContext.HasAccessToOrder(order))
//No order found with the specified id
return RedirectToAction("List");
//a vendor should have access only to his products
- var orderItems = order.OrderItems.Where(_workContextAccessor.WorkContext.HasAccessToOrderItem).ToList();
+ var orderItems = order.OrderItems.Where(_contextAccessor.WorkContext.HasAccessToOrderItem).ToList();
var (shipment, totalWeight) =
await _shipmentViewModelService.PrepareShipment(order, orderItems.ToList(), model);
@@ -187,7 +187,7 @@ public class ShipmentController : BaseVendorController
public async Task<IActionResult> ShipmentDetails(string id)
{
var shipment = await _shipmentService.GetShipmentById(id);
- if (shipment == null || !_workContextAccessor.WorkContext.HasAccessToShipment(shipment))
+ if (shipment == null || !_contextAccessor.WorkContext.HasAccessToShipment(shipment))
//No shipment found with the specified id
return RedirectToAction("List");
@@ -200,7 +200,7 @@ public class ShipmentController : BaseVendorController
public async Task<IActionResult> DeleteShipment(string id)
{
var shipment = await _shipmentService.GetShipmentById(id);
- if (shipment == null || !_workContextAccessor.WorkContext.HasAccessToShipment(shipment))
+ if (shipment == null || !_contextAccessor.WorkContext.HasAccessToShipment(shipment))
//No shipment found with the specified id
return RedirectToAction("List");
@@ -225,7 +225,7 @@ public class ShipmentController : BaseVendorController
return RedirectToAction("ShipmentDetails", new { id = model.Id });
var shipment = await _shipmentService.GetShipmentById(model.Id);
- if (shipment == null || !_workContextAccessor.WorkContext.HasAccessToShipment(shipment))
+ if (shipment == null || !_contextAccessor.WorkContext.HasAccessToShipment(shipment))
//No shipment found with the specified id
return RedirectToAction("List");
@@ -243,7 +243,7 @@ public class ShipmentController : BaseVendorController
return RedirectToAction("ShipmentDetails", new { id = model.Id });
var shipment = await _shipmentService.GetShipmentById(model.Id);
- if (shipment == null || !_workContextAccessor.WorkContext.HasAccessToShipment(shipment))
+ if (shipment == null || !_contextAccessor.WorkContext.HasAccessToShipment(shipment))
//No shipment found with the specified id
return RedirectToAction("List");
@@ -258,7 +258,7 @@ public class ShipmentController : BaseVendorController
public async Task<IActionResult> SetAsShipped(string id)
{
var shipment = await _shipmentService.GetShipmentById(id);
- if (shipment == null || !_workContextAccessor.WorkContext.HasAccessToShipment(shipment))
+ if (shipment == null || !_contextAccessor.WorkContext.HasAccessToShipment(shipment))
//No shipment found with the specified id
return RedirectToAction("List");
@@ -283,7 +283,7 @@ public class ShipmentController : BaseVendorController
return RedirectToAction("ShipmentDetails", new { id = model.Id });
var shipment = await _shipmentService.GetShipmentById(model.Id);
- if (shipment == null || !_workContextAccessor.WorkContext.HasAccessToShipment(shipment))
+ if (shipment == null || !_contextAccessor.WorkContext.HasAccessToShipment(shipment))
//No shipment found with the specified id
return RedirectToAction("List");
@@ -308,7 +308,7 @@ public class ShipmentController : BaseVendorController
public async Task<IActionResult> SetAsDelivered(string id)
{
var shipment = await _shipmentService.GetShipmentById(id);
- if (shipment == null || !_workContextAccessor.WorkContext.HasAccessToShipment(shipment))
+ if (shipment == null || !_contextAccessor.WorkContext.HasAccessToShipment(shipment))
//No shipment found with the specified id
return RedirectToAction("List");
@@ -334,7 +334,7 @@ public class ShipmentController : BaseVendorController
return RedirectToAction("ShipmentDetails", new { id = model.Id });
var shipment = await _shipmentService.GetShipmentById(model.Id);
- if (shipment == null || !_workContextAccessor.WorkContext.HasAccessToShipment(shipment))
+ if (shipment == null || !_contextAccessor.WorkContext.HasAccessToShipment(shipment))
//No shipment found with the specified id
return RedirectToAction("List");
@@ -358,7 +358,7 @@ public class ShipmentController : BaseVendorController
public async Task<IActionResult> PdfPackagingSlip(string shipmentId)
{
var shipment = await _shipmentService.GetShipmentById(shipmentId);
- if (shipment == null || !_workContextAccessor.WorkContext.HasAccessToShipment(shipment))
+ if (shipment == null || !_contextAccessor.WorkContext.HasAccessToShipment(shipment))
//no shipment found with the specified id
return RedirectToAction("List");
@@ -369,7 +369,7 @@ public class ShipmentController : BaseVendorController
byte[] bytes;
using (var stream = new MemoryStream())
{
- await _pdfService.PrintPackagingSlipsToPdf(stream, shipments, _workContextAccessor.WorkContext.WorkingLanguage.Id);
+ await _pdfService.PrintPackagingSlipsToPdf(stream, shipments, _contextAccessor.WorkContext.WorkingLanguage.Id);
bytes = stream.ToArray();
}
@@ -394,7 +394,7 @@ public class ShipmentController : BaseVendorController
using (var stream = new MemoryStream())
{
await _pdfService.PrintPackagingSlipsToPdf(stream, shipments.shipments.ToList(),
- _workContextAccessor.WorkContext.WorkingLanguage.Id);
+ _contextAccessor.WorkContext.WorkingLanguage.Id);
bytes = stream.ToArray();
}
@@ -418,7 +418,7 @@ public class ShipmentController : BaseVendorController
//a vendor should have access only to his shipments
var shipmentsAccess =
(from item in shipments
- where _workContextAccessor.WorkContext.HasAccessToShipment(item)
+ where _contextAccessor.WorkContext.HasAccessToShipment(item)
select item).ToList();
//ensure that we at least one shipment selected
@@ -431,7 +431,7 @@ public class ShipmentController : BaseVendorController
byte[] bytes;
using (var stream = new MemoryStream())
{
- await _pdfService.PrintPackagingSlipsToPdf(stream, shipmentsAccess, _workContextAccessor.WorkContext.WorkingLanguage.Id);
+ await _pdfService.PrintPackagingSlipsToPdf(stream, shipmentsAccess, _contextAccessor.WorkContext.WorkingLanguage.Id);
bytes = stream.ToArray();
}
@@ -448,7 +448,7 @@ public class ShipmentController : BaseVendorController
//a vendor should have access only to his shipments
shipmentsAccess.AddRange(from item in shipments
- where _workContextAccessor.WorkContext.HasAccessToShipment(item)
+ where _contextAccessor.WorkContext.HasAccessToShipment(item)
select item);
foreach (var shipment in shipmentsAccess)
@@ -475,7 +475,7 @@ public class ShipmentController : BaseVendorController
//a vendor should have access only to his shipments
shipmentsAccess.AddRange(
from item in shipments
- where _workContextAccessor.WorkContext.HasAccessToShipment(item)
+ where _contextAccessor.WorkContext.HasAccessToShipment(item)
select item);
foreach (var shipment in shipmentsAccess)
@@ -498,7 +498,7 @@ public class ShipmentController : BaseVendorController
public async Task<IActionResult> ShipmentNotesSelect(string shipmentId)
{
var shipment = await _shipmentService.GetShipmentById(shipmentId);
- if (shipment == null || !_workContextAccessor.WorkContext.HasAccessToShipment(shipment))
+ if (shipment == null || !_contextAccessor.WorkContext.HasAccessToShipment(shipment))
throw new ArgumentException("No shipment found with the specified id");
//shipment notes
@@ -515,7 +515,7 @@ public class ShipmentController : BaseVendorController
string message)
{
var shipment = await _shipmentService.GetShipmentById(shipmentId);
- if (shipment == null || !_workContextAccessor.WorkContext.HasAccessToShipment(shipment))
+ if (shipment == null || !_contextAccessor.WorkContext.HasAccessToShipment(shipment))
return Json(new { Result = false });
await _shipmentViewModelService.InsertShipmentNote(shipment, displayToCustomer, message);
@@ -528,7 +528,7 @@ public class ShipmentController : BaseVendorController
public async Task<IActionResult> ShipmentNoteDelete(string id, string shipmentId)
{
var shipment = await _shipmentService.GetShipmentById(shipmentId);
- if (shipment == null || !_workContextAccessor.WorkContext.HasAccessToShipment(shipment))
+ if (shipment == null || !_contextAccessor.WorkContext.HasAccessToShipment(shipment))
throw new ArgumentException("No shipment found with the specified id");
await _shipmentViewModelService.DeleteShipmentNote(shipment, id);
diff --git a/src/Web/Grand.Web.Vendor/Controllers/VendorInfoController.cs b/src/Web/Grand.Web.Vendor/Controllers/VendorInfoController.cs
index 185286b7d..da6869011 100644
--- a/src/Web/Grand.Web.Vendor/Controllers/VendorInfoController.cs
+++ b/src/Web/Grand.Web.Vendor/Controllers/VendorInfoController.cs
@@ -22,7 +22,7 @@ public class VendorInfoController : BaseVendorController
ITranslationService translationService,
IVendorService vendorService,
ILanguageService languageService,
- IWorkContextAccessor workContextAccessor,
+ IContextAccessor contextAccessor,
ICountryService countryService,
VendorSettings vendorSettings,
ISeNameService seNameService)
@@ -30,7 +30,7 @@ public class VendorInfoController : BaseVendorController
_translationService = translationService;
_vendorService = vendorService;
_languageService = languageService;
- _workContextAccessor = workContextAccessor;
+ _contextAccessor = contextAccessor;
_countryService = countryService;
_vendorSettings = vendorSettings;
_seNameService = seNameService;
@@ -40,7 +40,7 @@ public class VendorInfoController : BaseVendorController
#region Fields
- private readonly IWorkContextAccessor _workContextAccessor;
+ private readonly IContextAccessor _contextAccessor;
private readonly ITranslationService _translationService;
private readonly IVendorService _vendorService;
private readonly ILanguageService _languageService;
@@ -121,7 +121,7 @@ public class VendorInfoController : BaseVendorController
if (!_vendorSettings.AllowVendorsToEditInfo)
throw new Exception("Vendor can't edit info");
- var vendor = await _vendorService.GetVendorById(_workContextAccessor.WorkContext.CurrentVendor.Id);
+ var vendor = await _vendorService.GetVendorById(_contextAccessor.WorkContext.CurrentVendor.Id);
if (vendor == null || vendor.Deleted)
throw new ArgumentNullException(nameof(vendor));
@@ -151,7 +151,7 @@ public class VendorInfoController : BaseVendorController
throw new Exception("Vendor can't edit info");
var vendor = await _vendorService.GetVendorById(model.Id);
- if (vendor == null || vendor.Deleted || vendor.Id != _workContextAccessor.WorkContext.CurrentVendor.Id)
+ if (vendor == null || vendor.Deleted || vendor.Id != _contextAccessor.WorkContext.CurrentVendor.Id)
throw new ArgumentNullException(nameof(vendor));
if (ModelState.IsValid)
diff --git a/src/Web/Grand.Web.Vendor/Controllers/VendorReviewController.cs b/src/Web/Grand.Web.Vendor/Controllers/VendorReviewController.cs
index ac3b603a7..a26197396 100644
--- a/src/Web/Grand.Web.Vendor/Controllers/VendorReviewController.cs
+++ b/src/Web/Grand.Web.Vendor/Controllers/VendorReviewController.cs
@@ -20,12 +20,12 @@ public class VendorReviewController : BaseVendorController
IVendorReviewViewModelService vendorReviewViewModelService,
IVendorService vendorService,
ITranslationService translationService,
- IWorkContextAccessor workContextAccessor)
+ IContextAccessor contextAccessor)
{
_vendorReviewViewModelService = vendorReviewViewModelService;
_vendorService = vendorService;
_translationService = translationService;
- _workContextAccessor = workContextAccessor;
+ _contextAccessor = contextAccessor;
}
#endregion
@@ -35,7 +35,7 @@ public class VendorReviewController : BaseVendorController
private readonly IVendorReviewViewModelService _vendorReviewViewModelService;
private readonly IVendorService _vendorService;
private readonly ITranslationService _translationService;
- private readonly IWorkContextAccessor _workContextAccessor;
+ private readonly IContextAccessor _contextAccessor;
#endregion Fields
@@ -73,7 +73,7 @@ public class VendorReviewController : BaseVendorController
{
var vendorReview = await _vendorService.GetVendorReviewById(id);
- if (vendorReview == null || vendorReview.VendorId != _workContextAccessor.WorkContext.CurrentVendor.Id)
+ if (vendorReview == null || vendorReview.VendorId != _contextAccessor.WorkContext.CurrentVendor.Id)
//No vendor review found with the specified id
return RedirectToAction("List");
@@ -88,7 +88,7 @@ public class VendorReviewController : BaseVendorController
public async Task<IActionResult> Edit(VendorReviewModel model, bool continueEditing)
{
var vendorReview = await _vendorService.GetVendorReviewById(model.Id);
- if (vendorReview == null || vendorReview.VendorId != _workContextAccessor.WorkContext.CurrentVendor.Id)
+ if (vendorReview == null || vendorReview.VendorId != _contextAccessor.WorkContext.CurrentVendor.Id)
//No vendor review found with the specified id
return RedirectToAction("List");
@@ -112,7 +112,7 @@ public class VendorReviewController : BaseVendorController
public async Task<IActionResult> Delete(string id)
{
var vendorReview = await _vendorService.GetVendorReviewById(id);
- if (vendorReview == null || vendorReview.VendorId != _workContextAccessor.WorkContext.CurrentVendor.Id)
+ if (vendorReview == null || vendorReview.VendorId != _contextAccessor.WorkContext.CurrentVendor.Id)
//No vendor review found with the specified id
return RedirectToAction("List");
diff --git a/src/Web/Grand.Web.Vendor/Services/MerchandiseReturnViewModelService.cs b/src/Web/Grand.Web.Vendor/Services/MerchandiseReturnViewModelService.cs
index 391acd1a2..5869284ac 100644
--- a/src/Web/Grand.Web.Vendor/Services/MerchandiseReturnViewModelService.cs
+++ b/src/Web/Grand.Web.Vendor/Services/MerchandiseReturnViewModelService.cs
@@ -27,7 +27,7 @@ public class MerchandiseReturnViewModelService : IMerchandiseReturnViewModelServ
#region Fields
private readonly IOrderService _orderService;
- private readonly IWorkContextAccessor _workContextAccessor;
+ private readonly IContextAccessor _contextAccessor;
private readonly IProductService _productService;
private readonly IDateTimeService _dateTimeService;
private readonly ICustomerService _customerService;
@@ -49,7 +49,7 @@ public class MerchandiseReturnViewModelService : IMerchandiseReturnViewModelServ
public MerchandiseReturnViewModelService(
IOrderService orderService,
- IWorkContextAccessor workContextAccessor,
+ IContextAccessor contextAccessor,
IProductService productService,
ICustomerService customerService,
IDateTimeService dateTimeService,
@@ -66,7 +66,7 @@ public class MerchandiseReturnViewModelService : IMerchandiseReturnViewModelServ
IEnumTranslationService enumTranslationService)
{
_orderService = orderService;
- _workContextAccessor = workContextAccessor;
+ _contextAccessor = contextAccessor;
_productService = productService;
_customerService = customerService;
_dateTimeService = dateTimeService;
@@ -154,7 +154,7 @@ public class MerchandiseReturnViewModelService : IMerchandiseReturnViewModelServ
var merchandiseReturns = await _merchandiseReturnService.SearchMerchandiseReturns(
customerId: customerId,
- vendorId: _workContextAccessor.WorkContext.CurrentVendor.Id,
+ vendorId: _contextAccessor.WorkContext.CurrentVendor.Id,
rs: model.SearchMerchandiseReturnStatusId >= 0
? (MerchandiseReturnStatus?)model.SearchMerchandiseReturnStatusId
: null,
diff --git a/src/Web/Grand.Web.Vendor/Services/OrderViewModelService.cs b/src/Web/Grand.Web.Vendor/Services/OrderViewModelService.cs
index 3d3b89c24..ac44d88b2 100644
--- a/src/Web/Grand.Web.Vendor/Services/OrderViewModelService.cs
+++ b/src/Web/Grand.Web.Vendor/Services/OrderViewModelService.cs
@@ -38,7 +38,7 @@ public class OrderViewModelService : IOrderViewModelService
private readonly IDateTimeService _dateTimeService;
private readonly IPriceFormatter _priceFormatter;
private readonly ITranslationService _translationService;
- private readonly IWorkContextAccessor _workContextAccessor;
+ private readonly IContextAccessor _contextAccessor;
private readonly ICurrencyService _currencyService;
private readonly IPaymentService _paymentService;
private readonly ICountryService _countryService;
@@ -67,7 +67,7 @@ public class OrderViewModelService : IOrderViewModelService
IDateTimeService dateTimeService,
IPriceFormatter priceFormatter,
ITranslationService translationService,
- IWorkContextAccessor workContextAccessor,
+ IContextAccessor contextAccessor,
ICurrencyService currencyService,
IPaymentService paymentService,
ICountryService countryService,
@@ -91,7 +91,7 @@ public class OrderViewModelService : IOrderViewModelService
_dateTimeService = dateTimeService;
_priceFormatter = priceFormatter;
_translationService = translationService;
- _workContextAccessor = workContextAccessor;
+ _contextAccessor = contextAccessor;
_currencyService = currencyService;
_paymentService = paymentService;
_countryService = countryService;
@@ -216,7 +216,7 @@ public class OrderViewModelService : IOrderViewModelService
//load orders
var orders = await _orderService.SearchOrders(
- vendorId: _workContextAccessor.WorkContext.CurrentVendor.Id,
+ vendorId: _contextAccessor.WorkContext.CurrentVendor.Id,
customerId: model.CustomerId,
productId: model.ProductId,
warehouseId: model.WarehouseId,
@@ -321,7 +321,7 @@ public class OrderViewModelService : IOrderViewModelService
model.BillingAddress = await order.BillingAddress.ToModel(_countryService);
model.BillingAddress.FormattedCustomAddressAttributes =
- await _addressAttributeParser.FormatAttributes(_workContextAccessor.WorkContext.WorkingLanguage,
+ await _addressAttributeParser.FormatAttributes(_contextAccessor.WorkContext.WorkingLanguage,
order.BillingAddress.Attributes);
model.BillingAddress.NameEnabled = _addressSettings.NameEnabled;
model.BillingAddress.FirstNameEnabled = true;
@@ -361,7 +361,7 @@ public class OrderViewModelService : IOrderViewModelService
{
model.ShippingAddress = await order.ShippingAddress.ToModel(_countryService);
model.ShippingAddress.FormattedCustomAddressAttributes =
- await _addressAttributeParser.FormatAttributes(_workContextAccessor.WorkContext.WorkingLanguage,
+ await _addressAttributeParser.FormatAttributes(_contextAccessor.WorkContext.WorkingLanguage,
order.ShippingAddress.Attributes);
model.ShippingAddress.NameEnabled = _addressSettings.NameEnabled;
model.ShippingAddress.FirstNameEnabled = true;
@@ -429,7 +429,7 @@ public class OrderViewModelService : IOrderViewModelService
model.CheckoutAttributeInfo = order.CheckoutAttributeDescription;
var hasDownloadableItems = false;
var products = order.OrderItems
- .Where(orderItem => orderItem.VendorId == _workContextAccessor.WorkContext.CurrentVendor.Id)
+ .Where(orderItem => orderItem.VendorId == _contextAccessor.WorkContext.CurrentVendor.Id)
.ToList();
foreach (var orderItem in products)
@@ -553,7 +553,7 @@ public class OrderViewModelService : IOrderViewModelService
//load orders
var orders = await _orderService.SearchOrders(
- vendorId: _workContextAccessor.WorkContext.CurrentVendor.Id,
+ vendorId: _contextAccessor.WorkContext.CurrentVendor.Id,
productId: model.ProductId,
warehouseId: model.WarehouseId,
paymentMethodSystemName: model.PaymentMethodSystemName,
diff --git a/src/Web/Grand.Web.Vendor/Services/ProductViewModelService.cs b/src/Web/Grand.Web.Vendor/Services/ProductViewModelService.cs
index 239c1b63a..6d277a2b2 100644
--- a/src/Web/Grand.Web.Vendor/Services/ProductViewModelService.cs
+++ b/src/Web/Grand.Web.Vendor/Services/ProductViewModelService.cs
@@ -61,7 +61,7 @@ public class ProductViewModelService : IProductViewModelService
private readonly TaxSettings _taxSettings;
private readonly ITranslationService _translationService;
private readonly IWarehouseService _warehouseService;
- private readonly IWorkContextAccessor _workContextAccessor;
+ private readonly IContextAccessor _contextAccessor;
private readonly ISeNameService _seNameService;
private readonly IEnumTranslationService _enumTranslationService;
@@ -80,7 +80,7 @@ public class ProductViewModelService : IProductViewModelService
ITranslationService translationService,
IProductLayoutService productLayoutService,
ISpecificationAttributeService specificationAttributeService,
- IWorkContextAccessor workContextAccessor,
+ IContextAccessor contextAccessor,
IWarehouseService warehouseService,
IDeliveryDateService deliveryDateService,
ITaxCategoryService taxCategoryService,
@@ -112,7 +112,7 @@ public class ProductViewModelService : IProductViewModelService
_translationService = translationService;
_productLayoutService = productLayoutService;
_specificationAttributeService = specificationAttributeService;
- _workContextAccessor = workContextAccessor;
+ _contextAccessor = contextAccessor;
_warehouseService = warehouseService;
_deliveryDateService = deliveryDateService;
_taxCategoryService = taxCategoryService;
@@ -613,7 +613,7 @@ public class ProductViewModelService : IProductViewModelService
categoryIds: categoryIds,
brandId: model.SearchBrandId,
collectionId: model.SearchCollectionId,
- vendorId: _workContextAccessor.WorkContext.CurrentVendor.Id,
+ vendorId: _contextAccessor.WorkContext.CurrentVendor.Id,
warehouseId: model.SearchWarehouseId,
productType: model.SearchProductTypeId > 0 ? (ProductType?)model.SearchProductTypeId : null,
keywords: model.SearchProductName,
@@ -674,7 +674,7 @@ public class ProductViewModelService : IProductViewModelService
categoryIds: categoryIds,
brandId: model.SearchBrandId,
collectionId: model.SearchCollectionId,
- vendorId: _workContextAccessor.WorkContext.CurrentVendor.Id,
+ vendorId: _contextAccessor.WorkContext.CurrentVendor.Id,
warehouseId: model.SearchWarehouseId,
productType: model.SearchProductTypeId > 0 ? (ProductType?)model.SearchProductTypeId : null,
keywords: model.SearchProductName,
@@ -689,7 +689,7 @@ public class ProductViewModelService : IProductViewModelService
{
//product
var product = model.ToEntity(_dateTimeService);
- product.VendorId = _workContextAccessor.WorkContext.CurrentVendor?.Id;
+ product.VendorId = _contextAccessor.WorkContext.CurrentVendor?.Id;
product.Locales = await _seNameService.TranslationSeNameProperties(model.Locales, product, x => x.Name);
product.SeName = await _seNameService.ValidateSeName(product, model.SeName, product.Name, true);
@@ -750,7 +750,7 @@ public class ProductViewModelService : IProductViewModelService
{
var product = products[i];
//a vendor should have access only to his products
- if (product.VendorId != _workContextAccessor.WorkContext.CurrentVendor.Id)
+ if (product.VendorId != _contextAccessor.WorkContext.CurrentVendor.Id)
continue;
await DeleteProduct(product);
@@ -767,7 +767,7 @@ public class ProductViewModelService : IProductViewModelService
ProductModel.AddProductModel model, int pageIndex, int pageSize)
{
var products = await _productService.PrepareProductList(model.SearchCategoryId, model.SearchBrandId,
- model.SearchCollectionId, string.Empty, _workContextAccessor.WorkContext.CurrentVendor.Id, model.SearchProductTypeId,
+ model.SearchCollectionId, string.Empty, _contextAccessor.WorkContext.CurrentVendor.Id, model.SearchProductTypeId,
model.SearchProductName, pageIndex, pageSize);
return (products.Select(x => x.ToModel(_dateTimeService)).ToList(), products.TotalCount);
}
@@ -898,7 +898,7 @@ public class ProductViewModelService : IProductViewModelService
foreach (var id in model.SelectedProductIds)
{
var product = await _productService.GetProductById(id);
- if (product == null || product.VendorId != _workContextAccessor.WorkContext.CurrentVendor.Id) continue;
+ if (product == null || product.VendorId != _contextAccessor.WorkContext.CurrentVendor.Id) continue;
var existingRelatedProducts = productId1.RelatedProducts;
if (model.ProductId == id) continue;
@@ -943,7 +943,7 @@ public class ProductViewModelService : IProductViewModelService
foreach (var id in model.SelectedProductIds)
{
var product = await _productService.GetProductById(id);
- if (product != null && productId1.VendorId == _workContextAccessor.WorkContext.CurrentVendor.Id)
+ if (product != null && productId1.VendorId == _contextAccessor.WorkContext.CurrentVendor.Id)
{
var existingSimilarProducts = productId1.SimilarProducts;
if (model.ProductId != id)
@@ -991,7 +991,7 @@ public class ProductViewModelService : IProductViewModelService
foreach (var id in model.SelectedProductIds)
{
var product = await _productService.GetProductById(id);
- if (product != null && productId1.VendorId == _workContextAccessor.WorkContext.CurrentVendor.Id)
+ if (product != null && productId1.VendorId == _contextAccessor.WorkContext.CurrentVendor.Id)
{
var existingBundleProducts = productId1.BundleProducts;
if (model.ProductId != id)
@@ -1038,7 +1038,7 @@ public class ProductViewModelService : IProductViewModelService
foreach (var id in model.SelectedProductIds)
{
var product = await _productService.GetProductById(id);
- if (product != null && product.VendorId == _workContextAccessor.WorkContext.CurrentVendor.Id &&
+ if (product != null && product.VendorId == _contextAccessor.WorkContext.CurrentVendor.Id &&
crossSellProduct.CrossSellProduct.All(x => x != id))
if (model.ProductId != id)
await _productService.InsertCrossSellProduct(
@@ -1064,7 +1064,7 @@ public class ProductViewModelService : IProductViewModelService
foreach (var id in model.SelectedProductIds)
{
var product = await _productService.GetProductById(id);
- if (product != null && product.VendorId == _workContextAccessor.WorkContext.CurrentVendor.Id)
+ if (product != null && product.VendorId == _contextAccessor.WorkContext.CurrentVendor.Id)
if (mainproduct.RecommendedProduct.All(x => x != id))
if (model.ProductId != id)
await _productService.InsertRecommendedProduct(model.ProductId, id);
@@ -1081,7 +1081,7 @@ public class ProductViewModelService : IProductViewModelService
foreach (var id in model.SelectedProductIds)
{
var product = await _productService.GetProductById(id);
- if (product == null || product.VendorId != _workContextAccessor.WorkContext.CurrentVendor.Id) continue;
+ if (product == null || product.VendorId != _contextAccessor.WorkContext.CurrentVendor.Id) continue;
product.ParentGroupedProductId = model.ProductId;
await _productService.UpdateAssociatedProduct(product);
}
@@ -1152,7 +1152,7 @@ public class ProductViewModelService : IProductViewModelService
var products = (await _productService.SearchProducts(categoryIds: searchCategoryIds,
brandId: model.SearchBrandId,
collectionId: model.SearchCollectionId,
- vendorId: _workContextAccessor.WorkContext.CurrentVendor.Id,
+ vendorId: _contextAccessor.WorkContext.CurrentVendor.Id,
productType: model.SearchProductTypeId > 0 ? (ProductType?)model.SearchProductTypeId : null,
keywords: model.SearchProductName,
pageIndex: pageIndex - 1,
@@ -1182,7 +1182,7 @@ public class ProductViewModelService : IProductViewModelService
{
//update
var product = await _productService.GetProductById(pModel.Id, true);
- if (product == null || product.VendorId != _workContextAccessor.WorkContext.CurrentVendor.Id) continue;
+ if (product == null || product.VendorId != _contextAccessor.WorkContext.CurrentVendor.Id) continue;
var prevStockQuantity = _stockQuantityService.GetTotalStockQuantity(product, total: true);
@@ -1212,7 +1212,7 @@ public class ProductViewModelService : IProductViewModelService
{
//delete
var product = await _productService.GetProductById(pModel.Id, true);
- if (product == null || product.VendorId != _workContextAccessor.WorkContext.CurrentVendor.Id) continue;
+ if (product == null || product.VendorId != _contextAccessor.WorkContext.CurrentVendor.Id) continue;
await _productService.DeleteProduct(product);
}
@@ -1780,7 +1780,7 @@ public class ProductViewModelService : IProductViewModelService
foreach (var x in product.ProductAttributeCombinations)
{
var attributes = await _productAttributeFormatter.FormatAttributes(product, x.Attributes,
- _workContextAccessor.WorkContext.CurrentCustomer, "<br />", true, true, true, false, true, true);
+ _contextAccessor.WorkContext.CurrentCustomer, "<br />", true, true, true, false, true, true);
var pacModel = new ProductModel.ProductAttributeCombinationModel {
Id = x.Id,
ProductId = product.Id,
@@ -1831,7 +1831,7 @@ public class ProductViewModelService : IProductViewModelService
model.WarehouseInventoryModels = wim;
model.ProductId = product.Id;
model.Attributes = await _productAttributeFormatter.FormatAttributes(product,
- combination.Attributes, _workContextAccessor.WorkContext.CurrentCustomer, "<br />", true, true, true, false);
+ combination.Attributes, _contextAccessor.WorkContext.CurrentCustomer, "<br />", true, true, true, false);
if (model.UseMultipleWarehouses)
foreach (var winv in combination.WarehouseInventory)
{
diff --git a/src/Web/Grand.Web.Vendor/Services/ShipmentViewModelService.cs b/src/Web/Grand.Web.Vendor/Services/ShipmentViewModelService.cs
index 927204c83..10776fd2a 100644
--- a/src/Web/Grand.Web.Vendor/Services/ShipmentViewModelService.cs
+++ b/src/Web/Grand.Web.Vendor/Services/ShipmentViewModelService.cs
@@ -32,11 +32,11 @@ public class ShipmentViewModelService : IShipmentViewModelService
private readonly IStockQuantityService _stockQuantityService;
private readonly ITranslationService _translationService;
private readonly IWarehouseService _warehouseService;
- private readonly IWorkContextAccessor _workContextAccessor;
+ private readonly IContextAccessor _contextAccessor;
public ShipmentViewModelService(
IOrderService orderService,
- IWorkContextAccessor workContextAccessor,
+ IContextAccessor contextAccessor,
IGroupService groupService,
IProductService productService,
IShipmentService shipmentService,
@@ -51,7 +51,7 @@ public class ShipmentViewModelService : IShipmentViewModelService
ShippingProviderSettings shippingProviderSettings)
{
_orderService = orderService;
- _workContextAccessor = workContextAccessor;
+ _contextAccessor = contextAccessor;
_groupService = groupService;
_productService = productService;
_shipmentService = shipmentService;
@@ -104,7 +104,7 @@ public class ShipmentViewModelService : IShipmentViewModelService
if (orderItem == null)
continue;
- if (orderItem.VendorId != _workContextAccessor.WorkContext.CurrentVendor.Id)
+ if (orderItem.VendorId != _contextAccessor.WorkContext.CurrentVendor.Id)
continue;
//quantities
@@ -261,7 +261,7 @@ public class ShipmentViewModelService : IShipmentViewModelService
//load shipments
var shipments = await _shipmentService.GetAllShipments(
- vendorId: _workContextAccessor.WorkContext.CurrentVendor.Id,
+ vendorId: _contextAccessor.WorkContext.CurrentVendor.Id,
warehouseId: model.WarehouseId,
shippingCity: model.City,
trackingNumber: model.TrackingNumber,
@@ -301,8 +301,8 @@ public class ShipmentViewModelService : IShipmentViewModelService
var orderItems = order.OrderItems;
//a vendor should have access only to his products
- if (_workContextAccessor.WorkContext.CurrentVendor != null && !await _groupService.IsStaff(_workContextAccessor.WorkContext.CurrentCustomer))
- orderItems = orderItems.Where(_workContextAccessor.WorkContext.HasAccessToOrderItem).ToList();
+ if (_contextAccessor.WorkContext.CurrentVendor != null && !await _groupService.IsStaff(_contextAccessor.WorkContext.CurrentCustomer))
+ orderItems = orderItems.Where(_contextAccessor.WorkContext.HasAccessToOrderItem).ToList();
foreach (var orderItem in orderItems)
{
@@ -498,7 +498,7 @@ public class ShipmentViewModelService : IShipmentViewModelService
DeliveryDateUtc = null,
AdminComment = model.AdminComment,
StoreId = order.StoreId,
- VendorId = _workContextAccessor.WorkContext.CurrentVendor.Id
+ VendorId = _contextAccessor.WorkContext.CurrentVendor.Id
};
double? totalWeight = null;
foreach (var orderItem in orderItems)
diff --git a/src/Web/Grand.Web.Vendor/Services/VendorReviewViewModelService.cs b/src/Web/Grand.Web.Vendor/Services/VendorReviewViewModelService.cs
index 003f560ea..9086f1258 100644
--- a/src/Web/Grand.Web.Vendor/Services/VendorReviewViewModelService.cs
+++ b/src/Web/Grand.Web.Vendor/Services/VendorReviewViewModelService.cs
@@ -18,10 +18,10 @@ public class VendorReviewViewModelService : IVendorReviewViewModelService
private readonly IMediator _mediator;
private readonly ITranslationService _translationService;
private readonly IVendorService _vendorService;
- private readonly IWorkContextAccessor _workContextAccessor;
+ private readonly IContextAccessor _contextAccessor;
public VendorReviewViewModelService(
- IWorkContextAccessor workContextAccessor,
+ IContextAccessor contextAccessor,
IVendorService vendorService,
ICustomerService customerService,
ITranslationService translationService,
@@ -33,7 +33,7 @@ public class VendorReviewViewModelService : IVendorReviewViewModelService
_translationService = translationService;
_dateTimeService = dateTimeService;
_mediator = mediator;
- _workContextAccessor = workContextAccessor;
+ _contextAccessor = contextAccessor;
}
public virtual async Task PrepareVendorReviewModel(VendorReviewModel model,
@@ -75,7 +75,7 @@ public class VendorReviewViewModelService : IVendorReviewViewModelService
: _dateTimeService.ConvertToUtcTime(model.CreatedOnTo.Value, _dateTimeService.CurrentTimeZone).AddDays(1);
var vendorReviews = await _vendorService.GetAllVendorReviews("", null,
- createdOnFromValue, createdToFromValue, model.SearchText, _workContextAccessor.WorkContext.CurrentVendor.Id, pageIndex - 1,
+ createdOnFromValue, createdToFromValue, model.SearchText, _contextAccessor.WorkContext.CurrentVendor.Id, pageIndex - 1,
pageSize);
var items = new List<VendorReviewModel>();
foreach (var x in vendorReviews)
@@ -115,12 +115,12 @@ public class VendorReviewViewModelService : IVendorReviewViewModelService
foreach (var id in selectedIds)
{
var vendorReview = await _vendorService.GetVendorReviewById(id);
- if (vendorReview == null || vendorReview.VendorId != _workContextAccessor.WorkContext.CurrentVendor.Id) continue;
+ if (vendorReview == null || vendorReview.VendorId != _contextAccessor.WorkContext.CurrentVendor.Id) continue;
var previousIsApproved = vendorReview.IsApproved;
vendorReview.IsApproved = true;
await _vendorService.UpdateVendorReview(vendorReview);
- await _vendorService.UpdateVendorReviewTotals(_workContextAccessor.WorkContext.CurrentVendor);
+ await _vendorService.UpdateVendorReviewTotals(_contextAccessor.WorkContext.CurrentVendor);
//raise event (only if it wasn't approved before)
if (!previousIsApproved)
@@ -133,11 +133,11 @@ public class VendorReviewViewModelService : IVendorReviewViewModelService
foreach (var id in selectedIds)
{
var vendorReview = await _vendorService.GetVendorReviewById(id);
- if (vendorReview == null || vendorReview.VendorId != _workContextAccessor.WorkContext.CurrentVendor.Id) continue;
+ if (vendorReview == null || vendorReview.VendorId != _contextAccessor.WorkContext.CurrentVendor.Id) continue;
vendorReview.IsApproved = false;
await _vendorService.UpdateVendorReview(vendorReview);
- await _vendorService.UpdateVendorReviewTotals(_workContextAccessor.WorkContext.CurrentVendor);
+ await _vendorService.UpdateVendorReviewTotals(_contextAccessor.WorkContext.CurrentVendor);
}
}
}
\ No newline at end of file
diff --git a/src/Web/Grand.Web.Vendor/Validators/Catalog/BundleProductModelValidator.cs b/src/Web/Grand.Web.Vendor/Validators/Catalog/BundleProductModelValidator.cs
index e2eebd5d1..742983a33 100644
--- a/src/Web/Grand.Web.Vendor/Validators/Catalog/BundleProductModelValidator.cs
+++ b/src/Web/Grand.Web.Vendor/Validators/Catalog/BundleProductModelValidator.cs
@@ -11,14 +11,14 @@ public class BundleProductModelValidator : BaseGrandValidator<ProductModel.Bundl
{
public BundleProductModelValidator(
IEnumerable<IValidatorConsumer<ProductModel.BundleProductModel>> validators,
- ITranslationService translationService, IProductService productService, IWorkContextAccessor workContextAccessor)
+ ITranslationService translationService, IProductService productService, IContextAccessor contextAccessor)
: base(validators)
{
RuleFor(x => x).MustAsync(async (x, _, _) =>
{
var product = await productService.GetProductById(x.ProductBundleId);
if (product == null) return true;
- return product.VendorId == workContextAccessor.WorkContext.CurrentVendor.Id;
+ return product.VendorId == contextAccessor.WorkContext.CurrentVendor.Id;
}).WithMessage(translationService.GetResource("Vendor.Catalog.Products.Permissions"));
}
}
\ No newline at end of file
diff --git a/src/Web/Grand.Web.Vendor/Validators/Catalog/ProductValidVendor.cs b/src/Web/Grand.Web.Vendor/Validators/Catalog/ProductValidVendor.cs
index 1e10338c5..f9173e5c9 100644
--- a/src/Web/Grand.Web.Vendor/Validators/Catalog/ProductValidVendor.cs
+++ b/src/Web/Grand.Web.Vendor/Validators/Catalog/ProductValidVendor.cs
@@ -11,14 +11,14 @@ public class ProductValidVendor : BaseGrandValidator<IProductValidVendor>
{
public ProductValidVendor(
IEnumerable<IValidatorConsumer<IProductValidVendor>> validators,
- ITranslationService translationService, IProductService productService, IWorkContextAccessor workContextAccessor)
+ ITranslationService translationService, IProductService productService, IContextAccessor contextAccessor)
: base(validators)
{
RuleFor(x => x).MustAsync(async (x, _, _) =>
{
var product = await productService.GetProductById(x.ProductId);
if (product == null) return true;
- return product.VendorId == workContextAccessor.WorkContext.CurrentVendor.Id;
+ return product.VendorId == contextAccessor.WorkContext.CurrentVendor.Id;
}).WithMessage(translationService.GetResource("Vendor.Catalog.Products.Permissions"));
}
}
@@ -27,7 +27,7 @@ public class ProductRelatedValidVendor : BaseGrandValidator<IProductRelatedValid
{
public ProductRelatedValidVendor(
IEnumerable<IValidatorConsumer<IProductRelatedValidVendor>> validators,
- ITranslationService translationService, IProductService productService, IWorkContextAccessor workContextAccessor)
+ ITranslationService translationService, IProductService productService, IContextAccessor contextAccessor)
: base(validators)
{
RuleFor(x => x).MustAsync(async (x, _, _) =>
@@ -36,8 +36,8 @@ public class ProductRelatedValidVendor : BaseGrandValidator<IProductRelatedValid
if (product1 == null) return true;
var product2 = await productService.GetProductById(x.ProductId2);
if (product2 == null) return true;
- return product1.VendorId == workContextAccessor.WorkContext.CurrentVendor.Id ||
- product2.VendorId == workContextAccessor.WorkContext.CurrentVendor.Id;
+ return product1.VendorId == contextAccessor.WorkContext.CurrentVendor.Id ||
+ product2.VendorId == contextAccessor.WorkContext.CurrentVendor.Id;
}).WithMessage(translationService.GetResource("Vendor.Catalog.Products.Permissions"));
}
}
\ No newline at end of file
diff --git a/src/Web/Grand.Web/Commands/Handler/Blogs/InsertBlogCommentCommandHandler.cs b/src/Web/Grand.Web/Commands/Handler/Blogs/InsertBlogCommentCommandHandler.cs
index 18429b838..14eabf264 100644
--- a/src/Web/Grand.Web/Commands/Handler/Blogs/InsertBlogCommentCommandHandler.cs
+++ b/src/Web/Grand.Web/Commands/Handler/Blogs/InsertBlogCommentCommandHandler.cs
@@ -17,14 +17,14 @@ public class InsertBlogCommentCommandHandler : IRequestHandler<InsertBlogComment
private readonly LanguageSettings _languageSettings;
private readonly IMessageProviderService _messageProviderService;
- private readonly IWorkContextAccessor _workContextAccessor;
+ private readonly IContextAccessor _contextAccessor;
- public InsertBlogCommentCommandHandler(IBlogService blogService, IWorkContextAccessor workContextAccessor,
+ public InsertBlogCommentCommandHandler(IBlogService blogService, IContextAccessor contextAccessor,
ICustomerService customerService, IMessageProviderService messageProviderService,
LanguageSettings languageSettings, BlogSettings blogSettings)
{
_blogService = blogService;
- _workContextAccessor = workContextAccessor;
+ _contextAccessor = contextAccessor;
_customerService = customerService;
_messageProviderService = messageProviderService;
@@ -34,11 +34,11 @@ public class InsertBlogCommentCommandHandler : IRequestHandler<InsertBlogComment
public async Task<BlogComment> Handle(InsertBlogCommentCommand request, CancellationToken cancellationToken)
{
- var customer = _workContextAccessor.WorkContext.CurrentCustomer;
+ var customer = _contextAccessor.WorkContext.CurrentCustomer;
var comment = new BlogComment {
BlogPostId = request.BlogPost.Id,
CustomerId = customer.Id,
- StoreId = _workContextAccessor.WorkContext.CurrentStore.Id,
+ StoreId = _contextAccessor.StoreContext.CurrentStore.Id,
CommentText = request.Model.CommentText,
BlogPostTitle = request.BlogPost.Title
};
diff --git a/src/Web/Grand.Web/Commands/Handler/Contact/ContactUsSendCommandHandler.cs b/src/Web/Grand.Web/Commands/Handler/Contact/ContactUsSendCommandHandler.cs
index 98840e0f0..d88e88b67 100644
--- a/src/Web/Grand.Web/Commands/Handler/Contact/ContactUsSendCommandHandler.cs
+++ b/src/Web/Grand.Web/Commands/Handler/Contact/ContactUsSendCommandHandler.cs
@@ -17,15 +17,15 @@ public class ContactUsSendCommandHandler : IRequestHandler<ContactUsSendCommand,
private readonly IContactAttributeParser _contactAttributeParser;
private readonly IMessageProviderService _messageProviderService;
private readonly ITranslationService _translationService;
- private readonly IWorkContextAccessor _workContextAccessor;
+ private readonly IContextAccessor _contextAccessor;
- public ContactUsSendCommandHandler(IWorkContextAccessor workContextAccessor,
+ public ContactUsSendCommandHandler(IContextAccessor contextAccessor,
IContactAttributeParser contactAttributeParser,
ITranslationService translationService,
IMessageProviderService messageProviderService,
CommonSettings commonSettings)
{
- _workContextAccessor = workContextAccessor;
+ _contextAccessor = contextAccessor;
_contactAttributeParser = contactAttributeParser;
_translationService = translationService;
_messageProviderService = messageProviderService;
@@ -39,9 +39,9 @@ public class ContactUsSendCommandHandler : IRequestHandler<ContactUsSendCommand,
request.Model.ContactAttribute = attributes;
request.Model.ContactAttributeInfo =
- await _contactAttributeParser.FormatAttributes(_workContextAccessor.WorkContext.WorkingLanguage, attributes,
- _workContextAccessor.WorkContext.CurrentCustomer);
- request.Model = await SendContactUs(request, _workContextAccessor.WorkContext.CurrentStore);
+ await _contactAttributeParser.FormatAttributes(_contextAccessor.WorkContext.WorkingLanguage, attributes,
+ _contextAccessor.WorkContext.CurrentCustomer);
+ request.Model = await SendContactUs(request, _contextAccessor.StoreContext.CurrentStore);
return request.Model;
}
@@ -52,7 +52,7 @@ public class ContactUsSendCommandHandler : IRequestHandler<ContactUsSendCommand,
var body = FormatText.ConvertText(request.Model.Enquiry);
await _messageProviderService.SendContactUsMessage
- (_workContextAccessor.WorkContext.CurrentCustomer, store, _workContextAccessor.WorkContext.WorkingLanguage.Id, request.Model.Email.Trim(),
+ (_contextAccessor.WorkContext.CurrentCustomer, store, _contextAccessor.WorkContext.WorkingLanguage.Id, request.Model.Email.Trim(),
request.Model.FullName, subject,
body, request.Model.ContactAttributeInfo, request.Model.ContactAttribute, request.IpAddress);
diff --git a/src/Web/Grand.Web/Commands/Handler/News/InsertNewsCommentCommandHandler.cs b/src/Web/Grand.Web/Commands/Handler/News/InsertNewsCommentCommandHandler.cs
index d1d5d56e7..de8fca0cc 100644
--- a/src/Web/Grand.Web/Commands/Handler/News/InsertNewsCommentCommandHandler.cs
+++ b/src/Web/Grand.Web/Commands/Handler/News/InsertNewsCommentCommandHandler.cs
@@ -17,13 +17,13 @@ public class InsertNewsCommentCommandHandler : IRequestHandler<InsertNewsComment
private readonly INewsService _newsService;
private readonly NewsSettings _newsSettings;
- private readonly IWorkContextAccessor _workContextAccessor;
+ private readonly IContextAccessor _contextAccessor;
- public InsertNewsCommentCommandHandler(IWorkContextAccessor workContextAccessor, INewsService newsService,
+ public InsertNewsCommentCommandHandler(IContextAccessor contextAccessor, INewsService newsService,
ICustomerService customerService, IMessageProviderService messageProviderService, NewsSettings newsSettings,
LanguageSettings languageSettings)
{
- _workContextAccessor = workContextAccessor;
+ _contextAccessor = contextAccessor;
_newsService = newsService;
_customerService = customerService;
_messageProviderService = messageProviderService;
@@ -36,8 +36,8 @@ public class InsertNewsCommentCommandHandler : IRequestHandler<InsertNewsComment
{
var comment = new NewsComment {
NewsItemId = request.NewsItem.Id,
- CustomerId = _workContextAccessor.WorkContext.CurrentCustomer.Id,
- StoreId = _workContextAccessor.WorkContext.CurrentStore.Id,
+ CustomerId = _contextAccessor.WorkContext.CurrentCustomer.Id,
+ StoreId = _contextAccessor.StoreContext.CurrentStore.Id,
CommentTitle = request.Model.CommentTitle,
CommentText = request.Model.CommentText
};
@@ -48,7 +48,7 @@ public class InsertNewsCommentCommandHandler : IRequestHandler<InsertNewsComment
await _newsService.UpdateNews(request.NewsItem);
- await _customerService.UpdateContributions(_workContextAccessor.WorkContext.CurrentCustomer);
+ await _customerService.UpdateContributions(_contextAccessor.WorkContext.CurrentCustomer);
//notify a store owner;
if (_newsSettings.NotifyAboutNewNewsComments)
diff --git a/src/Web/Grand.Web/Commands/Handler/Newsletter/SubscribeNewsletterHandler.cs b/src/Web/Grand.Web/Commands/Handler/Newsletter/SubscribeNewsletterHandler.cs
index 43aaa5f75..2e2789ece 100644
--- a/src/Web/Grand.Web/Commands/Handler/Newsletter/SubscribeNewsletterHandler.cs
+++ b/src/Web/Grand.Web/Commands/Handler/Newsletter/SubscribeNewsletterHandler.cs
@@ -17,18 +17,18 @@ public class SubscribeNewsletterHandler : IRequestHandler<SubscribeNewsletterCom
private readonly INewsletterCategoryService _newsletterCategoryService;
private readonly INewsLetterSubscriptionService _newsLetterSubscriptionService;
private readonly ITranslationService _translationService;
- private readonly IWorkContextAccessor _workContextAccessor;
+ private readonly IContextAccessor _contextAccessor;
public SubscribeNewsletterHandler(INewsLetterSubscriptionService newsLetterSubscriptionService,
ITranslationService translationService,
- IMessageProviderService messageProviderService, IWorkContextAccessor workContextAccessor,
+ IMessageProviderService messageProviderService, IContextAccessor contextAccessor,
INewsletterCategoryService newsletterCategoryService)
{
_newsLetterSubscriptionService = newsLetterSubscriptionService;
_translationService = translationService;
_messageProviderService = messageProviderService;
- _workContextAccessor = workContextAccessor;
+ _contextAccessor = contextAccessor;
_newsletterCategoryService = newsletterCategoryService;
}
@@ -48,21 +48,21 @@ public class SubscribeNewsletterHandler : IRequestHandler<SubscribeNewsletterCom
var subscription =
await _newsLetterSubscriptionService.GetNewsLetterSubscriptionByEmailAndStoreId(email,
- _workContextAccessor.WorkContext.CurrentStore.Id);
+ _contextAccessor.StoreContext.CurrentStore.Id);
if (subscription != null)
{
if (request.Subscribe)
{
if (!subscription.Active)
await _messageProviderService.SendNewsLetterSubscriptionActivationMessage(subscription,
- _workContextAccessor.WorkContext.WorkingLanguage.Id);
+ _contextAccessor.WorkContext.WorkingLanguage.Id);
model.Result = _translationService.GetResource("Newsletter.SubscribeEmailSent");
}
else
{
if (subscription.Active)
await _messageProviderService.SendNewsLetterSubscriptionDeactivationMessage(subscription,
- _workContextAccessor.WorkContext.WorkingLanguage.Id);
+ _contextAccessor.WorkContext.WorkingLanguage.Id);
model.Result = _translationService.GetResource("Newsletter.UnsubscribeEmailSent");
}
}
@@ -71,14 +71,14 @@ public class SubscribeNewsletterHandler : IRequestHandler<SubscribeNewsletterCom
subscription = new NewsLetterSubscription {
NewsLetterSubscriptionGuid = Guid.NewGuid(),
Email = email,
- CustomerId = _workContextAccessor.WorkContext.CurrentCustomer.Id,
+ CustomerId = _contextAccessor.WorkContext.CurrentCustomer.Id,
Active = false,
- StoreId = _workContextAccessor.WorkContext.CurrentStore.Id
+ StoreId = _contextAccessor.StoreContext.CurrentStore.Id
};
await _newsLetterSubscriptionService.InsertNewsLetterSubscription(subscription);
await _messageProviderService.SendNewsLetterSubscriptionActivationMessage(subscription,
- _workContextAccessor.WorkContext.WorkingLanguage.Id);
+ _contextAccessor.WorkContext.WorkingLanguage.Id);
model.Result = _translationService.GetResource("Newsletter.SubscribeEmailSent");
var modelCategory = await PrepareNewsletterCategory(subscription.Id);
@@ -100,12 +100,12 @@ public class SubscribeNewsletterHandler : IRequestHandler<SubscribeNewsletterCom
var model = new NewsletterCategoryModel {
NewsletterEmailId = id
};
- var categories = await _newsletterCategoryService.GetNewsletterCategoriesByStore(_workContextAccessor.WorkContext.CurrentStore.Id);
+ var categories = await _newsletterCategoryService.GetNewsletterCategoriesByStore(_contextAccessor.StoreContext.CurrentStore.Id);
foreach (var item in categories)
model.NewsletterCategories.Add(new NewsletterSimpleCategory {
Id = item.Id,
- Name = item.GetTranslation(x => x.Name, _workContextAccessor.WorkContext.WorkingLanguage.Id),
- Description = item.GetTranslation(x => x.Description, _workContextAccessor.WorkContext.WorkingLanguage.Id),
+ Name = item.GetTranslation(x => x.Name, _contextAccessor.WorkContext.WorkingLanguage.Id),
+ Description = item.GetTranslation(x => x.Description, _contextAccessor.WorkContext.WorkingLanguage.Id),
Selected = item.Selected
});
return model;
diff --git a/src/Web/Grand.Web/Commands/Handler/Orders/MerchandiseReturnSubmitCommandHandler.cs b/src/Web/Grand.Web/Commands/Handler/Orders/MerchandiseReturnSubmitCommandHandler.cs
index 1c1d2dd3a..5413257d6 100644
--- a/src/Web/Grand.Web/Commands/Handler/Orders/MerchandiseReturnSubmitCommandHandler.cs
+++ b/src/Web/Grand.Web/Commands/Handler/Orders/MerchandiseReturnSubmitCommandHandler.cs
@@ -18,17 +18,17 @@ public class MerchandiseReturnSubmitCommandHandler : IRequestHandler<Merchandise
private readonly IMerchandiseReturnService _merchandiseReturnService;
private readonly IMessageProviderService _messageProviderService;
private readonly IProductService _productService;
- private readonly IWorkContextAccessor _workContextAccessor;
+ private readonly IContextAccessor _contextAccessor;
- public MerchandiseReturnSubmitCommandHandler(IWorkContextAccessor workContextAccessor,
+ public MerchandiseReturnSubmitCommandHandler(IContextAccessor contextAccessor,
IProductService productService,
IMerchandiseReturnService merchandiseReturnService,
IMessageProviderService messageProviderService,
IGroupService groupService,
LanguageSettings languageSettings)
{
- _workContextAccessor = workContextAccessor;
+ _contextAccessor = contextAccessor;
_productService = productService;
_merchandiseReturnService = merchandiseReturnService;
_messageProviderService = messageProviderService;
@@ -40,12 +40,12 @@ public class MerchandiseReturnSubmitCommandHandler : IRequestHandler<Merchandise
MerchandiseReturnSubmitCommand request, CancellationToken cancellationToken)
{
var rr = new MerchandiseReturn {
- StoreId = _workContextAccessor.WorkContext.CurrentStore.Id,
+ StoreId = _contextAccessor.StoreContext.CurrentStore.Id,
OrderId = request.Order.Id,
- CustomerId = _workContextAccessor.WorkContext.CurrentCustomer.Id,
- OwnerId = await _groupService.IsOwner(_workContextAccessor.WorkContext.CurrentCustomer)
- ? _workContextAccessor.WorkContext.CurrentCustomer.Id
- : _workContextAccessor.WorkContext.CurrentCustomer.OwnerId,
+ CustomerId = _contextAccessor.WorkContext.CurrentCustomer.Id,
+ OwnerId = await _groupService.IsOwner(_contextAccessor.WorkContext.CurrentCustomer)
+ ? _contextAccessor.WorkContext.CurrentCustomer.Id
+ : _contextAccessor.WorkContext.CurrentCustomer.OwnerId,
SeId = request.Order.SeId,
CustomerComments = request.Model.Comments,
StaffNotes = string.Empty,
@@ -71,10 +71,10 @@ public class MerchandiseReturnSubmitCommandHandler : IRequestHandler<Merchandise
var rra = await _merchandiseReturnService.GetMerchandiseReturnActionById(rraId);
rr.MerchandiseReturnItems.Add(new MerchandiseReturnItem {
RequestedAction = rra != null
- ? rra.GetTranslation(x => x.Name, _workContextAccessor.WorkContext.WorkingLanguage.Id)
+ ? rra.GetTranslation(x => x.Name, _contextAccessor.WorkContext.WorkingLanguage.Id)
: "not available",
ReasonForReturn = rrr != null
- ? rrr.GetTranslation(x => x.Name, _workContextAccessor.WorkContext.WorkingLanguage.Id)
+ ? rrr.GetTranslation(x => x.Name, _contextAccessor.WorkContext.WorkingLanguage.Id)
: "not available",
Quantity = quantity.Value,
OrderItemId = orderItem.Id
diff --git a/src/Web/Grand.Web/Commands/Handler/Vendors/ContactVendorCommandHandler.cs b/src/Web/Grand.Web/Commands/Handler/Vendors/ContactVendorCommandHandler.cs
index dcf97ca7c..4ad0d48fb 100644
--- a/src/Web/Grand.Web/Commands/Handler/Vendors/ContactVendorCommandHandler.cs
+++ b/src/Web/Grand.Web/Commands/Handler/Vendors/ContactVendorCommandHandler.cs
@@ -14,13 +14,13 @@ public class ContactVendorCommandHandler : IRequestHandler<ContactVendorSendComm
private readonly CommonSettings _commonSettings;
private readonly IMessageProviderService _messageProviderService;
private readonly ITranslationService _translationService;
- private readonly IWorkContextAccessor _workContextAccessor;
+ private readonly IContextAccessor _contextAccessor;
- public ContactVendorCommandHandler(IMessageProviderService messageProviderService, IWorkContextAccessor workContextAccessor,
+ public ContactVendorCommandHandler(IMessageProviderService messageProviderService, IContextAccessor contextAccessor,
ITranslationService translationService, CommonSettings commonSettings)
{
_messageProviderService = messageProviderService;
- _workContextAccessor = workContextAccessor;
+ _contextAccessor = contextAccessor;
_translationService = translationService;
_commonSettings = commonSettings;
}
@@ -30,8 +30,8 @@ public class ContactVendorCommandHandler : IRequestHandler<ContactVendorSendComm
var subject = _commonSettings.SubjectFieldOnContactUsForm ? request.Model.Subject : null;
var body = FormatText.ConvertText(request.Model.Enquiry);
- await _messageProviderService.SendContactVendorMessage(_workContextAccessor.WorkContext.CurrentCustomer, request.Store,
- request.Vendor, _workContextAccessor.WorkContext.WorkingLanguage.Id,
+ await _messageProviderService.SendContactVendorMessage(_contextAccessor.WorkContext.CurrentCustomer, request.Store,
+ request.Vendor, _contextAccessor.WorkContext.WorkingLanguage.Id,
request.Model.Email.Trim(), request.Model.FullName, subject, body, request.IpAddress);
request.Model.SuccessfullySent = true;
diff --git a/src/Web/Grand.Web/Commands/Handler/Vendors/InsertVendorReviewCommandHandler.cs b/src/Web/Grand.Web/Commands/Handler/Vendors/InsertVendorReviewCommandHandler.cs
index a6edeb7f0..24fe5189f 100644
--- a/src/Web/Grand.Web/Commands/Handler/Vendors/InsertVendorReviewCommandHandler.cs
+++ b/src/Web/Grand.Web/Commands/Handler/Vendors/InsertVendorReviewCommandHandler.cs
@@ -16,15 +16,15 @@ public class InsertVendorReviewCommandHandler : IRequestHandler<InsertVendorRevi
private readonly IMessageProviderService _messageProviderService;
private readonly IVendorService _vendorService;
private readonly VendorSettings _vendorSettings;
- private readonly IWorkContextAccessor _workContextAccessor;
+ private readonly IContextAccessor _contextAccessor;
- public InsertVendorReviewCommandHandler(IVendorService vendorService, IWorkContextAccessor workContextAccessor,
+ public InsertVendorReviewCommandHandler(IVendorService vendorService, IContextAccessor contextAccessor,
ICustomerService customerService, IMessageProviderService messageProviderService,
LanguageSettings languageSettings, VendorSettings vendorSettings)
{
_vendorService = vendorService;
- _workContextAccessor = workContextAccessor;
+ _contextAccessor = contextAccessor;
_customerService = customerService;
_messageProviderService = messageProviderService;
_languageSettings = languageSettings;
@@ -41,7 +41,7 @@ public class InsertVendorReviewCommandHandler : IRequestHandler<InsertVendorRevi
var vendorReview = new VendorReview {
VendorId = request.Vendor.Id,
- CustomerId = _workContextAccessor.WorkContext.CurrentCustomer.Id,
+ CustomerId = _contextAccessor.WorkContext.CurrentCustomer.Id,
Title = request.Model.AddVendorReview.Title,
ReviewText = request.Model.AddVendorReview.ReviewText,
Rating = rating,
@@ -51,8 +51,8 @@ public class InsertVendorReviewCommandHandler : IRequestHandler<InsertVendorRevi
};
await _vendorService.InsertVendorReview(vendorReview);
- if (!_workContextAccessor.WorkContext.CurrentCustomer.HasContributions)
- await _customerService.UpdateContributions(_workContextAccessor.WorkContext.CurrentCustomer);
+ if (!_contextAccessor.WorkContext.CurrentCustomer.HasContributions)
+ await _customerService.UpdateContributions(_contextAccessor.WorkContext.CurrentCustomer);
//update vendor totals
await _vendorService.UpdateVendorReviewTotals(request.Vendor);
diff --git a/src/Web/Grand.Web/Components/CategoryFeaturedProducts.cs b/src/Web/Grand.Web/Components/CategoryFeaturedProducts.cs
index 58c5f2f86..0c0313747 100644
--- a/src/Web/Grand.Web/Components/CategoryFeaturedProducts.cs
+++ b/src/Web/Grand.Web/Components/CategoryFeaturedProducts.cs
@@ -12,10 +12,10 @@ public class CategoryFeaturedProductsViewComponent : BaseViewComponent
public CategoryFeaturedProductsViewComponent(
IMediator mediator,
- IWorkContextAccessor workContextAccessor)
+ IContextAccessor contextAccessor)
{
_mediator = mediator;
- _workContextAccessor = workContextAccessor;
+ _contextAccessor = contextAccessor;
}
#endregion
@@ -25,9 +25,9 @@ public class CategoryFeaturedProductsViewComponent : BaseViewComponent
public async Task<IViewComponentResult> InvokeAsync()
{
var model = await _mediator.Send(new GetCategoryFeaturedProducts {
- Customer = _workContextAccessor.WorkContext.CurrentCustomer,
- Language = _workContextAccessor.WorkContext.WorkingLanguage,
- Store = _workContextAccessor.WorkContext.CurrentStore
+ Customer = _contextAccessor.WorkContext.CurrentCustomer,
+ Language = _contextAccessor.WorkContext.WorkingLanguage,
+ Store = _contextAccessor.StoreContext.CurrentStore
});
return !model.Any() ? Content("") : View(model);
@@ -38,7 +38,7 @@ public class CategoryFeaturedProductsViewComponent : BaseViewComponent
#region Fields
private readonly IMediator _mediator;
- private readonly IWorkContextAccessor _workContextAccessor;
+ private readonly IContextAccessor _contextAccessor;
#endregion
}
\ No newline at end of file
diff --git a/src/Web/Grand.Web/Components/CategoryNavigation.cs b/src/Web/Grand.Web/Components/CategoryNavigation.cs
index 67ed3e2c0..25060bdf3 100644
--- a/src/Web/Grand.Web/Components/CategoryNavigation.cs
+++ b/src/Web/Grand.Web/Components/CategoryNavigation.cs
@@ -9,22 +9,22 @@ namespace Grand.Web.Components;
public class CategoryNavigationViewComponent : BaseViewComponent
{
private readonly IMediator _mediator;
- private readonly IWorkContextAccessor _workContextAccessor;
+ private readonly IContextAccessor _contextAccessor;
public CategoryNavigationViewComponent(
IMediator mediator,
- IWorkContextAccessor workContextAccessor)
+ IContextAccessor contextAccessor)
{
_mediator = mediator;
- _workContextAccessor = workContextAccessor;
+ _contextAccessor = contextAccessor;
}
public async Task<IViewComponentResult> InvokeAsync(string currentCategoryId, string currentProductId)
{
var model = await _mediator.Send(new GetCategoryNavigation {
- Customer = _workContextAccessor.WorkContext.CurrentCustomer,
- Language = _workContextAccessor.WorkContext.WorkingLanguage,
- Store = _workContextAccessor.WorkContext.CurrentStore,
+ Customer = _contextAccessor.WorkContext.CurrentCustomer,
+ Language = _contextAccessor.WorkContext.WorkingLanguage,
+ Store = _contextAccessor.StoreContext.CurrentStore,
CurrentCategoryId = currentCategoryId,
CurrentProductId = currentProductId
});
diff --git a/src/Web/Grand.Web/Components/CollectionFeaturedProducts.cs b/src/Web/Grand.Web/Components/CollectionFeaturedProducts.cs
index 8cbef6572..f673bca78 100644
--- a/src/Web/Grand.Web/Components/CollectionFeaturedProducts.cs
+++ b/src/Web/Grand.Web/Components/CollectionFeaturedProducts.cs
@@ -10,10 +10,10 @@ public class CollectionFeaturedProductsViewComponent : BaseViewComponent
{
#region Constructors
- public CollectionFeaturedProductsViewComponent(IMediator mediator, IWorkContextAccessor workContextAccessor)
+ public CollectionFeaturedProductsViewComponent(IMediator mediator, IContextAccessor contextAccessor)
{
_mediator = mediator;
- _workContextAccessor = workContextAccessor;
+ _contextAccessor = contextAccessor;
}
#endregion
@@ -23,9 +23,9 @@ public class CollectionFeaturedProductsViewComponent : BaseViewComponent
public async Task<IViewComponentResult> InvokeAsync()
{
var model = await _mediator.Send(new GetCollectionFeaturedProducts {
- Customer = _workContextAccessor.WorkContext.CurrentCustomer,
- Language = _workContextAccessor.WorkContext.WorkingLanguage,
- Store = _workContextAccessor.WorkContext.CurrentStore
+ Customer = _contextAccessor.WorkContext.CurrentCustomer,
+ Language = _contextAccessor.WorkContext.WorkingLanguage,
+ Store = _contextAccessor.StoreContext.CurrentStore
});
return !model.Any() ? Content("") : View(model);
@@ -36,7 +36,7 @@ public class CollectionFeaturedProductsViewComponent : BaseViewComponent
#region Fields
private readonly IMediator _mediator;
- private readonly IWorkContextAccessor _workContextAccessor;
+ private readonly IContextAccessor _contextAccessor;
#endregion
}
\ No newline at end of file
diff --git a/src/Web/Grand.Web/Components/CollectionNavigation.cs b/src/Web/Grand.Web/Components/CollectionNavigation.cs
index 965737f76..834ddf046 100644
--- a/src/Web/Grand.Web/Components/CollectionNavigation.cs
+++ b/src/Web/Grand.Web/Components/CollectionNavigation.cs
@@ -11,15 +11,15 @@ public class CollectionNavigationViewComponent : BaseViewComponent
{
private readonly CatalogSettings _catalogSettings;
private readonly IMediator _mediator;
- private readonly IWorkContextAccessor _workContextAccessor;
+ private readonly IContextAccessor _contextAccessor;
public CollectionNavigationViewComponent(
IMediator mediator,
- IWorkContextAccessor workContextAccessor,
+ IContextAccessor contextAccessor,
CatalogSettings catalogSettings)
{
_mediator = mediator;
- _workContextAccessor = workContextAccessor;
+ _contextAccessor = contextAccessor;
_catalogSettings = catalogSettings;
}
@@ -30,9 +30,9 @@ public class CollectionNavigationViewComponent : BaseViewComponent
var model = await _mediator.Send(new GetCollectionNavigation {
CurrentCollectionId = currentCollectionId,
- Customer = _workContextAccessor.WorkContext.CurrentCustomer,
- Language = _workContextAccessor.WorkContext.WorkingLanguage,
- Store = _workContextAccessor.WorkContext.CurrentStore
+ Customer = _contextAccessor.WorkContext.CurrentCustomer,
+ Language = _contextAccessor.WorkContext.WorkingLanguage,
+ Store = _contextAccessor.StoreContext.CurrentStore
});
return !model.Collections.Any() ? Content("") : View(model);
diff --git a/src/Web/Grand.Web/Components/CrossSellProducts.cs b/src/Web/Grand.Web/Components/CrossSellProducts.cs
index a8dd15cf9..529449782 100644
--- a/src/Web/Grand.Web/Components/CrossSellProducts.cs
+++ b/src/Web/Grand.Web/Components/CrossSellProducts.cs
@@ -15,13 +15,13 @@ public class CrossSellProductsViewComponent : BaseViewComponent
public CrossSellProductsViewComponent(
IProductService productService,
- IWorkContextAccessor workContextAccessor,
+ IContextAccessor contextAccessor,
IMediator mediator,
CatalogSettings catalogSettings,
ShoppingCartSettings shoppingCartSettings)
{
_productService = productService;
- _workContextAccessor = workContextAccessor;
+ _contextAccessor = contextAccessor;
_mediator = mediator;
_catalogSettings = catalogSettings;
_shoppingCartSettings = shoppingCartSettings;
@@ -36,9 +36,9 @@ public class CrossSellProductsViewComponent : BaseViewComponent
if (_shoppingCartSettings.CrossSellsNumber == 0)
return Content("");
- var cart = _workContextAccessor.WorkContext.CurrentCustomer.ShoppingCartItems
+ var cart = _contextAccessor.WorkContext.CurrentCustomer.ShoppingCartItems
.Where(sci => sci.ShoppingCartTypeId == ShoppingCartType.ShoppingCart)
- .LimitPerStore(_shoppingCartSettings.SharedCartBetweenStores, _workContextAccessor.WorkContext.CurrentStore.Id)
+ .LimitPerStore(_shoppingCartSettings.SharedCartBetweenStores, _contextAccessor.StoreContext.CurrentStore.Id)
.ToList();
var products =
@@ -62,7 +62,7 @@ public class CrossSellProductsViewComponent : BaseViewComponent
#region Fields
private readonly IProductService _productService;
- private readonly IWorkContextAccessor _workContextAccessor;
+ private readonly IContextAccessor _contextAccessor;
private readonly IMediator _mediator;
private readonly CatalogSettings _catalogSettings;
diff --git a/src/Web/Grand.Web/Components/CustomerNavigation.cs b/src/Web/Grand.Web/Components/CustomerNavigation.cs
index 8e908dbf7..be55f32c0 100644
--- a/src/Web/Grand.Web/Components/CustomerNavigation.cs
+++ b/src/Web/Grand.Web/Components/CustomerNavigation.cs
@@ -9,23 +9,23 @@ namespace Grand.Web.Components;
public class CustomerNavigationViewComponent : BaseViewComponent
{
private readonly IMediator _mediator;
- private readonly IWorkContextAccessor _workContextAccessor;
+ private readonly IContextAccessor _contextAccessor;
public CustomerNavigationViewComponent(IMediator mediator,
- IWorkContextAccessor workContextAccessor)
+ IContextAccessor contextAccessor)
{
_mediator = mediator;
- _workContextAccessor = workContextAccessor;
+ _contextAccessor = contextAccessor;
}
public async Task<IViewComponentResult> InvokeAsync(int selectedTabId = 0)
{
var model = await _mediator.Send(new GetNavigation {
- Customer = _workContextAccessor.WorkContext.CurrentCustomer,
- Language = _workContextAccessor.WorkContext.WorkingLanguage,
+ Customer = _contextAccessor.WorkContext.CurrentCustomer,
+ Language = _contextAccessor.WorkContext.WorkingLanguage,
SelectedTabId = selectedTabId,
- Store = _workContextAccessor.WorkContext.CurrentStore,
- Vendor = _workContextAccessor.WorkContext.CurrentVendor
+ Store = _contextAccessor.StoreContext.CurrentStore,
+ Vendor = _contextAccessor.WorkContext.CurrentVendor
});
return View(model);
}
diff --git a/src/Web/Grand.Web/Components/CustomerRecommendedProducts.cs b/src/Web/Grand.Web/Components/CustomerRecommendedProducts.cs
index 7c5e07db0..ead1f492b 100644
--- a/src/Web/Grand.Web/Components/CustomerRecommendedProducts.cs
+++ b/src/Web/Grand.Web/Components/CustomerRecommendedProducts.cs
@@ -14,11 +14,11 @@ public class CustomerRecommendedProductsViewComponent : BaseViewComponent
#region Constructors
public CustomerRecommendedProductsViewComponent(
- IWorkContextAccessor workContextAccessor,
+ IContextAccessor contextAccessor,
IMediator mediator,
CatalogSettings catalogSettings)
{
- _workContextAccessor = workContextAccessor;
+ _contextAccessor = contextAccessor;
_mediator = mediator;
_catalogSettings = catalogSettings;
}
@@ -33,8 +33,8 @@ public class CustomerRecommendedProductsViewComponent : BaseViewComponent
return Content("");
var products = await _mediator.Send(new GetRecommendedProductsQuery {
- CustomerGroupIds = _workContextAccessor.WorkContext.CurrentCustomer.GetCustomerGroupIds(),
- StoreId = _workContextAccessor.WorkContext.CurrentStore.Id
+ CustomerGroupIds = _contextAccessor.WorkContext.CurrentCustomer.GetCustomerGroupIds(),
+ StoreId = _contextAccessor.StoreContext.CurrentStore.Id
});
if (!products.Any())
@@ -54,7 +54,7 @@ public class CustomerRecommendedProductsViewComponent : BaseViewComponent
#region Fields
- private readonly IWorkContextAccessor _workContextAccessor;
+ private readonly IContextAccessor _contextAccessor;
private readonly IMediator _mediator;
private readonly CatalogSettings _catalogSettings;
diff --git a/src/Web/Grand.Web/Components/EmailWishlist.cs b/src/Web/Grand.Web/Components/EmailWishlist.cs
index 5b3ec74b1..47dfd2ec2 100644
--- a/src/Web/Grand.Web/Components/EmailWishlist.cs
+++ b/src/Web/Grand.Web/Components/EmailWishlist.cs
@@ -16,17 +16,17 @@ public class EmailWishlistViewComponent : BaseViewComponent
private readonly IPermissionService _permissionService;
private readonly IShoppingCartService _shoppingCartService;
private readonly ShoppingCartSettings _shoppingCartSettings;
- private readonly IWorkContextAccessor _workContextAccessor;
+ private readonly IContextAccessor _contextAccessor;
public EmailWishlistViewComponent(
- IWorkContextAccessor workContextAccessor,
+ IContextAccessor contextAccessor,
IShoppingCartService shoppingCartService,
IPermissionService permissionService,
ShoppingCartSettings shoppingCartSettings,
CaptchaSettings captchaSettings
)
{
- _workContextAccessor = workContextAccessor;
+ _contextAccessor = contextAccessor;
_shoppingCartService = shoppingCartService;
_permissionService = permissionService;
_shoppingCartSettings = shoppingCartSettings;
@@ -39,13 +39,13 @@ public class EmailWishlistViewComponent : BaseViewComponent
!_shoppingCartSettings.EmailWishlistEnabled)
return Content("");
- var cart = await _shoppingCartService.GetShoppingCart(_workContextAccessor.WorkContext.CurrentStore.Id, ShoppingCartType.Wishlist);
+ var cart = await _shoppingCartService.GetShoppingCart(_contextAccessor.StoreContext.CurrentStore.Id, ShoppingCartType.Wishlist);
if (!cart.Any())
return Content("");
var model = new WishlistEmailAFriendModel {
- YourEmailAddress = _workContextAccessor.WorkContext.CurrentCustomer.Email,
+ YourEmailAddress = _contextAccessor.WorkContext.CurrentCustomer.Email,
DisplayCaptcha = _captchaSettings.Enabled && _captchaSettings.ShowOnEmailWishlistToFriendPage
};
return View(model);
diff --git a/src/Web/Grand.Web/Components/EstimateShipping.cs b/src/Web/Grand.Web/Components/EstimateShipping.cs
index 8ae17e048..882fad957 100644
--- a/src/Web/Grand.Web/Components/EstimateShipping.cs
+++ b/src/Web/Grand.Web/Components/EstimateShipping.cs
@@ -12,27 +12,27 @@ public class EstimateShippingViewComponent : BaseViewComponent
{
private readonly IMediator _mediator;
private readonly IShoppingCartService _shoppingCartService;
- private readonly IWorkContextAccessor _workContextAccessor;
+ private readonly IContextAccessor _contextAccessor;
public EstimateShippingViewComponent(IMediator mediator, IShoppingCartService shoppingCartService,
- IWorkContextAccessor workContextAccessor)
+ IContextAccessor contextAccessor)
{
_mediator = mediator;
_shoppingCartService = shoppingCartService;
- _workContextAccessor = workContextAccessor;
+ _contextAccessor = contextAccessor;
}
public async Task<IViewComponentResult> InvokeAsync()
{
- var cart = await _shoppingCartService.GetShoppingCart(_workContextAccessor.WorkContext.CurrentStore.Id,
+ var cart = await _shoppingCartService.GetShoppingCart(_contextAccessor.StoreContext.CurrentStore.Id,
ShoppingCartType.ShoppingCart);
var model = await _mediator.Send(new GetEstimateShipping {
Cart = cart,
- Currency = _workContextAccessor.WorkContext.WorkingCurrency,
- Customer = _workContextAccessor.WorkContext.CurrentCustomer,
- Language = _workContextAccessor.WorkContext.WorkingLanguage,
- Store = _workContextAccessor.WorkContext.CurrentStore
+ Currency = _contextAccessor.WorkContext.WorkingCurrency,
+ Customer = _contextAccessor.WorkContext.CurrentCustomer,
+ Language = _contextAccessor.WorkContext.WorkingLanguage,
+ Store = _contextAccessor.StoreContext.CurrentStore
});
return !model.Enabled ? Content("") : View(model);
}
diff --git a/src/Web/Grand.Web/Components/ExternalMethods.cs b/src/Web/Grand.Web/Components/ExternalMethods.cs
index 663123ca4..02c08cd4b 100644
--- a/src/Web/Grand.Web/Components/ExternalMethods.cs
+++ b/src/Web/Grand.Web/Components/ExternalMethods.cs
@@ -9,20 +9,20 @@ namespace Grand.Web.Components;
public class ExternalMethodsViewComponent : BaseViewComponent
{
private readonly IExternalAuthenticationService _externalAuthenticationService;
- private readonly IWorkContextAccessor _workContextAccessor;
+ private readonly IContextAccessor _contextAccessor;
public ExternalMethodsViewComponent(
IExternalAuthenticationService externalAuthenticationService,
- IWorkContextAccessor workContextAccessor)
+ IContextAccessor contextAccessor)
{
_externalAuthenticationService = externalAuthenticationService;
- _workContextAccessor = workContextAccessor;
+ _contextAccessor = contextAccessor;
}
public async Task<IViewComponentResult> InvokeAsync()
{
var models = _externalAuthenticationService
- .LoadActiveAuthenticationProviders(_workContextAccessor.WorkContext.CurrentCustomer, _workContextAccessor.WorkContext.CurrentStore);
+ .LoadActiveAuthenticationProviders(_contextAccessor.WorkContext.CurrentCustomer, _contextAccessor.StoreContext.CurrentStore);
var model = new List<ExternalAuthenticationMethodModel>();
foreach (var item in models)
diff --git a/src/Web/Grand.Web/Components/Footer.cs b/src/Web/Grand.Web/Components/Footer.cs
index c2b4bf72a..442e78991 100644
--- a/src/Web/Grand.Web/Components/Footer.cs
+++ b/src/Web/Grand.Web/Components/Footer.cs
@@ -29,10 +29,10 @@ public class FooterViewComponent : BaseViewComponent
private readonly StoreInformationSettings _storeInformationSettings;
private readonly VendorSettings _vendorSettings;
- private readonly IWorkContextAccessor _workContextAccessor;
+ private readonly IContextAccessor _contextAccessor;
public FooterViewComponent(
- IWorkContextAccessor workContextAccessor,
+ IContextAccessor contextAccessor,
IPageService pageService,
IPermissionService permissionService,
StoreInformationSettings storeInformationSettings,
@@ -43,7 +43,7 @@ public class FooterViewComponent : BaseViewComponent
VendorSettings vendorSettings,
CommonSettings commonSettings)
{
- _workContextAccessor = workContextAccessor;
+ _contextAccessor = contextAccessor;
_pageService = pageService;
_permissionService = permissionService;
@@ -65,23 +65,23 @@ public class FooterViewComponent : BaseViewComponent
private async Task<FooterModel> PrepareFooter()
{
var now = DateTime.UtcNow;
- var pageModel = (await _pageService.GetAllPages(_workContextAccessor.WorkContext.CurrentStore.Id))
+ var pageModel = (await _pageService.GetAllPages(_contextAccessor.StoreContext.CurrentStore.Id))
.Where(t => (t.IncludeInFooterRow1 || t.IncludeInFooterRow2 || t.IncludeInFooterRow3) && t.Published &&
(!t.StartDateUtc.HasValue || t.StartDateUtc < now) &&
(!t.EndDateUtc.HasValue || t.EndDateUtc > now))
.Select(t => new FooterModel.FooterPageModel {
Id = t.Id,
- Name = t.GetTranslation(x => x.Title, _workContextAccessor.WorkContext.WorkingLanguage.Id),
- SeName = t.GetSeName(_workContextAccessor.WorkContext.WorkingLanguage.Id),
+ Name = t.GetTranslation(x => x.Title, _contextAccessor.WorkContext.WorkingLanguage.Id),
+ SeName = t.GetSeName(_contextAccessor.WorkContext.WorkingLanguage.Id),
IncludeInFooterRow1 = t.IncludeInFooterRow1,
IncludeInFooterRow2 = t.IncludeInFooterRow2,
IncludeInFooterRow3 = t.IncludeInFooterRow3
}).ToList();
//model
- var currentstore = _workContextAccessor.WorkContext.CurrentStore;
+ var currentstore = _contextAccessor.StoreContext.CurrentStore;
var model = new FooterModel {
- StoreName = currentstore.GetTranslation(x => x.Name, _workContextAccessor.WorkContext.WorkingLanguage.Id),
+ StoreName = currentstore.GetTranslation(x => x.Name, _contextAccessor.WorkContext.WorkingLanguage.Id),
CompanyName = currentstore.CompanyName,
CompanyEmail = currentstore.CompanyEmail,
CompanyAddress = currentstore.CompanyAddress,
@@ -91,7 +91,7 @@ public class FooterViewComponent : BaseViewComponent
WishlistEnabled = await _permissionService.Authorize(StandardPermission.EnableWishlist),
ShoppingCartEnabled = await _permissionService.Authorize(StandardPermission.EnableShoppingCart),
SitemapEnabled = _commonSettings.SitemapEnabled,
- WorkingLanguageId = _workContextAccessor.WorkContext.WorkingLanguage.Id,
+ WorkingLanguageId = _contextAccessor.WorkContext.WorkingLanguage.Id,
FacebookLink = _storeInformationSettings.FacebookLink,
TwitterLink = _storeInformationSettings.TwitterLink,
YoutubeLink = _storeInformationSettings.YoutubeLink,
@@ -104,7 +104,7 @@ public class FooterViewComponent : BaseViewComponent
RecentlyViewedProductsEnabled = _catalogSettings.RecentlyViewedProductsEnabled,
RecommendedProductsEnabled = _catalogSettings.RecommendedProductsEnabled,
NewProductsEnabled = _catalogSettings.NewProductsEnabled,
- InclTax = _workContextAccessor.WorkContext.TaxDisplayType == TaxDisplayType.IncludingTax,
+ InclTax = _contextAccessor.WorkContext.TaxDisplayType == TaxDisplayType.IncludingTax,
AllowCustomersToApplyForVendorAccount = _vendorSettings.AllowCustomersToApplyForVendorAccount,
Pages = pageModel
};
diff --git a/src/Web/Grand.Web/Components/GetCoordinate.cs b/src/Web/Grand.Web/Components/GetCoordinate.cs
index 88ef6254a..a7bf21692 100644
--- a/src/Web/Grand.Web/Components/GetCoordinate.cs
+++ b/src/Web/Grand.Web/Components/GetCoordinate.cs
@@ -9,12 +9,12 @@ namespace Grand.Web.Components;
public class GetCoordinateViewComponent : BaseViewComponent
{
private readonly CustomerSettings _customerSettings;
- private readonly IWorkContextAccessor _workContextAccessor;
+ private readonly IContextAccessor _contextAccessor;
- public GetCoordinateViewComponent(CustomerSettings customerSettings, IWorkContextAccessor workContextAccessor)
+ public GetCoordinateViewComponent(CustomerSettings customerSettings, IContextAccessor contextAccessor)
{
_customerSettings = customerSettings;
- _workContextAccessor = workContextAccessor;
+ _contextAccessor = contextAccessor;
}
public IViewComponentResult Invoke()
@@ -22,12 +22,12 @@ public class GetCoordinateViewComponent : BaseViewComponent
if (!_customerSettings.GeoEnabled)
return Content("");
- if (_workContextAccessor.WorkContext.CurrentCustomer.Coordinates == null)
+ if (_contextAccessor.WorkContext.CurrentCustomer.Coordinates == null)
return View(new LocationModel());
var model = new LocationModel {
- Longitude = _workContextAccessor.WorkContext.CurrentCustomer.Coordinates.X,
- Latitude = _workContextAccessor.WorkContext.CurrentCustomer.Coordinates.Y
+ Longitude = _contextAccessor.WorkContext.CurrentCustomer.Coordinates.X,
+ Latitude = _contextAccessor.WorkContext.CurrentCustomer.Coordinates.Y
};
return View(model);
}
diff --git a/src/Web/Grand.Web/Components/HomePageBestSellers.cs b/src/Web/Grand.Web/Components/HomePageBestSellers.cs
index 8d7fb846e..faf8abc38 100644
--- a/src/Web/Grand.Web/Components/HomePageBestSellers.cs
+++ b/src/Web/Grand.Web/Components/HomePageBestSellers.cs
@@ -19,14 +19,14 @@ public class HomePageBestSellersViewComponent : BaseViewComponent
public HomePageBestSellersViewComponent(
IOrderReportService orderReportService,
ICacheBase cacheBase,
- IWorkContextAccessor workContextAccessor,
+ IContextAccessor contextAccessor,
IProductService productService,
IMediator mediator,
CatalogSettings catalogSettings)
{
_orderReportService = orderReportService;
_cacheBase = cacheBase;
- _workContextAccessor = workContextAccessor;
+ _contextAccessor = contextAccessor;
_productService = productService;
_mediator = mediator;
_catalogSettings = catalogSettings;
@@ -50,11 +50,11 @@ public class HomePageBestSellersViewComponent : BaseViewComponent
? -_catalogSettings.PeriodBestsellers
: -12);
var report = await _cacheBase.GetAsync(
- string.Format(CacheKeyConst.HOMEPAGE_BESTSELLERS_IDS_KEY, _workContextAccessor.WorkContext.CurrentStore.Id), async () =>
+ string.Format(CacheKeyConst.HOMEPAGE_BESTSELLERS_IDS_KEY, _contextAccessor.StoreContext.CurrentStore.Id), async () =>
await _orderReportService.BestSellersReport(
createdFromUtc: fromdate,
ps: PaymentStatus.Paid,
- storeId: _workContextAccessor.WorkContext.CurrentStore.Id,
+ storeId: _contextAccessor.StoreContext.CurrentStore.Id,
pageSize: _catalogSettings.NumberOfBestsellersOnHomepage));
productIds = report.Select(x => x.ProductId).ToList();
@@ -85,7 +85,7 @@ public class HomePageBestSellersViewComponent : BaseViewComponent
private readonly IOrderReportService _orderReportService;
private readonly ICacheBase _cacheBase;
- private readonly IWorkContextAccessor _workContextAccessor;
+ private readonly IContextAccessor _contextAccessor;
private readonly IProductService _productService;
private readonly IMediator _mediator;
diff --git a/src/Web/Grand.Web/Components/HomePageBrands.cs b/src/Web/Grand.Web/Components/HomePageBrands.cs
index 1cf269c00..acef2075a 100644
--- a/src/Web/Grand.Web/Components/HomePageBrands.cs
+++ b/src/Web/Grand.Web/Components/HomePageBrands.cs
@@ -9,22 +9,22 @@ namespace Grand.Web.Components;
public class HomePageBrandsViewComponent : BaseViewComponent
{
private readonly IMediator _mediator;
- private readonly IWorkContextAccessor _workContextAccessor;
+ private readonly IContextAccessor _contextAccessor;
public HomePageBrandsViewComponent(
IMediator mediator,
- IWorkContextAccessor workContextAccessor)
+ IContextAccessor contextAccessor)
{
_mediator = mediator;
- _workContextAccessor = workContextAccessor;
+ _contextAccessor = contextAccessor;
}
public async Task<IViewComponentResult> InvokeAsync()
{
var model = await _mediator.Send(new GetHomepageBrands {
- Customer = _workContextAccessor.WorkContext.CurrentCustomer,
- Language = _workContextAccessor.WorkContext.WorkingLanguage,
- Store = _workContextAccessor.WorkContext.CurrentStore
+ Customer = _contextAccessor.WorkContext.CurrentCustomer,
+ Language = _contextAccessor.WorkContext.WorkingLanguage,
+ Store = _contextAccessor.StoreContext.CurrentStore
});
return !model.Any() ? Content("") : View(model);
diff --git a/src/Web/Grand.Web/Components/HomePageCategories.cs b/src/Web/Grand.Web/Components/HomePageCategories.cs
index 16e4b251b..753a4a525 100644
--- a/src/Web/Grand.Web/Components/HomePageCategories.cs
+++ b/src/Web/Grand.Web/Components/HomePageCategories.cs
@@ -12,10 +12,10 @@ public class HomePageCategoriesViewComponent : BaseViewComponent
public HomePageCategoriesViewComponent(
IMediator mediator,
- IWorkContextAccessor workContextAccessor)
+ IContextAccessor contextAccessor)
{
_mediator = mediator;
- _workContextAccessor = workContextAccessor;
+ _contextAccessor = contextAccessor;
}
#endregion
@@ -25,9 +25,9 @@ public class HomePageCategoriesViewComponent : BaseViewComponent
public async Task<IViewComponentResult> InvokeAsync()
{
var model = await _mediator.Send(new GetHomepageCategory {
- Customer = _workContextAccessor.WorkContext.CurrentCustomer,
- Language = _workContextAccessor.WorkContext.WorkingLanguage,
- Store = _workContextAccessor.WorkContext.CurrentStore
+ Customer = _contextAccessor.WorkContext.CurrentCustomer,
+ Language = _contextAccessor.WorkContext.WorkingLanguage,
+ Store = _contextAccessor.StoreContext.CurrentStore
});
return !model.Any() ? Content("") : View(model);
@@ -38,7 +38,7 @@ public class HomePageCategoriesViewComponent : BaseViewComponent
#region Fields
private readonly IMediator _mediator;
- private readonly IWorkContextAccessor _workContextAccessor;
+ private readonly IContextAccessor _contextAccessor;
#endregion
}
\ No newline at end of file
diff --git a/src/Web/Grand.Web/Components/HomePageCollections.cs b/src/Web/Grand.Web/Components/HomePageCollections.cs
index a300f6092..3d53f13b7 100644
--- a/src/Web/Grand.Web/Components/HomePageCollections.cs
+++ b/src/Web/Grand.Web/Components/HomePageCollections.cs
@@ -9,22 +9,22 @@ namespace Grand.Web.Components;
public class HomePageCollectionsViewComponent : BaseViewComponent
{
private readonly IMediator _mediator;
- private readonly IWorkContextAccessor _workContextAccessor;
+ private readonly IContextAccessor _contextAccessor;
public HomePageCollectionsViewComponent(
IMediator mediator,
- IWorkContextAccessor workContextAccessor)
+ IContextAccessor contextAccessor)
{
_mediator = mediator;
- _workContextAccessor = workContextAccessor;
+ _contextAccessor = contextAccessor;
}
public async Task<IViewComponentResult> InvokeAsync()
{
var model = await _mediator.Send(new GetHomepageCollections {
- Customer = _workContextAccessor.WorkContext.CurrentCustomer,
- Language = _workContextAccessor.WorkContext.WorkingLanguage,
- Store = _workContextAccessor.WorkContext.CurrentStore
+ Customer = _contextAccessor.WorkContext.CurrentCustomer,
+ Language = _contextAccessor.WorkContext.WorkingLanguage,
+ Store = _contextAccessor.StoreContext.CurrentStore
});
return !model.Any() ? Content("") : View(model);
diff --git a/src/Web/Grand.Web/Components/HomePageNewProducts.cs b/src/Web/Grand.Web/Components/HomePageNewProducts.cs
index 3399fc557..bb447cc3a 100644
--- a/src/Web/Grand.Web/Components/HomePageNewProducts.cs
+++ b/src/Web/Grand.Web/Components/HomePageNewProducts.cs
@@ -13,11 +13,11 @@ public class HomePageNewProductsViewComponent : BaseViewComponent
#region Constructors
public HomePageNewProductsViewComponent(
- IWorkContextAccessor workContextAccessor,
+ IContextAccessor contextAccessor,
IMediator mediator,
CatalogSettings catalogSettings)
{
- _workContextAccessor = workContextAccessor;
+ _contextAccessor = contextAccessor;
_mediator = mediator;
_catalogSettings = catalogSettings;
}
@@ -32,8 +32,8 @@ public class HomePageNewProductsViewComponent : BaseViewComponent
return Content("");
var products = (await _mediator.Send(new GetSearchProductsQuery {
- Customer = _workContextAccessor.WorkContext.CurrentCustomer,
- StoreId = _workContextAccessor.WorkContext.CurrentStore.Id,
+ Customer = _contextAccessor.WorkContext.CurrentCustomer,
+ StoreId = _contextAccessor.StoreContext.CurrentStore.Id,
VisibleIndividuallyOnly = true,
MarkedAsNewOnly = true,
OrderBy = ProductSortingEnum.CreatedOn,
@@ -58,7 +58,7 @@ public class HomePageNewProductsViewComponent : BaseViewComponent
#region Fields
- private readonly IWorkContextAccessor _workContextAccessor;
+ private readonly IContextAccessor _contextAccessor;
private readonly IMediator _mediator;
private readonly CatalogSettings _catalogSettings;
diff --git a/src/Web/Grand.Web/Components/KnowledgebaseCategories.cs b/src/Web/Grand.Web/Components/KnowledgebaseCategories.cs
index d411e2528..9025ea9b2 100644
--- a/src/Web/Grand.Web/Components/KnowledgebaseCategories.cs
+++ b/src/Web/Grand.Web/Components/KnowledgebaseCategories.cs
@@ -12,13 +12,13 @@ public class KnowledgebaseCategories : BaseViewComponent
{
private readonly IKnowledgebaseService _knowledgebaseService;
private readonly KnowledgebaseSettings _knowledgebaseSettings;
- private readonly IWorkContextAccessor _workContextAccessor;
+ private readonly IContextAccessor _contextAccessor;
- public KnowledgebaseCategories(IKnowledgebaseService knowledgebaseService, IWorkContextAccessor workContextAccessor,
+ public KnowledgebaseCategories(IKnowledgebaseService knowledgebaseService, IContextAccessor contextAccessor,
KnowledgebaseSettings knowledgebaseSettings)
{
_knowledgebaseService = knowledgebaseService;
- _workContextAccessor = workContextAccessor;
+ _contextAccessor = contextAccessor;
_knowledgebaseSettings = knowledgebaseSettings;
}
@@ -34,10 +34,10 @@ public class KnowledgebaseCategories : BaseViewComponent
if (!string.IsNullOrEmpty(category.ParentCategoryId)) continue;
var newNode = new KnowledgebaseCategoryModel {
Id = category.Id,
- Name = category.GetTranslation(y => y.Name, _workContextAccessor.WorkContext.WorkingLanguage.Id),
+ Name = category.GetTranslation(y => y.Name, _contextAccessor.WorkContext.WorkingLanguage.Id),
Children = new List<KnowledgebaseCategoryModel>(),
IsCurrent = model.CurrentCategoryId == category.Id,
- SeName = category.GetTranslation(y => y.SeName, _workContextAccessor.WorkContext.WorkingLanguage.Id)
+ SeName = category.GetTranslation(y => y.SeName, _contextAccessor.WorkContext.WorkingLanguage.Id)
};
FillChildNodes(newNode, categories, model.CurrentCategoryId);
@@ -56,10 +56,10 @@ public class KnowledgebaseCategories : BaseViewComponent
{
var newNode = new KnowledgebaseCategoryModel {
Id = child.Id,
- Name = child.GetTranslation(y => y.Name, _workContextAccessor.WorkContext.WorkingLanguage.Id),
+ Name = child.GetTranslation(y => y.Name, _contextAccessor.WorkContext.WorkingLanguage.Id),
Children = new List<KnowledgebaseCategoryModel>(),
IsCurrent = currentCategoryId == child.Id,
- SeName = child.GetTranslation(y => y.SeName, _workContextAccessor.WorkContext.WorkingLanguage.Id),
+ SeName = child.GetTranslation(y => y.SeName, _contextAccessor.WorkContext.WorkingLanguage.Id),
Parent = parentNode
};
diff --git a/src/Web/Grand.Web/Components/KnowledgebaseHomepageArticles.cs b/src/Web/Grand.Web/Components/KnowledgebaseHomepageArticles.cs
index 7ff28b13e..e28b1a975 100644
--- a/src/Web/Grand.Web/Components/KnowledgebaseHomepageArticles.cs
+++ b/src/Web/Grand.Web/Components/KnowledgebaseHomepageArticles.cs
@@ -12,13 +12,13 @@ public class KnowledgebaseHomepageArticles : BaseViewComponent
{
private readonly IKnowledgebaseService _knowledgebaseService;
private readonly KnowledgebaseSettings _knowledgebaseSettings;
- private readonly IWorkContextAccessor _workContextAccessor;
+ private readonly IContextAccessor _contextAccessor;
- public KnowledgebaseHomepageArticles(IKnowledgebaseService knowledgebaseService, IWorkContextAccessor workContextAccessor,
+ public KnowledgebaseHomepageArticles(IKnowledgebaseService knowledgebaseService, IContextAccessor contextAccessor,
KnowledgebaseSettings knowledgebaseSettings)
{
_knowledgebaseService = knowledgebaseService;
- _workContextAccessor = workContextAccessor;
+ _contextAccessor = contextAccessor;
_knowledgebaseSettings = knowledgebaseSettings;
}
@@ -33,8 +33,8 @@ public class KnowledgebaseHomepageArticles : BaseViewComponent
{
var a = new KnowledgebaseItemModel {
Id = article.Id,
- Name = article.GetTranslation(y => y.Name, _workContextAccessor.WorkContext.WorkingLanguage.Id),
- SeName = article.GetTranslation(y => y.SeName, _workContextAccessor.WorkContext.WorkingLanguage.Id),
+ Name = article.GetTranslation(y => y.Name, _contextAccessor.WorkContext.WorkingLanguage.Id),
+ SeName = article.GetTranslation(y => y.SeName, _contextAccessor.WorkContext.WorkingLanguage.Id),
IsArticle = true
};
diff --git a/src/Web/Grand.Web/Components/Menu.cs b/src/Web/Grand.Web/Components/Menu.cs
index 62d01fe4c..31c435c5f 100644
--- a/src/Web/Grand.Web/Components/Menu.cs
+++ b/src/Web/Grand.Web/Components/Menu.cs
@@ -12,28 +12,28 @@ public class MenuViewComponent : BaseViewComponent
{
private readonly IMediator _mediator;
private readonly IPermissionService _permissionService;
- private readonly IWorkContextAccessor _workContextAccessor;
+ private readonly IContextAccessor _contextAccessor;
public MenuViewComponent(
IMediator mediator,
- IWorkContextAccessor workContextAccessor,
+ IContextAccessor contextAccessor,
IPermissionService permissionService)
{
_mediator = mediator;
- _workContextAccessor = workContextAccessor;
+ _contextAccessor = contextAccessor;
_permissionService = permissionService;
}
public async Task<IViewComponentResult> InvokeAsync()
{
if (!await _permissionService.Authorize(StandardPermission.PublicStoreAllowNavigation,
- _workContextAccessor.WorkContext.CurrentCustomer))
+ _contextAccessor.WorkContext.CurrentCustomer))
return Content("");
var model = await _mediator.Send(new GetMenu {
- Customer = _workContextAccessor.WorkContext.CurrentCustomer,
- Language = _workContextAccessor.WorkContext.WorkingLanguage,
- Store = _workContextAccessor.WorkContext.CurrentStore
+ Customer = _contextAccessor.WorkContext.CurrentCustomer,
+ Language = _contextAccessor.WorkContext.WorkingLanguage,
+ Store = _contextAccessor.StoreContext.CurrentStore
});
return View(model);
diff --git a/src/Web/Grand.Web/Components/PersonalizedProducts.cs b/src/Web/Grand.Web/Components/PersonalizedProducts.cs
index 17e314b77..81f9e5da0 100644
--- a/src/Web/Grand.Web/Components/PersonalizedProducts.cs
+++ b/src/Web/Grand.Web/Components/PersonalizedProducts.cs
@@ -13,11 +13,11 @@ public class PersonalizedProductsViewComponent : BaseViewComponent
#region Constructors
public PersonalizedProductsViewComponent(
- IWorkContextAccessor workContextAccessor,
+ IContextAccessor contextAccessor,
IMediator mediator,
CatalogSettings catalogSettings)
{
- _workContextAccessor = workContextAccessor;
+ _contextAccessor = contextAccessor;
_mediator = mediator;
_catalogSettings = catalogSettings;
}
@@ -32,7 +32,7 @@ public class PersonalizedProductsViewComponent : BaseViewComponent
return Content("");
var products = await _mediator.Send(new GetPersonalizedProductsQuery {
- CustomerId = _workContextAccessor.WorkContext.CurrentCustomer.Id, ProductsNumber = _catalogSettings.PersonalizedProductsNumber
+ CustomerId = _contextAccessor.WorkContext.CurrentCustomer.Id, ProductsNumber = _catalogSettings.PersonalizedProductsNumber
});
if (!products.Any())
@@ -52,7 +52,7 @@ public class PersonalizedProductsViewComponent : BaseViewComponent
#region Fields
- private readonly IWorkContextAccessor _workContextAccessor;
+ private readonly IContextAccessor _contextAccessor;
private readonly IMediator _mediator;
private readonly CatalogSettings _catalogSettings;
diff --git a/src/Web/Grand.Web/Components/PopularProductTags.cs b/src/Web/Grand.Web/Components/PopularProductTags.cs
index f9c4f8b81..eace15d1e 100644
--- a/src/Web/Grand.Web/Components/PopularProductTags.cs
+++ b/src/Web/Grand.Web/Components/PopularProductTags.cs
@@ -9,19 +9,19 @@ namespace Grand.Web.Components;
public class PopularProductTagsViewComponent : BaseViewComponent
{
private readonly IMediator _mediator;
- private readonly IWorkContextAccessor _workContextAccessor;
+ private readonly IContextAccessor _contextAccessor;
- public PopularProductTagsViewComponent(IMediator mediator, IWorkContextAccessor workContextAccessor)
+ public PopularProductTagsViewComponent(IMediator mediator, IContextAccessor contextAccessor)
{
_mediator = mediator;
- _workContextAccessor = workContextAccessor;
+ _contextAccessor = contextAccessor;
}
public async Task<IViewComponentResult> InvokeAsync()
{
var model = await _mediator.Send(new GetPopularProductTags {
- Language = _workContextAccessor.WorkContext.WorkingLanguage,
- Store = _workContextAccessor.WorkContext.CurrentStore
+ Language = _contextAccessor.WorkContext.WorkingLanguage,
+ Store = _contextAccessor.StoreContext.CurrentStore
});
return !model.Tags.Any() ? Content("") : View(model);
}
diff --git a/src/Web/Grand.Web/Components/ProductEmailAFriend.cs b/src/Web/Grand.Web/Components/ProductEmailAFriend.cs
index 3e7ab267d..80d7e49d9 100644
--- a/src/Web/Grand.Web/Components/ProductEmailAFriend.cs
+++ b/src/Web/Grand.Web/Components/ProductEmailAFriend.cs
@@ -15,12 +15,12 @@ public class ProductEmailAFriendViewComponent : BaseViewComponent
public ProductEmailAFriendViewComponent(
IProductService productService,
- IWorkContextAccessor workContextAccessor,
+ IContextAccessor contextAccessor,
CatalogSettings catalogSettings,
CaptchaSettings captchaSettings)
{
_productService = productService;
- _workContextAccessor = workContextAccessor;
+ _contextAccessor = contextAccessor;
_catalogSettings = catalogSettings;
_captchaSettings = captchaSettings;
}
@@ -37,9 +37,9 @@ public class ProductEmailAFriendViewComponent : BaseViewComponent
var model = new ProductEmailAFriendModel {
ProductId = product.Id,
- ProductName = product.GetTranslation(x => x.Name, _workContextAccessor.WorkContext.WorkingLanguage.Id),
- ProductSeName = product.GetSeName(_workContextAccessor.WorkContext.WorkingLanguage.Id),
- YourEmailAddress = _workContextAccessor.WorkContext.CurrentCustomer.Email,
+ ProductName = product.GetTranslation(x => x.Name, _contextAccessor.WorkContext.WorkingLanguage.Id),
+ ProductSeName = product.GetSeName(_contextAccessor.WorkContext.WorkingLanguage.Id),
+ YourEmailAddress = _contextAccessor.WorkContext.CurrentCustomer.Email,
DisplayCaptcha = _captchaSettings.Enabled && _captchaSettings.ShowOnEmailProductToFriendPage
};
@@ -51,7 +51,7 @@ public class ProductEmailAFriendViewComponent : BaseViewComponent
#region Fields
private readonly IProductService _productService;
- private readonly IWorkContextAccessor _workContextAccessor;
+ private readonly IContextAccessor _contextAccessor;
private readonly CatalogSettings _catalogSettings;
private readonly CaptchaSettings _captchaSettings;
diff --git a/src/Web/Grand.Web/Components/ProductReviews.cs b/src/Web/Grand.Web/Components/ProductReviews.cs
index 1b006d0be..db4c6e15f 100644
--- a/src/Web/Grand.Web/Components/ProductReviews.cs
+++ b/src/Web/Grand.Web/Components/ProductReviews.cs
@@ -15,11 +15,11 @@ public class ProductReviewsViewComponent : BaseViewComponent
public ProductReviewsViewComponent(
IProductService productService,
IMediator mediator,
- IWorkContextAccessor workContextAccessor,
+ IContextAccessor contextAccessor,
CatalogSettings catalogSettings)
{
_productService = productService;
- _workContextAccessor = workContextAccessor;
+ _contextAccessor = contextAccessor;
_mediator = mediator;
_catalogSettings = catalogSettings;
}
@@ -35,10 +35,10 @@ public class ProductReviewsViewComponent : BaseViewComponent
return Content("");
var model = await _mediator.Send(new GetProductReviews {
- Customer = _workContextAccessor.WorkContext.CurrentCustomer,
- Language = _workContextAccessor.WorkContext.WorkingLanguage,
+ Customer = _contextAccessor.WorkContext.CurrentCustomer,
+ Language = _contextAccessor.WorkContext.WorkingLanguage,
Product = product,
- Store = _workContextAccessor.WorkContext.CurrentStore,
+ Store = _contextAccessor.StoreContext.CurrentStore,
Size = _catalogSettings.NumberOfReview
});
@@ -51,7 +51,7 @@ public class ProductReviewsViewComponent : BaseViewComponent
private readonly IProductService _productService;
private readonly IMediator _mediator;
- private readonly IWorkContextAccessor _workContextAccessor;
+ private readonly IContextAccessor _contextAccessor;
private readonly CatalogSettings _catalogSettings;
#endregion
diff --git a/src/Web/Grand.Web/Components/ProductsAlsoPurchased.cs b/src/Web/Grand.Web/Components/ProductsAlsoPurchased.cs
index ce91e3fe2..49309d9fa 100644
--- a/src/Web/Grand.Web/Components/ProductsAlsoPurchased.cs
+++ b/src/Web/Grand.Web/Components/ProductsAlsoPurchased.cs
@@ -20,7 +20,7 @@ public class ProductsAlsoPurchasedViewComponent : BaseViewComponent
IMediator mediator,
ICacheBase cacheBase,
IOrderReportService orderReportService,
- IWorkContextAccessor workContextAccessor,
+ IContextAccessor contextAccessor,
CatalogSettings catalogSettings
)
{
@@ -28,7 +28,7 @@ public class ProductsAlsoPurchasedViewComponent : BaseViewComponent
_mediator = mediator;
_cacheBase = cacheBase;
_orderReportService = orderReportService;
- _workContextAccessor = workContextAccessor;
+ _contextAccessor = contextAccessor;
_catalogSettings = catalogSettings;
}
@@ -43,10 +43,10 @@ public class ProductsAlsoPurchasedViewComponent : BaseViewComponent
//load and cache report
var productIds = await _cacheBase.GetAsync(
- string.Format(CacheKeyConst.PRODUCTS_ALSO_PURCHASED_IDS_KEY, productId, _workContextAccessor.WorkContext.CurrentStore.Id),
+ string.Format(CacheKeyConst.PRODUCTS_ALSO_PURCHASED_IDS_KEY, productId, _contextAccessor.StoreContext.CurrentStore.Id),
() =>
_orderReportService
- .GetAlsoPurchasedProductsIds(_workContextAccessor.WorkContext.CurrentStore.Id, productId,
+ .GetAlsoPurchasedProductsIds(_contextAccessor.StoreContext.CurrentStore.Id, productId,
_catalogSettings.ProductsAlsoPurchasedNumber)
);
@@ -75,7 +75,7 @@ public class ProductsAlsoPurchasedViewComponent : BaseViewComponent
private readonly IMediator _mediator;
private readonly ICacheBase _cacheBase;
private readonly IOrderReportService _orderReportService;
- private readonly IWorkContextAccessor _workContextAccessor;
+ private readonly IContextAccessor _contextAccessor;
private readonly CatalogSettings _catalogSettings;
#endregion
diff --git a/src/Web/Grand.Web/Components/PushNotificationsRegistration.cs b/src/Web/Grand.Web/Components/PushNotificationsRegistration.cs
index 7e79785ef..346887166 100644
--- a/src/Web/Grand.Web/Components/PushNotificationsRegistration.cs
+++ b/src/Web/Grand.Web/Components/PushNotificationsRegistration.cs
@@ -9,11 +9,11 @@ namespace Grand.Web.Components;
public class PushNotificationsRegistration : BaseViewComponent
{
private readonly PushNotificationsSettings _pushNotificationsSettings;
- private readonly IWorkContextAccessor _workContextAccessor;
+ private readonly IContextAccessor _contextAccessor;
- public PushNotificationsRegistration(IWorkContextAccessor workContextAccessor, PushNotificationsSettings pushNotificationsSettings)
+ public PushNotificationsRegistration(IContextAccessor contextAccessor, PushNotificationsSettings pushNotificationsSettings)
{
- _workContextAccessor = workContextAccessor;
+ _contextAccessor = contextAccessor;
_pushNotificationsSettings = pushNotificationsSettings;
}
@@ -34,7 +34,7 @@ public class PushNotificationsRegistration : BaseViewComponent
if (!_pushNotificationsSettings.Enabled) return Content("");
if (!_pushNotificationsSettings.AllowGuestNotifications &&
- string.IsNullOrEmpty(_workContextAccessor.WorkContext.CurrentCustomer.Email))
+ string.IsNullOrEmpty(_contextAccessor.WorkContext.CurrentCustomer.Email))
return Content("");
return View(model);
diff --git a/src/Web/Grand.Web/Components/RecentlyViewedProductsBlock.cs b/src/Web/Grand.Web/Components/RecentlyViewedProductsBlock.cs
index 95b69b5a6..3c25e3505 100644
--- a/src/Web/Grand.Web/Components/RecentlyViewedProductsBlock.cs
+++ b/src/Web/Grand.Web/Components/RecentlyViewedProductsBlock.cs
@@ -13,12 +13,12 @@ public class RecentlyViewedProductsBlockViewComponent : BaseViewComponent
#region Constructors
public RecentlyViewedProductsBlockViewComponent(
- IWorkContextAccessor workContextAccessor,
+ IContextAccessor contextAccessor,
IRecentlyViewedProductsService recentlyViewedProductsService,
IMediator mediator,
CatalogSettings catalogSettings)
{
- _workContextAccessor = workContextAccessor;
+ _contextAccessor = contextAccessor;
_recentlyViewedProductsService = recentlyViewedProductsService;
_mediator = mediator;
_catalogSettings = catalogSettings;
@@ -34,7 +34,7 @@ public class RecentlyViewedProductsBlockViewComponent : BaseViewComponent
return Content("");
var preparePictureModel = productThumbPictureSize.HasValue;
- var products = await _recentlyViewedProductsService.GetRecentlyViewedProducts(_workContextAccessor.WorkContext.CurrentCustomer.Id,
+ var products = await _recentlyViewedProductsService.GetRecentlyViewedProducts(_contextAccessor.WorkContext.CurrentCustomer.Id,
_catalogSettings.RecentlyViewedProductsNumber);
if (!products.Any())
@@ -55,7 +55,7 @@ public class RecentlyViewedProductsBlockViewComponent : BaseViewComponent
#region Fields
- private readonly IWorkContextAccessor _workContextAccessor;
+ private readonly IContextAccessor _contextAccessor;
private readonly IRecentlyViewedProductsService _recentlyViewedProductsService;
private readonly IMediator _mediator;
diff --git a/src/Web/Grand.Web/Components/SearchBox.cs b/src/Web/Grand.Web/Components/SearchBox.cs
index 064ae18bf..2d8d05c35 100644
--- a/src/Web/Grand.Web/Components/SearchBox.cs
+++ b/src/Web/Grand.Web/Components/SearchBox.cs
@@ -9,22 +9,22 @@ namespace Grand.Web.Components;
public class SearchBoxViewComponent : BaseViewComponent
{
private readonly IMediator _mediator;
- private readonly IWorkContextAccessor _workContextAccessor;
+ private readonly IContextAccessor _contextAccessor;
public SearchBoxViewComponent(
IMediator mediator,
- IWorkContextAccessor workContextAccessor)
+ IContextAccessor contextAccessor)
{
_mediator = mediator;
- _workContextAccessor = workContextAccessor;
+ _contextAccessor = contextAccessor;
}
public async Task<IViewComponentResult> InvokeAsync()
{
var model = await _mediator.Send(new GetSearchBox {
- Customer = _workContextAccessor.WorkContext.CurrentCustomer,
- Store = _workContextAccessor.WorkContext.CurrentStore,
- Language = _workContextAccessor.WorkContext.WorkingLanguage
+ Customer = _contextAccessor.WorkContext.CurrentCustomer,
+ Store = _contextAccessor.StoreContext.CurrentStore,
+ Language = _contextAccessor.WorkContext.WorkingLanguage
});
return View(model);
}
diff --git a/src/Web/Grand.Web/Components/SuggestedProducts.cs b/src/Web/Grand.Web/Components/SuggestedProducts.cs
index b4ea6b0b4..3db0d9134 100644
--- a/src/Web/Grand.Web/Components/SuggestedProducts.cs
+++ b/src/Web/Grand.Web/Components/SuggestedProducts.cs
@@ -13,11 +13,11 @@ public class SuggestedProductsViewComponent : BaseViewComponent
#region Constructors
public SuggestedProductsViewComponent(
- IWorkContextAccessor workContextAccessor,
+ IContextAccessor contextAccessor,
IMediator mediator,
CatalogSettings catalogSettings)
{
- _workContextAccessor = workContextAccessor;
+ _contextAccessor = contextAccessor;
_mediator = mediator;
_catalogSettings = catalogSettings;
}
@@ -32,7 +32,7 @@ public class SuggestedProductsViewComponent : BaseViewComponent
return Content("");
var products = await _mediator.Send(new GetSuggestedProductsQuery {
- CustomerTagIds = _workContextAccessor.WorkContext.CurrentCustomer.CustomerTags.ToArray(),
+ CustomerTagIds = _contextAccessor.WorkContext.CurrentCustomer.CustomerTags.ToArray(),
ProductsNumber = _catalogSettings.SuggestedProductsNumber
});
@@ -54,7 +54,7 @@ public class SuggestedProductsViewComponent : BaseViewComponent
#region Fields
- private readonly IWorkContextAccessor _workContextAccessor;
+ private readonly IContextAccessor _contextAccessor;
private readonly IMediator _mediator;
private readonly CatalogSettings _catalogSettings;
diff --git a/src/Web/Grand.Web/Components/VendorContact.cs b/src/Web/Grand.Web/Components/VendorContact.cs
index 9f8366fd2..1d4cea78d 100644
--- a/src/Web/Grand.Web/Components/VendorContact.cs
+++ b/src/Web/Grand.Web/Components/VendorContact.cs
@@ -17,13 +17,13 @@ public class VendorContactViewComponent : BaseViewComponent
public VendorContactViewComponent(
IVendorService vendorService,
- IWorkContextAccessor workContextAccessor,
+ IContextAccessor contextAccessor,
VendorSettings vendorSettings,
CommonSettings commonSettings,
CaptchaSettings captchaSettings)
{
_vendorService = vendorService;
- _workContextAccessor = workContextAccessor;
+ _contextAccessor = contextAccessor;
_vendorSettings = vendorSettings;
_commonSettings = commonSettings;
_captchaSettings = captchaSettings;
@@ -43,12 +43,12 @@ public class VendorContactViewComponent : BaseViewComponent
return Content("");
var model = new ContactVendorModel {
- Email = _workContextAccessor.WorkContext.CurrentCustomer.Email,
- FullName = _workContextAccessor.WorkContext.CurrentCustomer.GetFullName(),
+ Email = _contextAccessor.WorkContext.CurrentCustomer.Email,
+ FullName = _contextAccessor.WorkContext.CurrentCustomer.GetFullName(),
SubjectEnabled = _commonSettings.SubjectFieldOnContactUsForm,
DisplayCaptcha = _captchaSettings.Enabled && _captchaSettings.ShowOnContactUsPage,
VendorId = vendor.Id,
- VendorName = vendor.GetTranslation(x => x.Name, _workContextAccessor.WorkContext.WorkingLanguage.Id)
+ VendorName = vendor.GetTranslation(x => x.Name, _contextAccessor.WorkContext.WorkingLanguage.Id)
};
return View(model);
@@ -59,7 +59,7 @@ public class VendorContactViewComponent : BaseViewComponent
#region Fields
private readonly IVendorService _vendorService;
- private readonly IWorkContextAccessor _workContextAccessor;
+ private readonly IContextAccessor _contextAccessor;
private readonly VendorSettings _vendorSettings;
private readonly CommonSettings _commonSettings;
private readonly CaptchaSettings _captchaSettings;
diff --git a/src/Web/Grand.Web/Components/VendorNavigation.cs b/src/Web/Grand.Web/Components/VendorNavigation.cs
index 36023d890..7c5eeb33b 100644
--- a/src/Web/Grand.Web/Components/VendorNavigation.cs
+++ b/src/Web/Grand.Web/Components/VendorNavigation.cs
@@ -11,14 +11,14 @@ public class VendorNavigationViewComponent : BaseViewComponent
{
private readonly IMediator _mediator;
private readonly VendorSettings _vendorSettings;
- private readonly IWorkContextAccessor _workContextAccessor;
+ private readonly IContextAccessor _contextAccessor;
public VendorNavigationViewComponent(
- IWorkContextAccessor workContextAccessor,
+ IContextAccessor contextAccessor,
IMediator mediator,
VendorSettings vendorSettings)
{
- _workContextAccessor = workContextAccessor;
+ _contextAccessor = contextAccessor;
_mediator = mediator;
_vendorSettings = vendorSettings;
}
@@ -29,7 +29,7 @@ public class VendorNavigationViewComponent : BaseViewComponent
return Content("");
var model = await _mediator.Send(new GetVendorNavigation {
- Language = _workContextAccessor.WorkContext.WorkingLanguage
+ Language = _contextAccessor.WorkContext.WorkingLanguage
});
return !model.Vendors.Any() ? Content("") : View(model);
diff --git a/src/Web/Grand.Web/Components/VendorReviews.cs b/src/Web/Grand.Web/Components/VendorReviews.cs
index 393eea79a..5e2421ebc 100644
--- a/src/Web/Grand.Web/Components/VendorReviews.cs
+++ b/src/Web/Grand.Web/Components/VendorReviews.cs
@@ -16,13 +16,13 @@ public class VendorReviewsViewComponent : BaseViewComponent
public VendorReviewsViewComponent(
IVendorService vendorService,
IGroupService groupService,
- IWorkContextAccessor workContextAccessor,
+ IContextAccessor contextAccessor,
IMediator mediator,
VendorSettings vendorSettings)
{
_vendorService = vendorService;
_groupService = groupService;
- _workContextAccessor = workContextAccessor;
+ _contextAccessor = contextAccessor;
_mediator = mediator;
_vendorSettings = vendorSettings;
}
@@ -40,7 +40,7 @@ public class VendorReviewsViewComponent : BaseViewComponent
var model = await _mediator.Send(new GetVendorReviews { Vendor = vendor });
//only registered users can leave reviews
- if (await _groupService.IsGuest(_workContextAccessor.WorkContext.CurrentCustomer) &&
+ if (await _groupService.IsGuest(_contextAccessor.WorkContext.CurrentCustomer) &&
!_vendorSettings.AllowAnonymousUsersToReviewVendor)
model.AddVendorReview.NotAllowAnonymousUsersToReviewVendor = true;
@@ -55,7 +55,7 @@ public class VendorReviewsViewComponent : BaseViewComponent
private readonly IVendorService _vendorService;
private readonly IGroupService _groupService;
- private readonly IWorkContextAccessor _workContextAccessor;
+ private readonly IContextAccessor _contextAccessor;
private readonly IMediator _mediator;
private readonly VendorSettings _vendorSettings;
diff --git a/src/Web/Grand.Web/Components/Widget.cs b/src/Web/Grand.Web/Components/Widget.cs
index 9447a5a47..3ea5c4ea4 100644
--- a/src/Web/Grand.Web/Components/Widget.cs
+++ b/src/Web/Grand.Web/Components/Widget.cs
@@ -13,27 +13,27 @@ public class WidgetViewComponent : BaseViewComponent
{
private readonly ICacheBase _cacheBase;
private readonly IWidgetService _widgetService;
- private readonly IWorkContextAccessor _workContextAccessor;
+ private readonly IContextAccessor _contextAccessor;
- public WidgetViewComponent(IWorkContextAccessor workContextAccessor, ICacheBase cacheBase, IWidgetService widgetService)
+ public WidgetViewComponent(IContextAccessor contextAccessor, ICacheBase cacheBase, IWidgetService widgetService)
{
- _workContextAccessor = workContextAccessor;
+ _contextAccessor = contextAccessor;
_cacheBase = cacheBase;
_widgetService = widgetService;
}
public async Task<IViewComponentResult> InvokeAsync(string widgetZone, object additionalData = null)
{
- var cacheKey = string.Format(CacheKeyConst.WIDGET_MODEL_KEY, _workContextAccessor.WorkContext.CurrentStore.Id,
- string.Join(",", _workContextAccessor.WorkContext.CurrentCustomer.GetCustomerGroupIds()),
+ var cacheKey = string.Format(CacheKeyConst.WIDGET_MODEL_KEY, _contextAccessor.StoreContext.CurrentStore.Id,
+ string.Join(",", _contextAccessor.WorkContext.CurrentCustomer.GetCustomerGroupIds()),
widgetZone);
var cachedModel = await _cacheBase.GetAsync(cacheKey, async () =>
{
//model
var model = new List<WidgetModel>();
- var widgets = await _widgetService.LoadActiveWidgetsByWidgetZone(widgetZone, _workContextAccessor.WorkContext.CurrentStore.Id,
- _workContextAccessor.WorkContext.CurrentCustomer);
+ var widgets = await _widgetService.LoadActiveWidgetsByWidgetZone(widgetZone, _contextAccessor.StoreContext.CurrentStore.Id,
+ _contextAccessor.WorkContext.CurrentCustomer);
foreach (var widget in widgets)
{
var viewComponentName = await widget.GetPublicViewComponentName(widgetZone);
diff --git a/src/Web/Grand.Web/Controllers/AccountController.cs b/src/Web/Grand.Web/Controllers/AccountController.cs
index 082c1d737..39118610b 100644
--- a/src/Web/Grand.Web/Controllers/AccountController.cs
+++ b/src/Web/Grand.Web/Controllers/AccountController.cs
@@ -37,7 +37,7 @@ public class AccountController : BasePublicController
public AccountController(
IGrandAuthenticationService authenticationService,
ITranslationService translationService,
- IWorkContextAccessor workContextAccessor,
+ IContextAccessor contextAccessor,
ICustomerService customerService,
IGroupService groupService,
ICustomerManagerService customerManagerService,
@@ -49,7 +49,7 @@ public class AccountController : BasePublicController
{
_authenticationService = authenticationService;
_translationService = translationService;
- _workContextAccessor = workContextAccessor;
+ _contextAccessor = contextAccessor;
_customerService = customerService;
_groupService = groupService;
_customerManagerService = customerManagerService;
@@ -72,7 +72,7 @@ public class AccountController : BasePublicController
return RedirectToRoute("CustomerInfo");
var model = await _mediator.Send(new GetAuctions
- { Customer = _workContextAccessor.WorkContext.CurrentCustomer, Language = _workContextAccessor.WorkContext.WorkingLanguage });
+ { Customer = _contextAccessor.WorkContext.CurrentCustomer, Language = _contextAccessor.WorkContext.WorkingLanguage });
return View(model);
}
@@ -88,7 +88,7 @@ public class AccountController : BasePublicController
if (_customerSettings.HideNotesTab)
return RedirectToRoute("CustomerInfo");
- var model = await _mediator.Send(new GetNotes { Customer = _workContextAccessor.WorkContext.CurrentCustomer });
+ var model = await _mediator.Send(new GetNotes { Customer = _contextAccessor.WorkContext.CurrentCustomer });
return View(model);
}
@@ -105,8 +105,8 @@ public class AccountController : BasePublicController
return RedirectToRoute("CustomerInfo");
var model = await _mediator.Send(new GetDocuments {
- Customer = _workContextAccessor.WorkContext.CurrentCustomer,
- Language = _workContextAccessor.WorkContext.WorkingLanguage,
+ Customer = _contextAccessor.WorkContext.CurrentCustomer,
+ Language = _contextAccessor.WorkContext.WorkingLanguage,
Command = command
});
@@ -125,7 +125,7 @@ public class AccountController : BasePublicController
return RedirectToRoute("CustomerInfo");
var model = await _mediator.Send(new GetReviews
- { Customer = _workContextAccessor.WorkContext.CurrentCustomer, Language = _workContextAccessor.WorkContext.WorkingLanguage });
+ { Customer = _contextAccessor.WorkContext.CurrentCustomer, Language = _contextAccessor.WorkContext.WorkingLanguage });
return View(model);
}
@@ -142,7 +142,7 @@ public class AccountController : BasePublicController
return RedirectToRoute("CustomerInfo");
var model = await _mediator.Send(new GetCourses
- { Customer = _workContextAccessor.WorkContext.CurrentCustomer, Store = _workContextAccessor.WorkContext.CurrentStore });
+ { Customer = _contextAccessor.WorkContext.CurrentCustomer, Store = _contextAccessor.StoreContext.CurrentStore });
return View(model);
}
@@ -153,7 +153,7 @@ public class AccountController : BasePublicController
private readonly IGrandAuthenticationService _authenticationService;
private readonly ITranslationService _translationService;
- private readonly IWorkContextAccessor _workContextAccessor;
+ private readonly IContextAccessor _contextAccessor;
private readonly ICustomerService _customerService;
private readonly IGroupService _groupService;
private readonly ICustomerManagerService _customerManagerService;
@@ -242,8 +242,8 @@ public class AccountController : BasePublicController
if (_customerSettings.TwoFactorAuthenticationType != TwoFactorAuthenticationType.AppVerification)
await _mediator.Send(new GetTwoFactorAuthentication {
Customer = customer,
- Language = _workContextAccessor.WorkContext.WorkingLanguage,
- Store = _workContextAccessor.WorkContext.CurrentStore
+ Language = _contextAccessor.WorkContext.WorkingLanguage,
+ Store = _contextAccessor.StoreContext.CurrentStore
});
return View();
@@ -318,19 +318,19 @@ public class AccountController : BasePublicController
public virtual async Task<IActionResult> Logout(
[FromServices] StoreInformationSettings storeInformationSettings)
{
- if (_workContextAccessor.WorkContext.OriginalCustomerIfImpersonated != null)
+ if (_contextAccessor.WorkContext.OriginalCustomerIfImpersonated != null)
{
//logout impersonated customer
- await _customerService.UpdateUserField<int?>(_workContextAccessor.WorkContext.OriginalCustomerIfImpersonated,
+ await _customerService.UpdateUserField<int?>(_contextAccessor.WorkContext.OriginalCustomerIfImpersonated,
SystemCustomerFieldNames.ImpersonatedCustomerId, null);
//redirect back to customer details page (admin area)
return RedirectToAction("Edit", "Customer",
- new { id = _workContextAccessor.WorkContext.CurrentCustomer.Id, area = "Admin" });
+ new { id = _contextAccessor.WorkContext.CurrentCustomer.Id, area = "Admin" });
}
//raise event
- await _mediator.Publish(new CustomerLoggedOutEvent(_workContextAccessor.WorkContext.CurrentCustomer));
+ await _mediator.Publish(new CustomerLoggedOutEvent(_contextAccessor.WorkContext.CurrentCustomer));
//standard logout
await _authenticationService.SignOut();
@@ -367,8 +367,8 @@ public class AccountController : BasePublicController
var customer = await _customerService.GetCustomerByEmail(model.Email);
await _mediator.Send(new PasswordRecoverySendCommand {
Customer = customer,
- Store = _workContextAccessor.WorkContext.CurrentStore,
- Language = _workContextAccessor.WorkContext.WorkingLanguage,
+ Store = _contextAccessor.StoreContext.CurrentStore,
+ Language = _contextAccessor.WorkContext.WorkingLanguage,
Model = model
});
@@ -427,13 +427,13 @@ public class AccountController : BasePublicController
return RedirectToRoute("RegisterResult", new { resultId = (int)UserRegistrationType.Disabled });
//check if customer is registered.
- if (await _groupService.IsRegistered(_workContextAccessor.WorkContext.CurrentCustomer)) return RedirectToRoute("HomePage");
+ if (await _groupService.IsRegistered(_contextAccessor.WorkContext.CurrentCustomer)) return RedirectToRoute("HomePage");
var model = await _mediator.Send(new GetRegister {
- Customer = _workContextAccessor.WorkContext.CurrentCustomer,
+ Customer = _contextAccessor.WorkContext.CurrentCustomer,
ExcludeProperties = false,
- Language = _workContextAccessor.WorkContext.WorkingLanguage,
- Store = _workContextAccessor.WorkContext.CurrentStore
+ Language = _contextAccessor.WorkContext.WorkingLanguage,
+ Store = _contextAccessor.StoreContext.CurrentStore
});
return View(model);
@@ -450,45 +450,45 @@ public class AccountController : BasePublicController
return RedirectToRoute("RegisterResult", new { resultId = (int)UserRegistrationType.Disabled });
//check if customer is registered.
- if (await _groupService.IsRegistered(_workContextAccessor.WorkContext.CurrentCustomer)) return RedirectToRoute("HomePage");
+ if (await _groupService.IsRegistered(_contextAccessor.WorkContext.CurrentCustomer)) return RedirectToRoute("HomePage");
if (ModelState.IsValid)
{
if (_customerSettings.UsernamesEnabled && model.Username != null) model.Username = model.Username.Trim();
var isApproved = _customerSettings.UserRegistrationType == UserRegistrationType.Standard;
- var registrationRequest = new RegistrationRequest(_workContextAccessor.WorkContext.CurrentCustomer, model.Email,
+ var registrationRequest = new RegistrationRequest(_contextAccessor.WorkContext.CurrentCustomer, model.Email,
_customerSettings.UsernamesEnabled ? model.Username : model.Email, model.Password,
- _customerSettings.DefaultPasswordFormat, _workContextAccessor.WorkContext.CurrentStore.Id, isApproved);
+ _customerSettings.DefaultPasswordFormat, _contextAccessor.StoreContext.CurrentStore.Id, isApproved);
await _customerManagerService.RegisterCustomer(registrationRequest);
var customerAttributes = await _mediator.Send(new GetParseCustomAttributes
{ SelectedAttributes = model.SelectedAttributes });
await _mediator.Send(new CustomerRegisteredCommand {
- Customer = _workContextAccessor.WorkContext.CurrentCustomer,
+ Customer = _contextAccessor.WorkContext.CurrentCustomer,
CustomerAttributes = customerAttributes,
Model = model,
- Store = _workContextAccessor.WorkContext.CurrentStore
+ Store = _contextAccessor.StoreContext.CurrentStore
});
//login customer now
if (isApproved)
- await _authenticationService.SignIn(_workContextAccessor.WorkContext.CurrentCustomer, true);
+ await _authenticationService.SignIn(_contextAccessor.WorkContext.CurrentCustomer, true);
//raise event
- await _mediator.Publish(new CustomerRegisteredEvent(_workContextAccessor.WorkContext.CurrentCustomer));
+ await _mediator.Publish(new CustomerRegisteredEvent(_contextAccessor.WorkContext.CurrentCustomer));
switch (_customerSettings.UserRegistrationType)
{
case UserRegistrationType.EmailValidation:
{
//email validation message
- await _customerService.UpdateUserField(_workContextAccessor.WorkContext.CurrentCustomer,
+ await _customerService.UpdateUserField(_contextAccessor.WorkContext.CurrentCustomer,
SystemCustomerFieldNames.AccountActivationToken, Guid.NewGuid().ToString());
await _messageProviderService.SendCustomerEmailValidationMessage(
- _workContextAccessor.WorkContext.CurrentCustomer, _workContextAccessor.WorkContext.CurrentStore,
- _workContextAccessor.WorkContext.WorkingLanguage.Id);
+ _contextAccessor.WorkContext.CurrentCustomer, _contextAccessor.StoreContext.CurrentStore,
+ _contextAccessor.WorkContext.WorkingLanguage.Id);
//result
return RedirectToRoute("RegisterResult",
@@ -502,8 +502,8 @@ public class AccountController : BasePublicController
case UserRegistrationType.Standard:
{
//send customer welcome message
- await _messageProviderService.SendCustomerWelcomeMessage(_workContextAccessor.WorkContext.CurrentCustomer,
- _workContextAccessor.WorkContext.CurrentStore, _workContextAccessor.WorkContext.WorkingLanguage.Id);
+ await _messageProviderService.SendCustomerWelcomeMessage(_contextAccessor.WorkContext.CurrentCustomer,
+ _contextAccessor.StoreContext.CurrentStore, _contextAccessor.WorkContext.WorkingLanguage.Id);
var redirectUrl = Url.RouteUrl("RegisterResult",
new { resultId = (int)UserRegistrationType.Standard }, HttpContext.Request.Scheme);
@@ -521,10 +521,10 @@ public class AccountController : BasePublicController
//If we got this far, something failed, redisplay form
model = await _mediator.Send(new GetRegister {
- Customer = _workContextAccessor.WorkContext.CurrentCustomer,
+ Customer = _contextAccessor.WorkContext.CurrentCustomer,
ExcludeProperties = true,
- Language = _workContextAccessor.WorkContext.WorkingLanguage,
- Store = _workContextAccessor.WorkContext.CurrentStore,
+ Language = _contextAccessor.WorkContext.WorkingLanguage,
+ Store = _contextAccessor.StoreContext.CurrentStore,
Model = model,
OverrideCustomCustomerAttributes = await _mediator.Send(new GetParseCustomAttributes
{ SelectedAttributes = model.SelectedAttributes })
@@ -574,8 +574,8 @@ public class AccountController : BasePublicController
if (!_customerSettings.UsernamesEnabled || string.IsNullOrWhiteSpace(username))
return Json(new { Available = false, Text = statusText });
- if (_workContextAccessor.WorkContext.CurrentCustomer is { Username: not null } &&
- _workContextAccessor.WorkContext.CurrentCustomer.Username.Equals(username, StringComparison.OrdinalIgnoreCase))
+ if (_contextAccessor.WorkContext.CurrentCustomer is { Username: not null } &&
+ _contextAccessor.WorkContext.CurrentCustomer.Username.Equals(username, StringComparison.OrdinalIgnoreCase))
{
statusText = _translationService.GetResource("Account.CheckUsernameAvailability.CurrentUsername");
}
@@ -608,13 +608,13 @@ public class AccountController : BasePublicController
//activate user account
customer.Active = true;
- customer.StoreId = _workContextAccessor.WorkContext.CurrentStore.Id;
+ customer.StoreId = _contextAccessor.StoreContext.CurrentStore.Id;
await _customerService.UpdateActive(customer);
await _customerService.UpdateUserField(customer, SystemCustomerFieldNames.AccountActivationToken, "");
//send welcome message
- await _messageProviderService.SendCustomerWelcomeMessage(customer, _workContextAccessor.WorkContext.CurrentStore,
- _workContextAccessor.WorkContext.WorkingLanguage.Id);
+ await _messageProviderService.SendCustomerWelcomeMessage(customer, _contextAccessor.StoreContext.CurrentStore,
+ _contextAccessor.WorkContext.WorkingLanguage.Id);
var model = new AccountActivationModel {
Result = _translationService.GetResource("Account.AccountActivation.Activated")
@@ -632,10 +632,10 @@ public class AccountController : BasePublicController
public virtual async Task<IActionResult> Info()
{
var model = await _mediator.Send(new GetInfo {
- Customer = _workContextAccessor.WorkContext.CurrentCustomer,
+ Customer = _contextAccessor.WorkContext.CurrentCustomer,
ExcludeProperties = false,
- Language = _workContextAccessor.WorkContext.WorkingLanguage,
- Store = _workContextAccessor.WorkContext.CurrentStore
+ Language = _contextAccessor.WorkContext.WorkingLanguage,
+ Store = _contextAccessor.StoreContext.CurrentStore
});
return View(model);
}
@@ -649,14 +649,14 @@ public class AccountController : BasePublicController
if (ModelState.IsValid)
{
await _mediator.Send(new UpdateCustomerInfoCommand {
- Customer = _workContextAccessor.WorkContext.CurrentCustomer,
+ Customer = _contextAccessor.WorkContext.CurrentCustomer,
CustomerAttributes = await _mediator.Send(new GetParseCustomAttributes {
SelectedAttributes = model.SelectedAttributes,
- CustomerCustomAttribute = _workContextAccessor.WorkContext.CurrentCustomer.Attributes.ToList()
+ CustomerCustomAttribute = _contextAccessor.WorkContext.CurrentCustomer.Attributes.ToList()
}),
Model = model,
- OriginalCustomerIfImpersonated = _workContextAccessor.WorkContext.OriginalCustomerIfImpersonated,
- Store = _workContextAccessor.WorkContext.CurrentStore
+ OriginalCustomerIfImpersonated = _contextAccessor.WorkContext.OriginalCustomerIfImpersonated,
+ Store = _contextAccessor.StoreContext.CurrentStore
});
return RedirectToRoute("CustomerInfo");
}
@@ -664,13 +664,13 @@ public class AccountController : BasePublicController
//If we got this far, something failed, redisplay form
model = await _mediator.Send(new GetInfo {
Model = model,
- Customer = _workContextAccessor.WorkContext.CurrentCustomer,
+ Customer = _contextAccessor.WorkContext.CurrentCustomer,
ExcludeProperties = true,
- Language = _workContextAccessor.WorkContext.WorkingLanguage,
- Store = _workContextAccessor.WorkContext.CurrentStore,
+ Language = _contextAccessor.WorkContext.WorkingLanguage,
+ Store = _contextAccessor.StoreContext.CurrentStore,
OverrideCustomCustomerAttributes = await _mediator.Send(new GetParseCustomAttributes {
SelectedAttributes = model.SelectedAttributes,
- CustomerCustomAttribute = _workContextAccessor.WorkContext.CurrentCustomer.Attributes.ToList()
+ CustomerCustomAttribute = _contextAccessor.WorkContext.CurrentCustomer.Attributes.ToList()
})
});
@@ -684,7 +684,7 @@ public class AccountController : BasePublicController
[FromServices] IExternalAuthenticationService openAuthenticationService)
{
//ensure it's our record
- var ear = (await openAuthenticationService.GetExternalIdentifiers(_workContextAccessor.WorkContext.CurrentCustomer))
+ var ear = (await openAuthenticationService.GetExternalIdentifiers(_contextAccessor.WorkContext.CurrentCustomer))
.FirstOrDefault(x => x.Id == id);
if (ear == null)
@@ -706,7 +706,7 @@ public class AccountController : BasePublicController
if (!_customerSettings.AllowUsersToExportData)
return Challenge();
- var model = await _mediator.Send(new GetCustomerData(_workContextAccessor.WorkContext.CurrentCustomer));
+ var model = await _mediator.Send(new GetCustomerData(_contextAccessor.WorkContext.CurrentCustomer));
return File(model, "text/xls", "PersonalInfo.xlsx");
}
@@ -721,9 +721,9 @@ public class AccountController : BasePublicController
public virtual async Task<IActionResult> Addresses()
{
var model = await _mediator.Send(new GetAddressList {
- Customer = _workContextAccessor.WorkContext.CurrentCustomer,
- Language = _workContextAccessor.WorkContext.WorkingLanguage,
- Store = _workContextAccessor.WorkContext.CurrentStore
+ Customer = _contextAccessor.WorkContext.CurrentCustomer,
+ Language = _contextAccessor.WorkContext.WorkingLanguage,
+ Store = _contextAccessor.StoreContext.CurrentStore
});
return View(model);
}
@@ -733,7 +733,7 @@ public class AccountController : BasePublicController
[CustomerGroupAuthorize(SystemCustomerGroupNames.Registered)]
public virtual async Task<IActionResult> AddressDelete(string addressId)
{
- var customer = _workContextAccessor.WorkContext.CurrentCustomer;
+ var customer = _contextAccessor.WorkContext.CurrentCustomer;
//find address (ensure that it belongs to the current customer)
var address = customer.Addresses.FirstOrDefault(a => a.Id == addressId);
@@ -755,16 +755,16 @@ public class AccountController : BasePublicController
public virtual async Task<IActionResult> AddressAdd()
{
var countries =
- await _countryService.GetAllCountries(_workContextAccessor.WorkContext.WorkingLanguage.Id, _workContextAccessor.WorkContext.CurrentStore.Id);
+ await _countryService.GetAllCountries(_contextAccessor.WorkContext.WorkingLanguage.Id, _contextAccessor.StoreContext.CurrentStore.Id);
var model = new CustomerAddressEditModel {
Address = await _mediator.Send(new GetAddressModel {
- Language = _workContextAccessor.WorkContext.WorkingLanguage,
- Store = _workContextAccessor.WorkContext.CurrentStore,
+ Language = _contextAccessor.WorkContext.WorkingLanguage,
+ Store = _contextAccessor.StoreContext.CurrentStore,
Model = null,
Address = null,
ExcludeProperties = false,
PrePopulateWithCustomerFields = true,
- Customer = _workContextAccessor.WorkContext.CurrentCustomer,
+ Customer = _contextAccessor.WorkContext.CurrentCustomer,
LoadCountries = () => countries
})
};
@@ -779,11 +779,11 @@ public class AccountController : BasePublicController
public virtual async Task<IActionResult> AddressAdd(CustomerAddressEditModel model,
[FromServices] AddressSettings addressSettings)
{
- var customer = _workContextAccessor.WorkContext.CurrentCustomer;
+ var customer = _contextAccessor.WorkContext.CurrentCustomer;
if (ModelState.IsValid)
{
- var address = model.Address.ToEntity(_workContextAccessor.WorkContext.CurrentCustomer, addressSettings);
+ var address = model.Address.ToEntity(_contextAccessor.WorkContext.CurrentCustomer, addressSettings);
address.Attributes = await _mediator.Send(new GetParseCustomAddressAttributes
{ SelectedAttributes = model.Address.SelectedAttributes });
customer.Addresses.Add(address);
@@ -794,15 +794,15 @@ public class AccountController : BasePublicController
}
var countries =
- await _countryService.GetAllCountries(_workContextAccessor.WorkContext.WorkingLanguage.Id, _workContextAccessor.WorkContext.CurrentStore.Id);
+ await _countryService.GetAllCountries(_contextAccessor.WorkContext.WorkingLanguage.Id, _contextAccessor.StoreContext.CurrentStore.Id);
//If we got this far, something failed, redisplay form
model.Address = await _mediator.Send(new GetAddressModel {
- Language = _workContextAccessor.WorkContext.WorkingLanguage,
- Store = _workContextAccessor.WorkContext.CurrentStore,
+ Language = _contextAccessor.WorkContext.WorkingLanguage,
+ Store = _contextAccessor.StoreContext.CurrentStore,
Model = model.Address,
Address = null,
ExcludeProperties = true,
- Customer = _workContextAccessor.WorkContext.CurrentCustomer,
+ Customer = _contextAccessor.WorkContext.CurrentCustomer,
LoadCountries = () => countries,
OverrideAttributes = await _mediator.Send(new GetParseCustomAddressAttributes
{ SelectedAttributes = model.Address.SelectedAttributes })
@@ -816,7 +816,7 @@ public class AccountController : BasePublicController
[ProducesResponseType(typeof(CustomerAddressEditModel), StatusCodes.Status200OK)]
public virtual async Task<IActionResult> AddressEdit(string addressId)
{
- var customer = _workContextAccessor.WorkContext.CurrentCustomer;
+ var customer = _contextAccessor.WorkContext.CurrentCustomer;
//find address (ensure that it belongs to the current customer)
var address = customer.Addresses.FirstOrDefault(a => a.Id == addressId);
if (address == null)
@@ -824,15 +824,15 @@ public class AccountController : BasePublicController
return RedirectToRoute("CustomerAddresses");
var countries =
- await _countryService.GetAllCountries(_workContextAccessor.WorkContext.WorkingLanguage.Id, _workContextAccessor.WorkContext.CurrentStore.Id);
+ await _countryService.GetAllCountries(_contextAccessor.WorkContext.WorkingLanguage.Id, _contextAccessor.StoreContext.CurrentStore.Id);
var model = new CustomerAddressEditModel();
model.Address = await _mediator.Send(new GetAddressModel {
- Language = _workContextAccessor.WorkContext.WorkingLanguage,
- Store = _workContextAccessor.WorkContext.CurrentStore,
+ Language = _contextAccessor.WorkContext.WorkingLanguage,
+ Store = _contextAccessor.StoreContext.CurrentStore,
Model = model.Address,
Address = address,
ExcludeProperties = false,
- Customer = _workContextAccessor.WorkContext.CurrentCustomer,
+ Customer = _contextAccessor.WorkContext.CurrentCustomer,
LoadCountries = () => countries
});
@@ -847,7 +847,7 @@ public class AccountController : BasePublicController
public virtual async Task<IActionResult> AddressEdit(CustomerAddressEditModel model,
[FromServices] AddressSettings addressSettings)
{
- var customer = _workContextAccessor.WorkContext.CurrentCustomer;
+ var customer = _contextAccessor.WorkContext.CurrentCustomer;
//find address (ensure that it belongs to the current customer)
var address = customer.Addresses.FirstOrDefault(a => a.Id == model.Address.Id);
if (address == null)
@@ -856,7 +856,7 @@ public class AccountController : BasePublicController
if (ModelState.IsValid)
{
- address = model.Address.ToEntity(address, _workContextAccessor.WorkContext.CurrentCustomer, addressSettings);
+ address = model.Address.ToEntity(address, _contextAccessor.WorkContext.CurrentCustomer, addressSettings);
address.Attributes = await _mediator.Send(new GetParseCustomAddressAttributes
{ SelectedAttributes = model.Address.SelectedAttributes });
await _customerService.UpdateAddress(address, customer.Id);
@@ -870,15 +870,15 @@ public class AccountController : BasePublicController
}
var countries =
- await _countryService.GetAllCountries(_workContextAccessor.WorkContext.WorkingLanguage.Id, _workContextAccessor.WorkContext.CurrentStore.Id);
+ await _countryService.GetAllCountries(_contextAccessor.WorkContext.WorkingLanguage.Id, _contextAccessor.StoreContext.CurrentStore.Id);
//If we got this far, something failed, redisplay form
model.Address = await _mediator.Send(new GetAddressModel {
- Language = _workContextAccessor.WorkContext.WorkingLanguage,
- Store = _workContextAccessor.WorkContext.CurrentStore,
+ Language = _contextAccessor.WorkContext.WorkingLanguage,
+ Store = _contextAccessor.StoreContext.CurrentStore,
Model = model.Address,
Address = address,
ExcludeProperties = true,
- Customer = _workContextAccessor.WorkContext.CurrentCustomer,
+ Customer = _contextAccessor.WorkContext.CurrentCustomer,
LoadCountries = () => countries,
OverrideAttributes = await _mediator.Send(new GetParseCustomAddressAttributes
{ SelectedAttributes = model.Address.SelectedAttributes })
@@ -899,9 +899,9 @@ public class AccountController : BasePublicController
return RedirectToRoute("CustomerInfo");
var model = await _mediator.Send(new GetDownloadableProducts {
- Customer = _workContextAccessor.WorkContext.CurrentCustomer,
- Store = _workContextAccessor.WorkContext.CurrentStore,
- Language = _workContextAccessor.WorkContext.WorkingLanguage
+ Customer = _contextAccessor.WorkContext.CurrentCustomer,
+ Store = _contextAccessor.StoreContext.CurrentStore,
+ Language = _contextAccessor.WorkContext.WorkingLanguage
});
return View(model);
}
@@ -923,7 +923,7 @@ public class AccountController : BasePublicController
{
var model = new ChangePasswordModel {
PasswordIsExpired = await _mediator.Send(new GetPasswordIsExpiredQuery
- { Customer = _workContextAccessor.WorkContext.CurrentCustomer })
+ { Customer = _contextAccessor.WorkContext.CurrentCustomer })
};
return View(model);
@@ -936,13 +936,14 @@ public class AccountController : BasePublicController
{
if (!ModelState.IsValid) return View(model);
- var changePasswordRequest = new ChangePasswordRequest(_workContextAccessor.WorkContext.CurrentCustomer.Email,
+ var changePasswordRequest = new ChangePasswordRequest(_contextAccessor.WorkContext.CurrentCustomer.Email,
_customerSettings.DefaultPasswordFormat, model.NewPassword, model.OldPassword);
await _customerManagerService.ChangePassword(changePasswordRequest);
+ var customer = await _customerService.GetCustomerById(_contextAccessor.WorkContext.CurrentCustomer.Id);
//sign in
- await _authenticationService.SignIn(_workContextAccessor.WorkContext.CurrentCustomer, true);
+ await _authenticationService.SignIn(customer, true);
model.Result = _translationService.GetResource("Account.ChangePassword.Success");
return View(model);
@@ -976,8 +977,8 @@ public class AccountController : BasePublicController
//delete account
await _mediator.Send(new DeleteAccountCommand {
- Customer = _workContextAccessor.WorkContext.CurrentCustomer,
- Store = _workContextAccessor.WorkContext.CurrentStore,
+ Customer = _contextAccessor.WorkContext.CurrentCustomer,
+ Store = _contextAccessor.StoreContext.CurrentStore,
IpAddress = HttpContext.Connection?.RemoteIpAddress?.ToString()
});
@@ -1002,13 +1003,13 @@ public class AccountController : BasePublicController
if (!_customerSettings.TwoFactorAuthenticationEnabled)
return RedirectToRoute("CustomerInfo");
- if (_workContextAccessor.WorkContext.CurrentCustomer.GetUserFieldFromEntity<bool>(SystemCustomerFieldNames.TwoFactorEnabled))
+ if (_contextAccessor.WorkContext.CurrentCustomer.GetUserFieldFromEntity<bool>(SystemCustomerFieldNames.TwoFactorEnabled))
return RedirectToRoute("CustomerInfo");
var model = await _mediator.Send(new GetTwoFactorAuthentication {
- Customer = _workContextAccessor.WorkContext.CurrentCustomer,
- Language = _workContextAccessor.WorkContext.WorkingLanguage,
- Store = _workContextAccessor.WorkContext.CurrentStore
+ Customer = _contextAccessor.WorkContext.CurrentCustomer,
+ Language = _contextAccessor.WorkContext.WorkingLanguage,
+ Store = _contextAccessor.StoreContext.CurrentStore
});
return View(model);
}
@@ -1023,7 +1024,7 @@ public class AccountController : BasePublicController
if (!_customerSettings.TwoFactorAuthenticationEnabled)
return RedirectToRoute("CustomerInfo");
- if (_workContextAccessor.WorkContext.CurrentCustomer.GetUserFieldFromEntity<bool>(SystemCustomerFieldNames.TwoFactorEnabled))
+ if (_contextAccessor.WorkContext.CurrentCustomer.GetUserFieldFromEntity<bool>(SystemCustomerFieldNames.TwoFactorEnabled))
return RedirectToRoute("CustomerInfo");
if (string.IsNullOrEmpty(model.Code))
@@ -1034,11 +1035,11 @@ public class AccountController : BasePublicController
else
{
if (await twoFactorAuthenticationService.AuthenticateTwoFactor(model.SecretKey, model.Code,
- _workContextAccessor.WorkContext.CurrentCustomer, _customerSettings.TwoFactorAuthenticationType))
+ _contextAccessor.WorkContext.CurrentCustomer, _customerSettings.TwoFactorAuthenticationType))
{
- await _customerService.UpdateUserField(_workContextAccessor.WorkContext.CurrentCustomer,
+ await _customerService.UpdateUserField(_contextAccessor.WorkContext.CurrentCustomer,
SystemCustomerFieldNames.TwoFactorEnabled, true);
- await _customerService.UpdateUserField(_workContextAccessor.WorkContext.CurrentCustomer,
+ await _customerService.UpdateUserField(_contextAccessor.WorkContext.CurrentCustomer,
SystemCustomerFieldNames.TwoFactorSecretKey, model.SecretKey);
Success(_translationService.GetResource("Account.TwoFactorAuth.Enabled"));
@@ -1061,13 +1062,13 @@ public class AccountController : BasePublicController
if (!_customerSettings.TwoFactorAuthenticationEnabled)
return RedirectToRoute("CustomerInfo");
- if (!_workContextAccessor.WorkContext.CurrentCustomer.GetUserFieldFromEntity<bool>(SystemCustomerFieldNames.TwoFactorEnabled))
+ if (!_contextAccessor.WorkContext.CurrentCustomer.GetUserFieldFromEntity<bool>(SystemCustomerFieldNames.TwoFactorEnabled))
return RedirectToRoute("CustomerInfo");
_ = await _mediator.Send(new GetTwoFactorAuthentication {
- Customer = _workContextAccessor.WorkContext.CurrentCustomer,
- Language = _workContextAccessor.WorkContext.WorkingLanguage,
- Store = _workContextAccessor.WorkContext.CurrentStore
+ Customer = _contextAccessor.WorkContext.CurrentCustomer,
+ Language = _contextAccessor.WorkContext.WorkingLanguage,
+ Store = _contextAccessor.StoreContext.CurrentStore
});
var model = new CustomerInfoModel.TwoFactorAuthorizationModel {
@@ -1086,7 +1087,7 @@ public class AccountController : BasePublicController
if (!_customerSettings.TwoFactorAuthenticationEnabled)
return RedirectToRoute("CustomerInfo");
- if (!_workContextAccessor.WorkContext.CurrentCustomer.GetUserFieldFromEntity<bool>(SystemCustomerFieldNames.TwoFactorEnabled))
+ if (!_contextAccessor.WorkContext.CurrentCustomer.GetUserFieldFromEntity<bool>(SystemCustomerFieldNames.TwoFactorEnabled))
return RedirectToRoute("CustomerInfo");
if (string.IsNullOrEmpty(model.Code))
@@ -1097,14 +1098,14 @@ public class AccountController : BasePublicController
else
{
var secretKey =
- _workContextAccessor.WorkContext.CurrentCustomer.GetUserFieldFromEntity<string>(SystemCustomerFieldNames
+ _contextAccessor.WorkContext.CurrentCustomer.GetUserFieldFromEntity<string>(SystemCustomerFieldNames
.TwoFactorSecretKey);
if (await twoFactorAuthenticationService.AuthenticateTwoFactor(secretKey, model.Code,
- _workContextAccessor.WorkContext.CurrentCustomer, _customerSettings.TwoFactorAuthenticationType))
+ _contextAccessor.WorkContext.CurrentCustomer, _customerSettings.TwoFactorAuthenticationType))
{
- await _customerService.UpdateUserField(_workContextAccessor.WorkContext.CurrentCustomer,
+ await _customerService.UpdateUserField(_contextAccessor.WorkContext.CurrentCustomer,
SystemCustomerFieldNames.TwoFactorEnabled, false);
- await _customerService.UpdateUserField<string>(_workContextAccessor.WorkContext.CurrentCustomer,
+ await _customerService.UpdateUserField<string>(_contextAccessor.WorkContext.CurrentCustomer,
SystemCustomerFieldNames.TwoFactorSecretKey, null);
Success(_translationService.GetResource("Account.TwoFactorAuth.Disabled"));
@@ -1127,13 +1128,13 @@ public class AccountController : BasePublicController
[CustomerGroupAuthorize(SystemCustomerGroupNames.Registered)]
public virtual async Task<IActionResult> SubAccounts()
{
- if (!await _groupService.IsOwner(_workContextAccessor.WorkContext.CurrentCustomer))
+ if (!await _groupService.IsOwner(_contextAccessor.WorkContext.CurrentCustomer))
return Challenge();
if (_customerSettings.HideSubAccountsTab)
return RedirectToRoute("CustomerInfo");
- var model = await _mediator.Send(new GetSubAccounts { Customer = _workContextAccessor.WorkContext.CurrentCustomer });
+ var model = await _mediator.Send(new GetSubAccounts { Customer = _contextAccessor.WorkContext.CurrentCustomer });
return View(model);
}
@@ -1142,7 +1143,7 @@ public class AccountController : BasePublicController
[CustomerGroupAuthorize(SystemCustomerGroupNames.Registered)]
public virtual async Task<IActionResult> SubAccountAdd()
{
- if (!await _groupService.IsOwner(_workContextAccessor.WorkContext.CurrentCustomer))
+ if (!await _groupService.IsOwner(_contextAccessor.WorkContext.CurrentCustomer))
return Challenge();
var model = new SubAccountCreateModel {
@@ -1156,15 +1157,15 @@ public class AccountController : BasePublicController
[CustomerGroupAuthorize(SystemCustomerGroupNames.Registered)]
public virtual async Task<IActionResult> SubAccountAdd(SubAccountCreateModel model)
{
- if (!await _groupService.IsOwner(_workContextAccessor.WorkContext.CurrentCustomer))
+ if (!await _groupService.IsOwner(_contextAccessor.WorkContext.CurrentCustomer))
return Challenge();
if (!ModelState.IsValid) return View(model);
await _mediator.Send(new SubAccountAddCommand {
- Customer = _workContextAccessor.WorkContext.CurrentCustomer,
+ Customer = _contextAccessor.WorkContext.CurrentCustomer,
Model = model,
- Store = _workContextAccessor.WorkContext.CurrentStore
+ Store = _contextAccessor.StoreContext.CurrentStore
});
return RedirectToRoute("CustomerSubAccounts");
@@ -1174,11 +1175,11 @@ public class AccountController : BasePublicController
[CustomerGroupAuthorize(SystemCustomerGroupNames.Registered)]
public virtual async Task<IActionResult> SubAccountEdit(string id)
{
- if (!await _groupService.IsOwner(_workContextAccessor.WorkContext.CurrentCustomer))
+ if (!await _groupService.IsOwner(_contextAccessor.WorkContext.CurrentCustomer))
return Challenge();
var model = await _mediator.Send(new GetSubAccount
- { CustomerId = id, CurrentCustomer = _workContextAccessor.WorkContext.CurrentCustomer });
+ { CustomerId = id, CurrentCustomer = _contextAccessor.WorkContext.CurrentCustomer });
return View(model);
}
@@ -1188,15 +1189,15 @@ public class AccountController : BasePublicController
[CustomerGroupAuthorize(SystemCustomerGroupNames.Registered)]
public virtual async Task<IActionResult> SubAccountEdit(SubAccountEditModel model)
{
- if (!await _groupService.IsOwner(_workContextAccessor.WorkContext.CurrentCustomer))
+ if (!await _groupService.IsOwner(_contextAccessor.WorkContext.CurrentCustomer))
return Challenge();
if (!ModelState.IsValid) return View(model);
_ = await _mediator.Send(new SubAccountEditCommand {
- CurrentCustomer = _workContextAccessor.WorkContext.CurrentCustomer,
+ CurrentCustomer = _contextAccessor.WorkContext.CurrentCustomer,
EditModel = model,
- Store = _workContextAccessor.WorkContext.CurrentStore
+ Store = _contextAccessor.StoreContext.CurrentStore
});
return RedirectToRoute("CustomerSubAccounts");
@@ -1207,11 +1208,11 @@ public class AccountController : BasePublicController
[CustomerGroupAuthorize(SystemCustomerGroupNames.Registered)]
public virtual async Task<IActionResult> SubAccountDelete(string id)
{
- if (!await _groupService.IsOwner(_workContextAccessor.WorkContext.CurrentCustomer))
+ if (!await _groupService.IsOwner(_contextAccessor.WorkContext.CurrentCustomer))
return Challenge();
var result = await _mediator.Send(new SubAccountDeleteCommand {
- CurrentCustomer = _workContextAccessor.WorkContext.CurrentCustomer,
+ CurrentCustomer = _contextAccessor.WorkContext.CurrentCustomer,
CustomerId = id
});
diff --git a/src/Web/Grand.Web/Controllers/ActionCartController.cs b/src/Web/Grand.Web/Controllers/ActionCartController.cs
index d8e2498ee..ef629213b 100644
--- a/src/Web/Grand.Web/Controllers/ActionCartController.cs
+++ b/src/Web/Grand.Web/Controllers/ActionCartController.cs
@@ -31,7 +31,7 @@ public class ActionCartController : BasePublicController
public ActionCartController(IProductService productService,
IShoppingCartService shoppingCartService,
- IWorkContextAccessor workContextAccessor,
+ IContextAccessor contextAccessor,
IGroupService groupService,
ITranslationService translationService,
ICurrencyService currencyService,
@@ -41,7 +41,7 @@ public class ActionCartController : BasePublicController
{
_productService = productService;
_shoppingCartService = shoppingCartService;
- _workContextAccessor = workContextAccessor;
+ _contextAccessor = contextAccessor;
_groupService = groupService;
_translationService = translationService;
_currencyService = currencyService;
@@ -56,7 +56,7 @@ public class ActionCartController : BasePublicController
private readonly IProductService _productService;
private readonly IShoppingCartService _shoppingCartService;
- private readonly IWorkContextAccessor _workContextAccessor;
+ private readonly IContextAccessor _contextAccessor;
private readonly IGroupService _groupService;
private readonly ITranslationService _translationService;
private readonly ICurrencyService _currencyService;
@@ -73,7 +73,7 @@ public class ActionCartController : BasePublicController
//we can't add grouped products
if (product.ProductTypeId == ProductType.GroupedProduct)
return Json(new {
- redirect = Url.RouteUrl("Product", new { SeName = product.GetSeName(_workContextAccessor.WorkContext.WorkingLanguage.Id) })
+ redirect = Url.RouteUrl("Product", new { SeName = product.GetSeName(_contextAccessor.WorkContext.WorkingLanguage.Id) })
});
switch (cartType)
@@ -83,13 +83,13 @@ public class ActionCartController : BasePublicController
//we cannot add to the cart such products from category pages
return Json(new {
redirect = Url.RouteUrl("Product",
- new { SeName = product.GetSeName(_workContextAccessor.WorkContext.WorkingLanguage.Id) })
+ new { SeName = product.GetSeName(_contextAccessor.WorkContext.WorkingLanguage.Id) })
});
case ShoppingCartType.ShoppingCart when product.EnteredPrice:
//cannot be added to the cart (requires a customer to enter price)
return Json(new {
redirect = Url.RouteUrl("Product",
- new { SeName = product.GetSeName(_workContextAccessor.WorkContext.WorkingLanguage.Id) })
+ new { SeName = product.GetSeName(_contextAccessor.WorkContext.WorkingLanguage.Id) })
});
}
@@ -97,13 +97,13 @@ public class ActionCartController : BasePublicController
if (cartType == ShoppingCartType.ShoppingCart && allowedQuantities.Length > 0)
//cannot be added to the cart (requires a customer to select a quantity from drop down list)
return Json(new {
- redirect = Url.RouteUrl("Product", new { SeName = product.GetSeName(_workContextAccessor.WorkContext.WorkingLanguage.Id) })
+ redirect = Url.RouteUrl("Product", new { SeName = product.GetSeName(_contextAccessor.WorkContext.WorkingLanguage.Id) })
});
if (cartType != ShoppingCartType.Wishlist && product.ProductAttributeMappings.Any())
//product has some attributes
return Json(new {
- redirect = Url.RouteUrl("Product", new { SeName = product.GetSeName(_workContextAccessor.WorkContext.WorkingLanguage.Id) })
+ redirect = Url.RouteUrl("Product", new { SeName = product.GetSeName(_contextAccessor.WorkContext.WorkingLanguage.Id) })
});
return null;
@@ -111,9 +111,9 @@ public class ActionCartController : BasePublicController
private string GetWarehouse(Product product)
{
- return product.UseMultipleWarehouses ? _workContextAccessor.WorkContext.CurrentStore.DefaultWarehouseId :
- string.IsNullOrEmpty(_workContextAccessor.WorkContext.CurrentStore.DefaultWarehouseId) ? product.WarehouseId :
- _workContextAccessor.WorkContext.CurrentStore.DefaultWarehouseId;
+ return product.UseMultipleWarehouses ? _contextAccessor.StoreContext.CurrentStore.DefaultWarehouseId :
+ string.IsNullOrEmpty(_contextAccessor.StoreContext.CurrentStore.DefaultWarehouseId) ? product.WarehouseId :
+ _contextAccessor.StoreContext.CurrentStore.DefaultWarehouseId;
}
private IActionResult ReturnFailMessage(Product product, ShoppingCartType shoppingCartTypeId)
@@ -156,7 +156,7 @@ public class ActionCartController : BasePublicController
if (double.TryParse(model.CustomerEnteredPrice, out var customerEnteredPrice))
customerEnteredPriceConverted =
await _currencyService.ConvertToPrimaryStoreCurrency(customerEnteredPrice,
- _workContextAccessor.WorkContext.WorkingCurrency);
+ _contextAccessor.WorkContext.WorkingCurrency);
return customerEnteredPriceConverted;
}
@@ -181,11 +181,11 @@ public class ActionCartController : BasePublicController
if (redirect != null)
return redirect;
- var customer = _workContextAccessor.WorkContext.CurrentCustomer;
+ var customer = _contextAccessor.WorkContext.CurrentCustomer;
var warehouseId = GetWarehouse(product);
- var cart = await _shoppingCartService.GetShoppingCart(_workContextAccessor.WorkContext.CurrentStore.Id, model.ShoppingCartTypeId);
+ var cart = await _shoppingCartService.GetShoppingCart(_contextAccessor.StoreContext.CurrentStore.Id, model.ShoppingCartTypeId);
if (model.ShoppingCartTypeId != ShoppingCartType.Wishlist)
{
@@ -198,7 +198,7 @@ public class ActionCartController : BasePublicController
var addToCartWarnings = await _shoppingCartValidator
.GetShoppingCartItemWarnings(customer, new ShoppingCartItem {
ShoppingCartTypeId = model.ShoppingCartTypeId,
- StoreId = _workContextAccessor.WorkContext.CurrentStore.Id,
+ StoreId = _contextAccessor.StoreContext.CurrentStore.Id,
WarehouseId = warehouseId,
Quantity = quantityToValidate
}, product, new ShoppingCartValidatorOptions {
@@ -209,7 +209,7 @@ public class ActionCartController : BasePublicController
//cannot be added to the cart
return Json(new {
redirect = Url.RouteUrl("Product",
- new { SeName = product.GetSeName(_workContextAccessor.WorkContext.WorkingLanguage.Id) })
+ new { SeName = product.GetSeName(_contextAccessor.WorkContext.WorkingLanguage.Id) })
});
}
@@ -217,7 +217,7 @@ public class ActionCartController : BasePublicController
var addToCart = await _shoppingCartService.AddToCart(customer,
product.Id,
model.ShoppingCartTypeId,
- _workContextAccessor.WorkContext.CurrentStore.Id,
+ _contextAccessor.StoreContext.CurrentStore.Id,
warehouseId,
quantity: model.Quantity,
validator: new ShoppingCartValidatorOptions {
@@ -231,7 +231,7 @@ public class ActionCartController : BasePublicController
if (addToCart.warnings.Any())
//cannot be added to the cart
return Json(new {
- redirect = Url.RouteUrl("Product", new { SeName = product.GetSeName(_workContextAccessor.WorkContext.WorkingLanguage.Id) })
+ redirect = Url.RouteUrl("Product", new { SeName = product.GetSeName(_contextAccessor.WorkContext.WorkingLanguage.Id) })
});
var addtoCartModel = await _mediator.Send(new GetAddToCart {
@@ -240,10 +240,10 @@ public class ActionCartController : BasePublicController
ShoppingCartItem = addToCart.shoppingCartItem,
Quantity = model.Quantity,
CartType = model.ShoppingCartTypeId,
- Currency = _workContextAccessor.WorkContext.WorkingCurrency,
- Store = _workContextAccessor.WorkContext.CurrentStore,
- Language = _workContextAccessor.WorkContext.WorkingLanguage,
- TaxDisplayType = _workContextAccessor.WorkContext.TaxDisplayType
+ Currency = _contextAccessor.WorkContext.WorkingCurrency,
+ Store = _contextAccessor.StoreContext.CurrentStore,
+ Language = _contextAccessor.WorkContext.WorkingLanguage,
+ TaxDisplayType = _contextAccessor.WorkContext.TaxDisplayType
});
//added to the cart/wishlist
@@ -258,7 +258,7 @@ public class ActionCartController : BasePublicController
});
//display notification message and update appropriate blocks
- var qty = (await _shoppingCartService.GetShoppingCart(_workContextAccessor.WorkContext.CurrentStore.Id,
+ var qty = (await _shoppingCartService.GetShoppingCart(_contextAccessor.StoreContext.CurrentStore.Id,
ShoppingCartType.Wishlist)).Sum(x => x.Quantity);
var updatetopwishlistsectionhtml =
string.Format(_translationService.GetResource("Wishlist.HeaderQuantity"), qty);
@@ -292,17 +292,17 @@ public class ActionCartController : BasePublicController
var updatetopcartsectionhtml = string.Format(
_translationService.GetResource("ShoppingCart.HeaderQuantity"),
- (await _shoppingCartService.GetShoppingCart(_workContextAccessor.WorkContext.CurrentStore.Id,
+ (await _shoppingCartService.GetShoppingCart(_contextAccessor.StoreContext.CurrentStore.Id,
shoppingCartTypes.ToArray()))
.Sum(x => x.Quantity));
var miniShoppingCartmodel = _shoppingCartSettings.MiniShoppingCartEnabled
? await _mediator.Send(new GetMiniShoppingCart {
- Customer = _workContextAccessor.WorkContext.CurrentCustomer,
- Currency = _workContextAccessor.WorkContext.WorkingCurrency,
- Language = _workContextAccessor.WorkContext.WorkingLanguage,
- TaxDisplayType = _workContextAccessor.WorkContext.TaxDisplayType,
- Store = _workContextAccessor.WorkContext.CurrentStore
+ Customer = _contextAccessor.WorkContext.CurrentCustomer,
+ Currency = _contextAccessor.WorkContext.WorkingCurrency,
+ Language = _contextAccessor.WorkContext.WorkingLanguage,
+ TaxDisplayType = _contextAccessor.WorkContext.TaxDisplayType,
+ Store = _contextAccessor.StoreContext.CurrentStore
})
: null;
@@ -396,14 +396,14 @@ public class ActionCartController : BasePublicController
//save item
var addToCartWarnings = new List<string>();
var warehouseId = _shoppingCartSettings.AllowToSelectWarehouse ? model.WarehouseId :
- product.UseMultipleWarehouses ? _workContextAccessor.WorkContext.CurrentStore.DefaultWarehouseId :
- string.IsNullOrEmpty(_workContextAccessor.WorkContext.CurrentStore.DefaultWarehouseId) ? product.WarehouseId :
- _workContextAccessor.WorkContext.CurrentStore.DefaultWarehouseId;
+ product.UseMultipleWarehouses ? _contextAccessor.StoreContext.CurrentStore.DefaultWarehouseId :
+ string.IsNullOrEmpty(_contextAccessor.StoreContext.CurrentStore.DefaultWarehouseId) ? product.WarehouseId :
+ _contextAccessor.StoreContext.CurrentStore.DefaultWarehouseId;
//add to the cart
- var (warnings, shoppingCartItem) = await _shoppingCartService.AddToCart(_workContextAccessor.WorkContext.CurrentCustomer,
- product.Id, model.ShoppingCartTypeId, _workContextAccessor.WorkContext.CurrentStore.Id, warehouseId,
+ var (warnings, shoppingCartItem) = await _shoppingCartService.AddToCart(_contextAccessor.WorkContext.CurrentCustomer,
+ product.Id, model.ShoppingCartTypeId, _contextAccessor.StoreContext.CurrentStore.Id, warehouseId,
attributes, customerEnteredPriceConverted,
rentalStartDate, rentalEndDate, model.EnteredQuantity, true, model.Reservation, parameter, duration,
new ShoppingCartValidatorOptions {
@@ -426,16 +426,16 @@ public class ActionCartController : BasePublicController
var addtoCartModel = await _mediator.Send(new GetAddToCart {
Product = product,
- Customer = _workContextAccessor.WorkContext.CurrentCustomer,
+ Customer = _contextAccessor.WorkContext.CurrentCustomer,
ShoppingCartItem = shoppingCartItem,
Quantity = model.EnteredQuantity,
CartType = model.ShoppingCartTypeId,
CustomerEnteredPrice = customerEnteredPriceConverted,
Attributes = attributes,
- Currency = _workContextAccessor.WorkContext.WorkingCurrency,
- Store = _workContextAccessor.WorkContext.CurrentStore,
- Language = _workContextAccessor.WorkContext.WorkingLanguage,
- TaxDisplayType = _workContextAccessor.WorkContext.TaxDisplayType,
+ Currency = _contextAccessor.WorkContext.WorkingCurrency,
+ Store = _contextAccessor.StoreContext.CurrentStore,
+ Language = _contextAccessor.WorkContext.WorkingLanguage,
+ TaxDisplayType = _contextAccessor.WorkContext.TaxDisplayType,
Duration = duration,
Parameter = parameter,
ReservationId = model.Reservation,
@@ -455,7 +455,7 @@ public class ActionCartController : BasePublicController
});
//display notification message and update appropriate blocks
- var qty = (await _shoppingCartService.GetShoppingCart(_workContextAccessor.WorkContext.CurrentStore.Id,
+ var qty = (await _shoppingCartService.GetShoppingCart(_contextAccessor.StoreContext.CurrentStore.Id,
ShoppingCartType.Wishlist)).Sum(x => x.Quantity);
var updatetopwishlistsectionhtml =
string.Format(_translationService.GetResource("Wishlist.HeaderQuantity"), qty);
@@ -489,17 +489,17 @@ public class ActionCartController : BasePublicController
var updatetopcartsectionhtml = string.Format(
_translationService.GetResource("ShoppingCart.HeaderQuantity"),
- (await _shoppingCartService.GetShoppingCart(_workContextAccessor.WorkContext.CurrentStore.Id,
+ (await _shoppingCartService.GetShoppingCart(_contextAccessor.StoreContext.CurrentStore.Id,
shoppingCartTypes.ToArray()))
.Sum(x => x.Quantity));
var miniShoppingCartmodel = _shoppingCartSettings.MiniShoppingCartEnabled
? await _mediator.Send(new GetMiniShoppingCart {
- Customer = _workContextAccessor.WorkContext.CurrentCustomer,
- Currency = _workContextAccessor.WorkContext.WorkingCurrency,
- Language = _workContextAccessor.WorkContext.WorkingLanguage,
- TaxDisplayType = _workContextAccessor.WorkContext.TaxDisplayType,
- Store = _workContextAccessor.WorkContext.CurrentStore
+ Customer = _contextAccessor.WorkContext.CurrentCustomer,
+ Currency = _contextAccessor.WorkContext.WorkingCurrency,
+ Language = _contextAccessor.WorkContext.WorkingLanguage,
+ TaxDisplayType = _contextAccessor.WorkContext.TaxDisplayType,
+ Store = _contextAccessor.StoreContext.CurrentStore
})
: null;
@@ -524,7 +524,7 @@ public class ActionCartController : BasePublicController
[HttpPost]
public virtual async Task<IActionResult> UpdateItemCart(ProductDetailsCart model)
{
- var cart = _workContextAccessor.WorkContext.CurrentCustomer.ShoppingCartItems.FirstOrDefault(sci =>
+ var cart = _contextAccessor.WorkContext.CurrentCustomer.ShoppingCartItems.FirstOrDefault(sci =>
sci.Id == model.ShoppingCartItemId);
if (cart == null)
return Json(new {
@@ -574,7 +574,7 @@ public class ActionCartController : BasePublicController
if (double.TryParse(model.CustomerEnteredPrice, out var customerEnteredPrice))
customerEnteredPriceConverted =
await _currencyService.ConvertToPrimaryStoreCurrency(customerEnteredPrice,
- _workContextAccessor.WorkContext.WorkingCurrency);
+ _contextAccessor.WorkContext.WorkingCurrency);
#endregion
@@ -641,7 +641,7 @@ public class ActionCartController : BasePublicController
var warehouseId = _shoppingCartSettings.AllowToSelectWarehouse ? model.WarehouseId : cart.WarehouseId;
//update existing item
- addToCartWarnings.AddRange(await _shoppingCartService.UpdateShoppingCartItem(_workContextAccessor.WorkContext.CurrentCustomer,
+ addToCartWarnings.AddRange(await _shoppingCartService.UpdateShoppingCartItem(_contextAccessor.WorkContext.CurrentCustomer,
cart.Id, warehouseId, attributes, customerEnteredPriceConverted,
rentalStartDate, rentalEndDate, model.EnteredQuantity));
@@ -661,7 +661,7 @@ public class ActionCartController : BasePublicController
[HttpGet]
public virtual async Task<IActionResult> GetItemCart(string shoppingCartId)
{
- var cart = _workContextAccessor.WorkContext.CurrentCustomer.ShoppingCartItems.FirstOrDefault(sci => sci.Id == shoppingCartId);
+ var cart = _contextAccessor.WorkContext.CurrentCustomer.ShoppingCartItems.FirstOrDefault(sci => sci.Id == shoppingCartId);
if (cart == null)
return Json(new {
success = false,
@@ -693,13 +693,13 @@ public class ActionCartController : BasePublicController
redirect = Url.RouteUrl("HomePage")
});
return Json(new {
- redirect = Url.RouteUrl("Product", new { SeName = product.GetSeName(_workContextAccessor.WorkContext.WorkingLanguage.Id) })
+ redirect = Url.RouteUrl("Product", new { SeName = product.GetSeName(_contextAccessor.WorkContext.WorkingLanguage.Id) })
});
}
//prepare the model
var model = await _mediator.Send(new GetProductDetailsPage {
- Store = _workContextAccessor.WorkContext.CurrentStore,
+ Store = _contextAccessor.StoreContext.CurrentStore,
Product = product,
UpdateCartItem = cart
});
@@ -714,7 +714,7 @@ public class ActionCartController : BasePublicController
public virtual async Task<IActionResult> AddBid(AddBidModel model,
[FromServices] IAuctionService auctionService)
{
- var customer = _workContextAccessor.WorkContext.CurrentCustomer;
+ var customer = _contextAccessor.WorkContext.CurrentCustomer;
if (!await _groupService.IsRegistered(customer))
return Json(new {
success = false,
@@ -745,7 +745,7 @@ public class ActionCartController : BasePublicController
var warehouseId = _shoppingCartSettings.AllowToSelectWarehouse
? model.WarehouseId
- : _workContextAccessor.WorkContext.CurrentStore.DefaultWarehouseId;
+ : _contextAccessor.StoreContext.CurrentStore.DefaultWarehouseId;
var shoppingCartItem = new ShoppingCartItem {
Attributes = new List<CustomAttribute>(),
@@ -753,7 +753,7 @@ public class ActionCartController : BasePublicController
ProductId = product.Id,
WarehouseId = warehouseId,
ShoppingCartTypeId = ShoppingCartType.Auctions,
- StoreId = _workContextAccessor.WorkContext.CurrentStore.Id,
+ StoreId = _contextAccessor.StoreContext.CurrentStore.Id,
EnteredPrice = bid,
Quantity = 1
};
@@ -773,7 +773,7 @@ public class ActionCartController : BasePublicController
}
//insert new bid
- await auctionService.NewBid(customer, product, _workContextAccessor.WorkContext.CurrentStore, _workContextAccessor.WorkContext.WorkingLanguage,
+ await auctionService.NewBid(customer, product, _contextAccessor.StoreContext.CurrentStore, _contextAccessor.WorkContext.WorkingLanguage,
warehouseId, bid);
var addtoCartModel = await _mediator.Send(new GetAddToCart {
@@ -781,10 +781,10 @@ public class ActionCartController : BasePublicController
Customer = customer,
Quantity = 1,
CartType = ShoppingCartType.Auctions,
- Currency = _workContextAccessor.WorkContext.WorkingCurrency,
- Store = _workContextAccessor.WorkContext.CurrentStore,
- Language = _workContextAccessor.WorkContext.WorkingLanguage,
- TaxDisplayType = _workContextAccessor.WorkContext.TaxDisplayType
+ Currency = _contextAccessor.WorkContext.WorkingCurrency,
+ Store = _contextAccessor.StoreContext.CurrentStore,
+ Language = _contextAccessor.WorkContext.WorkingLanguage,
+ TaxDisplayType = _contextAccessor.WorkContext.TaxDisplayType
});
return Json(new {
diff --git a/src/Web/Grand.Web/Controllers/BlogController.cs b/src/Web/Grand.Web/Controllers/BlogController.cs
index 4de063c03..a65637e9b 100644
--- a/src/Web/Grand.Web/Controllers/BlogController.cs
+++ b/src/Web/Grand.Web/Controllers/BlogController.cs
@@ -29,14 +29,14 @@ public class BlogController : BasePublicController
IMediator mediator,
IBlogService blogService,
ITranslationService translationService,
- IWorkContextAccessor workContextAccessor,
+ IContextAccessor contextAccessor,
BlogSettings blogSettings)
{
_mediator = mediator;
_blogService = blogService;
_translationService = translationService;
_blogSettings = blogSettings;
- _workContextAccessor = workContextAccessor;
+ _contextAccessor = contextAccessor;
}
#endregion
@@ -46,7 +46,7 @@ public class BlogController : BasePublicController
private readonly IMediator _mediator;
private readonly IBlogService _blogService;
private readonly ITranslationService _translationService;
- private readonly IWorkContextAccessor _workContextAccessor;
+ private readonly IContextAccessor _contextAccessor;
private readonly BlogSettings _blogSettings;
#endregion
@@ -124,7 +124,7 @@ public class BlogController : BasePublicController
return RedirectToRoute("HomePage");
//Store acl
- if (!aclService.Authorize(blogPost, _workContextAccessor.WorkContext.CurrentStore.Id))
+ if (!aclService.Authorize(blogPost, _contextAccessor.StoreContext.CurrentStore.Id))
return InvokeHttp404();
var model = await _mediator.Send(new GetBlogPost { BlogPost = blogPost });
@@ -152,7 +152,7 @@ public class BlogController : BasePublicController
success = false
});
- if (!aclService.Authorize(blogPost, _workContextAccessor.WorkContext.CurrentStore.Id))
+ if (!aclService.Authorize(blogPost, _contextAccessor.StoreContext.CurrentStore.Id))
return Json(new {
success = false
});
@@ -171,7 +171,7 @@ public class BlogController : BasePublicController
blogComment.CommentText,
CreatedOn = HttpContext.RequestServices.GetService<IDateTimeService>()
.ConvertToUserTime(blogComment.CreatedOnUtc, DateTimeKind.Utc),
- CustomerName = _workContextAccessor.WorkContext.CurrentCustomer.FormatUserName(HttpContext.RequestServices
+ CustomerName = _contextAccessor.WorkContext.CurrentCustomer.FormatUserName(HttpContext.RequestServices
.GetService<CustomerSettings>().CustomerNameFormat)
}
});
diff --git a/src/Web/Grand.Web/Controllers/CatalogController.cs b/src/Web/Grand.Web/Controllers/CatalogController.cs
index 736e6a689..7ebfa150a 100644
--- a/src/Web/Grand.Web/Controllers/CatalogController.cs
+++ b/src/Web/Grand.Web/Controllers/CatalogController.cs
@@ -35,7 +35,7 @@ public class CatalogController : BasePublicController
ICategoryService categoryService,
IBrandService brandService,
ICollectionService collectionService,
- IWorkContextAccessor workContextAccessor,
+ IContextAccessor contextAccessor,
IGroupService groupService,
ITranslationService translationService,
IAclService aclService,
@@ -47,7 +47,7 @@ public class CatalogController : BasePublicController
_categoryService = categoryService;
_brandService = brandService;
_collectionService = collectionService;
- _workContextAccessor = workContextAccessor;
+ _contextAccessor = contextAccessor;
_groupService = groupService;
_translationService = translationService;
_aclService = aclService;
@@ -64,7 +64,7 @@ public class CatalogController : BasePublicController
private readonly ICategoryService _categoryService;
private readonly IBrandService _brandService;
private readonly ICollectionService _collectionService;
- private readonly IWorkContextAccessor _workContextAccessor;
+ private readonly IContextAccessor _contextAccessor;
private readonly IGroupService _groupService;
private readonly ITranslationService _translationService;
private readonly IAclService _aclService;
@@ -99,7 +99,7 @@ public class CatalogController : BasePublicController
if (category == null)
return InvokeHttp404();
- var customer = _workContextAccessor.WorkContext.CurrentCustomer;
+ var customer = _contextAccessor.WorkContext.CurrentCustomer;
//Check whether the current user has a "Manage catalog" permission
//It allows him to preview a category before publishing
@@ -111,7 +111,7 @@ public class CatalogController : BasePublicController
return InvokeHttp404();
//Store access
- if (!_aclService.Authorize(category, _workContextAccessor.WorkContext.CurrentStore.Id))
+ if (!_aclService.Authorize(category, _contextAccessor.StoreContext.CurrentStore.Id))
return InvokeHttp404();
//display "edit" (manage) link
@@ -123,10 +123,10 @@ public class CatalogController : BasePublicController
var model = await _mediator.Send(new GetCategory {
Category = category,
Command = command,
- Currency = _workContextAccessor.WorkContext.WorkingCurrency,
- Customer = _workContextAccessor.WorkContext.CurrentCustomer,
- Language = _workContextAccessor.WorkContext.WorkingLanguage,
- Store = _workContextAccessor.WorkContext.CurrentStore
+ Currency = _contextAccessor.WorkContext.WorkingCurrency,
+ Customer = _contextAccessor.WorkContext.CurrentCustomer,
+ Language = _contextAccessor.WorkContext.WorkingLanguage,
+ Store = _contextAccessor.StoreContext.CurrentStore
});
//layout
@@ -140,9 +140,9 @@ public class CatalogController : BasePublicController
public virtual async Task<IActionResult> CategoryAll(CategoryPagingModel command)
{
var model = await _mediator.Send(new GetCategoryAll {
- Customer = _workContextAccessor.WorkContext.CurrentCustomer,
- Language = _workContextAccessor.WorkContext.WorkingLanguage,
- Store = _workContextAccessor.WorkContext.CurrentStore,
+ Customer = _contextAccessor.WorkContext.CurrentCustomer,
+ Language = _contextAccessor.WorkContext.WorkingLanguage,
+ Store = _contextAccessor.StoreContext.CurrentStore,
Command = command
});
return View(model);
@@ -159,7 +159,7 @@ public class CatalogController : BasePublicController
if (brand == null)
return InvokeHttp404();
- var customer = _workContextAccessor.WorkContext.CurrentCustomer;
+ var customer = _contextAccessor.WorkContext.CurrentCustomer;
//Check whether the current user has a "Manage catalog" permission
//It allows him to preview a collection before publishing
@@ -171,7 +171,7 @@ public class CatalogController : BasePublicController
return InvokeHttp404();
//Store access
- if (!_aclService.Authorize(brand, _workContextAccessor.WorkContext.CurrentStore.Id))
+ if (!_aclService.Authorize(brand, _contextAccessor.StoreContext.CurrentStore.Id))
return InvokeHttp404();
//display "edit" (manage) link
@@ -182,11 +182,11 @@ public class CatalogController : BasePublicController
//model
var model = await _mediator.Send(new GetBrand {
Command = command,
- Currency = _workContextAccessor.WorkContext.WorkingCurrency,
- Customer = _workContextAccessor.WorkContext.CurrentCustomer,
- Language = _workContextAccessor.WorkContext.WorkingLanguage,
+ Currency = _contextAccessor.WorkContext.WorkingCurrency,
+ Customer = _contextAccessor.WorkContext.CurrentCustomer,
+ Language = _contextAccessor.WorkContext.WorkingLanguage,
Brand = brand,
- Store = _workContextAccessor.WorkContext.CurrentStore
+ Store = _contextAccessor.StoreContext.CurrentStore
});
//template
@@ -199,9 +199,9 @@ public class CatalogController : BasePublicController
public virtual async Task<IActionResult> BrandAll(BrandPagingModel command)
{
var model = await _mediator.Send(new GetBrandAll {
- Customer = _workContextAccessor.WorkContext.CurrentCustomer,
- Language = _workContextAccessor.WorkContext.WorkingLanguage,
- Store = _workContextAccessor.WorkContext.CurrentStore,
+ Customer = _contextAccessor.WorkContext.CurrentCustomer,
+ Language = _contextAccessor.WorkContext.WorkingLanguage,
+ Store = _contextAccessor.StoreContext.CurrentStore,
Command = command
});
return View(model);
@@ -218,7 +218,7 @@ public class CatalogController : BasePublicController
if (collection == null)
return InvokeHttp404();
- var customer = _workContextAccessor.WorkContext.CurrentCustomer;
+ var customer = _contextAccessor.WorkContext.CurrentCustomer;
//Check whether the current user has a "Manage catalog" permission
//It allows him to preview a collection before publishing
@@ -231,7 +231,7 @@ public class CatalogController : BasePublicController
return InvokeHttp404();
//Store access
- if (!_aclService.Authorize(collection, _workContextAccessor.WorkContext.CurrentStore.Id))
+ if (!_aclService.Authorize(collection, _contextAccessor.StoreContext.CurrentStore.Id))
return InvokeHttp404();
//display "edit" (manage) link
@@ -242,11 +242,11 @@ public class CatalogController : BasePublicController
//model
var model = await _mediator.Send(new GetCollection {
Command = command,
- Currency = _workContextAccessor.WorkContext.WorkingCurrency,
- Customer = _workContextAccessor.WorkContext.CurrentCustomer,
- Language = _workContextAccessor.WorkContext.WorkingLanguage,
+ Currency = _contextAccessor.WorkContext.WorkingCurrency,
+ Customer = _contextAccessor.WorkContext.CurrentCustomer,
+ Language = _contextAccessor.WorkContext.WorkingLanguage,
Collection = collection,
- Store = _workContextAccessor.WorkContext.CurrentStore
+ Store = _contextAccessor.StoreContext.CurrentStore
});
//template
@@ -260,9 +260,9 @@ public class CatalogController : BasePublicController
public virtual async Task<IActionResult> CollectionAll(CollectionPagingModel command)
{
var model = await _mediator.Send(new GetCollectionAll {
- Customer = _workContextAccessor.WorkContext.CurrentCustomer,
- Language = _workContextAccessor.WorkContext.WorkingLanguage,
- Store = _workContextAccessor.WorkContext.CurrentStore,
+ Customer = _contextAccessor.WorkContext.CurrentCustomer,
+ Language = _contextAccessor.WorkContext.WorkingLanguage,
+ Store = _contextAccessor.StoreContext.CurrentStore,
Command = command
});
return View(model);
@@ -283,7 +283,7 @@ public class CatalogController : BasePublicController
if (!vendor.Active)
return InvokeHttp404();
- var customer = _workContextAccessor.WorkContext.CurrentCustomer;
+ var customer = _contextAccessor.WorkContext.CurrentCustomer;
//display "edit" (manage) link
if (await _permissionService.Authorize(StandardPermission.ManageAccessAdminPanel, customer) &&
@@ -293,9 +293,9 @@ public class CatalogController : BasePublicController
var model = await _mediator.Send(new GetVendor {
Command = command,
Vendor = vendor,
- Language = _workContextAccessor.WorkContext.WorkingLanguage,
- Customer = _workContextAccessor.WorkContext.CurrentCustomer,
- Store = _workContextAccessor.WorkContext.CurrentStore
+ Language = _contextAccessor.WorkContext.WorkingLanguage,
+ Customer = _contextAccessor.WorkContext.CurrentCustomer,
+ Store = _contextAccessor.StoreContext.CurrentStore
});
//review
model.VendorReviewOverview = PrepareVendorReviewOverviewModel(vendor);
@@ -311,7 +311,7 @@ public class CatalogController : BasePublicController
return RedirectToRoute("HomePage");
var model = await _mediator.Send(
- new GetVendorAll { Language = _workContextAccessor.WorkContext.WorkingLanguage, Command = command });
+ new GetVendorAll { Language = _contextAccessor.WorkContext.WorkingLanguage, Command = command });
return View(model);
}
@@ -331,7 +331,7 @@ public class CatalogController : BasePublicController
if (ModelState.IsValid)
{
var vendorReview = await _mediator.Send(new InsertVendorReviewCommand
- { Vendor = vendor, Store = _workContextAccessor.WorkContext.CurrentStore, Model = model });
+ { Vendor = vendor, Store = _contextAccessor.StoreContext.CurrentStore, Model = model });
//raise event
if (vendorReview.IsApproved)
await _mediator.Publish(new VendorReviewApprovedEvent(vendorReview));
@@ -374,7 +374,7 @@ public class CatalogController : BasePublicController
if (vendorReview == null)
throw new ArgumentException("No vendor review found with the specified id");
- var customer = _workContextAccessor.WorkContext.CurrentCustomer;
+ var customer = _contextAccessor.WorkContext.CurrentCustomer;
if (await _groupService.IsGuest(customer) && !_vendorSettings.AllowAnonymousUsersToReviewVendor)
return Json(new {
@@ -392,7 +392,7 @@ public class CatalogController : BasePublicController
});
vendorReview = await _mediator.Send(new SetVendorReviewHelpfulnessCommand {
- Customer = _workContextAccessor.WorkContext.CurrentCustomer,
+ Customer = _contextAccessor.WorkContext.CurrentCustomer,
Vendor = vendor,
Review = vendorReview,
Washelpful = washelpful
@@ -419,10 +419,10 @@ public class CatalogController : BasePublicController
var model = await _mediator.Send(new GetProductsByTag {
Command = command,
- Language = _workContextAccessor.WorkContext.WorkingLanguage,
+ Language = _contextAccessor.WorkContext.WorkingLanguage,
ProductTag = productTag,
- Customer = _workContextAccessor.WorkContext.CurrentCustomer,
- Store = _workContextAccessor.WorkContext.CurrentStore
+ Customer = _contextAccessor.WorkContext.CurrentCustomer,
+ Store = _contextAccessor.StoreContext.CurrentStore
});
return View(model);
}
@@ -437,10 +437,10 @@ public class CatalogController : BasePublicController
var model = await _mediator.Send(new GetProductsByTag {
Command = command,
- Language = _workContextAccessor.WorkContext.WorkingLanguage,
+ Language = _contextAccessor.WorkContext.WorkingLanguage,
ProductTag = productTag,
- Customer = _workContextAccessor.WorkContext.CurrentCustomer,
- Store = _workContextAccessor.WorkContext.CurrentStore
+ Customer = _contextAccessor.WorkContext.CurrentCustomer,
+ Store = _contextAccessor.StoreContext.CurrentStore
});
return View("ProductsByTag", model);
}
@@ -449,8 +449,8 @@ public class CatalogController : BasePublicController
public virtual async Task<IActionResult> ProductTagsAll()
{
var model = await _mediator.Send(new GetProductTagsAll {
- Language = _workContextAccessor.WorkContext.WorkingLanguage,
- Store = _workContextAccessor.WorkContext.CurrentStore
+ Language = _contextAccessor.WorkContext.WorkingLanguage,
+ Store = _contextAccessor.StoreContext.CurrentStore
});
return View(model);
}
@@ -472,12 +472,12 @@ public class CatalogController : BasePublicController
var isSearchTermSpecified = HttpContext.Request.Query.ContainsKey("q");
var searchModel = await _mediator.Send(new GetSearch {
Command = command,
- Currency = _workContextAccessor.WorkContext.WorkingCurrency,
- Customer = _workContextAccessor.WorkContext.CurrentCustomer,
+ Currency = _contextAccessor.WorkContext.WorkingCurrency,
+ Customer = _contextAccessor.WorkContext.CurrentCustomer,
IsSearchTermSpecified = isSearchTermSpecified,
- Language = _workContextAccessor.WorkContext.WorkingLanguage,
+ Language = _contextAccessor.WorkContext.WorkingLanguage,
Model = model,
- Store = _workContextAccessor.WorkContext.CurrentStore
+ Store = _contextAccessor.StoreContext.CurrentStore
});
return View(searchModel);
}
@@ -492,10 +492,10 @@ public class CatalogController : BasePublicController
var result = await _mediator.Send(new GetSearchAutoComplete {
CategoryId = categoryId,
Term = term.Trim(),
- Customer = _workContextAccessor.WorkContext.CurrentCustomer,
- Store = _workContextAccessor.WorkContext.CurrentStore,
- Language = _workContextAccessor.WorkContext.WorkingLanguage,
- Currency = _workContextAccessor.WorkContext.WorkingCurrency
+ Customer = _contextAccessor.WorkContext.CurrentCustomer,
+ Store = _contextAccessor.StoreContext.CurrentStore,
+ Language = _contextAccessor.WorkContext.WorkingLanguage,
+ Currency = _contextAccessor.WorkContext.WorkingCurrency
});
return Json(result);
}
diff --git a/src/Web/Grand.Web/Controllers/CheckoutController.cs b/src/Web/Grand.Web/Controllers/CheckoutController.cs
index 4b9deb1f2..fb2ce939b 100644
--- a/src/Web/Grand.Web/Controllers/CheckoutController.cs
+++ b/src/Web/Grand.Web/Controllers/CheckoutController.cs
@@ -37,7 +37,7 @@ public class CheckoutController : BasePublicController
#region Constructors
public CheckoutController(
- IWorkContextAccessor workContextAccessor,
+ IContextAccessor contextAccessor,
ITranslationService translationService,
ICustomerService customerService,
IGroupService groupService,
@@ -57,7 +57,7 @@ public class CheckoutController : BasePublicController
ShippingSettings shippingSettings,
AddressSettings addressSettings)
{
- _workContextAccessor = workContextAccessor;
+ _contextAccessor = contextAccessor;
_translationService = translationService;
_customerService = customerService;
_groupService = groupService;
@@ -83,9 +83,9 @@ public class CheckoutController : BasePublicController
[HttpGet]
public virtual async Task<IActionResult> Index()
{
- var customer = _workContextAccessor.WorkContext.CurrentCustomer;
+ var customer = _contextAccessor.WorkContext.CurrentCustomer;
- var cart = await _shoppingCartService.GetShoppingCart(_workContextAccessor.WorkContext.CurrentStore.Id,
+ var cart = await _shoppingCartService.GetShoppingCart(_contextAccessor.StoreContext.CurrentStore.Id,
ShoppingCartType.ShoppingCart, ShoppingCartType.Auctions);
if (!cart.Any())
@@ -95,10 +95,10 @@ public class CheckoutController : BasePublicController
return Challenge();
//reset checkout data
- await _customerService.ResetCheckoutData(customer, _workContextAccessor.WorkContext.CurrentStore.Id);
+ await _customerService.ResetCheckoutData(customer, _contextAccessor.StoreContext.CurrentStore.Id);
//validation (cart)
- var checkoutAttributes = customer.GetUserFieldFromEntity<List<CustomAttribute>>(SystemCustomerFieldNames.CheckoutAttributes, _workContextAccessor.WorkContext.CurrentStore.Id);
+ var checkoutAttributes = customer.GetUserFieldFromEntity<List<CustomAttribute>>(SystemCustomerFieldNames.CheckoutAttributes, _contextAccessor.StoreContext.CurrentStore.Id);
var scWarnings = await _shoppingCartValidator.GetShoppingCartWarnings(cart, checkoutAttributes, true, true);
if (scWarnings.Any())
return RedirectToRoute("ShoppingCart", new { checkoutAttributes = true });
@@ -121,20 +121,20 @@ public class CheckoutController : BasePublicController
public virtual async Task<IActionResult> Start()
{
//validation
- var cart = await _shoppingCartService.GetShoppingCart(_workContextAccessor.WorkContext.CurrentStore.Id,
+ var cart = await _shoppingCartService.GetShoppingCart(_contextAccessor.StoreContext.CurrentStore.Id,
ShoppingCartType.ShoppingCart, ShoppingCartType.Auctions);
if (!cart.Any())
return RedirectToRoute("ShoppingCart");
- if (await _groupService.IsGuest(_workContextAccessor.WorkContext.CurrentCustomer) && !_orderSettings.AnonymousCheckoutAllowed)
+ if (await _groupService.IsGuest(_contextAccessor.WorkContext.CurrentCustomer) && !_orderSettings.AnonymousCheckoutAllowed)
return Challenge();
//validation (each shopping cart item)
foreach (var sci in cart)
{
var product = await _productService.GetProductById(sci.ProductId);
- var sciWarnings = await _shoppingCartValidator.GetShoppingCartItemWarnings(_workContextAccessor.WorkContext.CurrentCustomer,
+ var sciWarnings = await _shoppingCartValidator.GetShoppingCartItemWarnings(_contextAccessor.WorkContext.CurrentCustomer,
sci, product, new ShoppingCartValidatorOptions());
if (sciWarnings.Any())
return RedirectToRoute("ShoppingCart", new { checkoutAttributes = true });
@@ -145,17 +145,17 @@ public class CheckoutController : BasePublicController
ShippingRequired = requiresShipping,
BillingAddress = await _mediator.Send(new GetBillingAddress {
Cart = cart,
- Currency = _workContextAccessor.WorkContext.WorkingCurrency,
- Customer = _workContextAccessor.WorkContext.CurrentCustomer,
- Language = _workContextAccessor.WorkContext.WorkingLanguage,
- Store = _workContextAccessor.WorkContext.CurrentStore,
+ Currency = _contextAccessor.WorkContext.WorkingCurrency,
+ Customer = _contextAccessor.WorkContext.CurrentCustomer,
+ Language = _contextAccessor.WorkContext.WorkingLanguage,
+ Store = _contextAccessor.StoreContext.CurrentStore,
PrePopulateNewAddressWithCustomerFields = true
}),
ShippingAddress = await _mediator.Send(new GetShippingAddress {
- Currency = _workContextAccessor.WorkContext.WorkingCurrency,
- Customer = _workContextAccessor.WorkContext.CurrentCustomer,
- Language = _workContextAccessor.WorkContext.WorkingLanguage,
- Store = _workContextAccessor.WorkContext.CurrentStore,
+ Currency = _contextAccessor.WorkContext.WorkingCurrency,
+ Customer = _contextAccessor.WorkContext.CurrentCustomer,
+ Language = _contextAccessor.WorkContext.WorkingLanguage,
+ Store = _contextAccessor.StoreContext.CurrentStore,
PrePopulateNewAddressWithCustomerFields = true
})
};
@@ -173,7 +173,7 @@ public class CheckoutController : BasePublicController
try
{
//validation
- var cart = await _shoppingCartService.GetShoppingCart(_workContextAccessor.WorkContext.CurrentStore.Id,
+ var cart = await _shoppingCartService.GetShoppingCart(_contextAccessor.StoreContext.CurrentStore.Id,
ShoppingCartType.ShoppingCart, ShoppingCartType.Auctions);
await CartValidate(cart);
@@ -181,10 +181,10 @@ public class CheckoutController : BasePublicController
{
//existing address
var address =
- _workContextAccessor.WorkContext.CurrentCustomer.Addresses.FirstOrDefault(a => a.Id == model.BillingAddressId);
- _workContextAccessor.WorkContext.CurrentCustomer.BillingAddress =
+ _contextAccessor.WorkContext.CurrentCustomer.Addresses.FirstOrDefault(a => a.Id == model.BillingAddressId);
+ _contextAccessor.WorkContext.CurrentCustomer.BillingAddress =
address ?? throw new Exception("Address can't be loaded");
- await _customerService.UpdateBillingAddress(address, _workContextAccessor.WorkContext.CurrentCustomer.Id);
+ await _customerService.UpdateBillingAddress(address, _contextAccessor.WorkContext.CurrentCustomer.Id);
}
else
{
@@ -193,10 +193,10 @@ public class CheckoutController : BasePublicController
//model is not valid. redisplay the form with errors
var billingAddressModel = await _mediator.Send(new GetBillingAddress {
Cart = cart,
- Currency = _workContextAccessor.WorkContext.WorkingCurrency,
- Customer = _workContextAccessor.WorkContext.CurrentCustomer,
- Language = _workContextAccessor.WorkContext.WorkingLanguage,
- Store = _workContextAccessor.WorkContext.CurrentStore,
+ Currency = _contextAccessor.WorkContext.WorkingCurrency,
+ Customer = _contextAccessor.WorkContext.CurrentCustomer,
+ Language = _contextAccessor.WorkContext.WorkingLanguage,
+ Store = _contextAccessor.StoreContext.CurrentStore,
SelectedCountryId = model.BillingNewAddress.CountryId,
OverrideAttributes = await _mediator.Send(new GetParseCustomAddressAttributes
{ SelectedAttributes = model.BillingNewAddress.SelectedAttributes })
@@ -214,7 +214,7 @@ public class CheckoutController : BasePublicController
}
//try to find an address with the same values (don't duplicate records)
- var address = _workContextAccessor.WorkContext.CurrentCustomer.Addresses.ToList().FindAddress(
+ var address = _contextAccessor.WorkContext.CurrentCustomer.Addresses.ToList().FindAddress(
model.BillingNewAddress.FirstName, model.BillingNewAddress.LastName,
model.BillingNewAddress.PhoneNumber,
model.BillingNewAddress.Email, model.BillingNewAddress.FaxNumber,
@@ -227,32 +227,32 @@ public class CheckoutController : BasePublicController
{
//address is not found. create a new one
address =
- await _groupService.IsGuest(_workContextAccessor.WorkContext.CurrentCustomer)
+ await _groupService.IsGuest(_contextAccessor.WorkContext.CurrentCustomer)
? model.BillingNewAddress.ToEntity()
- : model.BillingNewAddress.ToEntity(_workContextAccessor.WorkContext.CurrentCustomer, addressSettings);
+ : model.BillingNewAddress.ToEntity(_contextAccessor.WorkContext.CurrentCustomer, addressSettings);
address.Attributes = await _mediator.Send(new GetParseCustomAddressAttributes
{ SelectedAttributes = model.BillingNewAddress.SelectedAttributes });
address.AddressType = _addressSettings.AddressTypeEnabled ? AddressType.Billing : AddressType.Any;
- _workContextAccessor.WorkContext.CurrentCustomer.Addresses.Add(address);
- await _customerService.InsertAddress(address, _workContextAccessor.WorkContext.CurrentCustomer.Id);
+ _contextAccessor.WorkContext.CurrentCustomer.Addresses.Add(address);
+ await _customerService.InsertAddress(address, _contextAccessor.WorkContext.CurrentCustomer.Id);
}
- _workContextAccessor.WorkContext.CurrentCustomer.BillingAddress = address;
- await _customerService.UpdateBillingAddress(address, _workContextAccessor.WorkContext.CurrentCustomer.Id);
+ _contextAccessor.WorkContext.CurrentCustomer.BillingAddress = address;
+ await _customerService.UpdateBillingAddress(address, _contextAccessor.WorkContext.CurrentCustomer.Id);
}
//load next step
if (cart.RequiresShipping())
return await LoadStepAfterBillingAddress(cart);
//shipping is not required
- _workContextAccessor.WorkContext.CurrentCustomer.ShippingAddress = null;
- await _customerService.UpdateCustomerField(_workContextAccessor.WorkContext.CurrentCustomer, x => x.ShippingAddress,
+ _contextAccessor.WorkContext.CurrentCustomer.ShippingAddress = null;
+ await _customerService.UpdateCustomerField(_contextAccessor.WorkContext.CurrentCustomer, x => x.ShippingAddress,
null);
- await _customerService.UpdateUserField<ShippingOption>(_workContextAccessor.WorkContext.CurrentCustomer,
- SystemCustomerFieldNames.SelectedShippingOption, null, _workContextAccessor.WorkContext.CurrentStore.Id);
+ await _customerService.UpdateUserField<ShippingOption>(_contextAccessor.WorkContext.CurrentCustomer,
+ SystemCustomerFieldNames.SelectedShippingOption, null, _contextAccessor.StoreContext.CurrentStore.Id);
//load next step
return await LoadStepAfterShippingMethod(cart);
}
@@ -271,7 +271,7 @@ public class CheckoutController : BasePublicController
try
{
//validation
- var cart = await _shoppingCartService.GetShoppingCart(_workContextAccessor.WorkContext.CurrentStore.Id,
+ var cart = await _shoppingCartService.GetShoppingCart(_contextAccessor.StoreContext.CurrentStore.Id,
ShoppingCartType.ShoppingCart, ShoppingCartType.Auctions);
await CartValidate(cart);
@@ -286,19 +286,19 @@ public class CheckoutController : BasePublicController
{
//customer decided to pick up in store
//no shipping address selected
- _workContextAccessor.WorkContext.CurrentCustomer.ShippingAddress = null;
- await _customerService.UpdateCustomerField(_workContextAccessor.WorkContext.CurrentCustomer, x => x.ShippingAddress,
+ _contextAccessor.WorkContext.CurrentCustomer.ShippingAddress = null;
+ await _customerService.UpdateCustomerField(_contextAccessor.WorkContext.CurrentCustomer, x => x.ShippingAddress,
null);
//clear shipping option XML/Description
- await _customerService.UpdateUserField(_workContextAccessor.WorkContext.CurrentCustomer,
- SystemCustomerFieldNames.ShippingOptionAttribute, "", _workContextAccessor.WorkContext.CurrentStore.Id);
- await _customerService.UpdateUserField(_workContextAccessor.WorkContext.CurrentCustomer,
+ await _customerService.UpdateUserField(_contextAccessor.WorkContext.CurrentCustomer,
+ SystemCustomerFieldNames.ShippingOptionAttribute, "", _contextAccessor.StoreContext.CurrentStore.Id);
+ await _customerService.UpdateUserField(_contextAccessor.WorkContext.CurrentCustomer,
SystemCustomerFieldNames.ShippingOptionAttributeDescription, "",
- _workContextAccessor.WorkContext.CurrentStore.Id);
+ _contextAccessor.StoreContext.CurrentStore.Id);
var pickupPoints =
- await _pickupPointService.LoadActivePickupPoints(_workContextAccessor.WorkContext.CurrentStore.Id);
+ await _pickupPointService.LoadActivePickupPoints(_contextAccessor.StoreContext.CurrentStore.Id);
var selectedPoint = pickupPoints.FirstOrDefault(x => x.Id.Equals(model.PickupPointId));
if (selectedPoint == null)
throw new Exception("Pickup point is not allowed");
@@ -312,21 +312,21 @@ public class CheckoutController : BasePublicController
ShippingRateProviderSystemName = $"PickupPoint_{selectedPoint.Id}"
};
- await _customerService.UpdateUserField(_workContextAccessor.WorkContext.CurrentCustomer,
+ await _customerService.UpdateUserField(_contextAccessor.WorkContext.CurrentCustomer,
SystemCustomerFieldNames.SelectedShippingOption,
pickUpInStoreShippingOption,
- _workContextAccessor.WorkContext.CurrentStore.Id);
+ _contextAccessor.StoreContext.CurrentStore.Id);
- await _customerService.UpdateUserField(_workContextAccessor.WorkContext.CurrentCustomer,
+ await _customerService.UpdateUserField(_contextAccessor.WorkContext.CurrentCustomer,
SystemCustomerFieldNames.SelectedPickupPoint,
selectedPoint.Id,
- _workContextAccessor.WorkContext.CurrentStore.Id);
+ _contextAccessor.StoreContext.CurrentStore.Id);
}
else
//set value indicating that "pick up in store" option has not been chosen
{
- await _customerService.UpdateUserField(_workContextAccessor.WorkContext.CurrentCustomer,
- SystemCustomerFieldNames.SelectedPickupPoint, "", _workContextAccessor.WorkContext.CurrentStore.Id);
+ await _customerService.UpdateUserField(_contextAccessor.WorkContext.CurrentCustomer,
+ SystemCustomerFieldNames.SelectedPickupPoint, "", _contextAccessor.StoreContext.CurrentStore.Id);
}
}
@@ -336,12 +336,12 @@ public class CheckoutController : BasePublicController
{
//existing address
var address =
- _workContextAccessor.WorkContext.CurrentCustomer.Addresses.FirstOrDefault(a => a.Id == model.ShippingAddressId);
+ _contextAccessor.WorkContext.CurrentCustomer.Addresses.FirstOrDefault(a => a.Id == model.ShippingAddressId);
if (address == null)
throw new Exception("Address can't be loaded");
- _workContextAccessor.WorkContext.CurrentCustomer.ShippingAddress = address;
- await _customerService.UpdateShippingAddress(address, _workContextAccessor.WorkContext.CurrentCustomer.Id);
+ _contextAccessor.WorkContext.CurrentCustomer.ShippingAddress = address;
+ await _customerService.UpdateShippingAddress(address, _contextAccessor.WorkContext.CurrentCustomer.Id);
}
else
{
@@ -349,10 +349,10 @@ public class CheckoutController : BasePublicController
{
//model is not valid. redisplay the form with errors
var shippingAddressModel = await _mediator.Send(new GetShippingAddress {
- Currency = _workContextAccessor.WorkContext.WorkingCurrency,
- Customer = _workContextAccessor.WorkContext.CurrentCustomer,
- Language = _workContextAccessor.WorkContext.WorkingLanguage,
- Store = _workContextAccessor.WorkContext.CurrentStore,
+ Currency = _contextAccessor.WorkContext.WorkingCurrency,
+ Customer = _contextAccessor.WorkContext.CurrentCustomer,
+ Language = _contextAccessor.WorkContext.WorkingLanguage,
+ Store = _contextAccessor.StoreContext.CurrentStore,
SelectedCountryId = model.ShippingNewAddress.CountryId,
OverrideAttributes = await _mediator.Send(new GetParseCustomAddressAttributes
{ SelectedAttributes = model.ShippingNewAddress.SelectedAttributes })
@@ -370,7 +370,7 @@ public class CheckoutController : BasePublicController
}
//try to find an address with the same values (don't duplicate records)
- var address = _workContextAccessor.WorkContext.CurrentCustomer.Addresses.ToList().FindAddress(
+ var address = _contextAccessor.WorkContext.CurrentCustomer.Addresses.ToList().FindAddress(
model.ShippingNewAddress.FirstName, model.ShippingNewAddress.LastName,
model.ShippingNewAddress.PhoneNumber,
model.ShippingNewAddress.Email, model.ShippingNewAddress.FaxNumber,
@@ -382,9 +382,9 @@ public class CheckoutController : BasePublicController
if (address == null)
{
address =
- await _groupService.IsGuest(_workContextAccessor.WorkContext.CurrentCustomer)
+ await _groupService.IsGuest(_contextAccessor.WorkContext.CurrentCustomer)
? model.ShippingNewAddress.ToEntity()
- : model.ShippingNewAddress.ToEntity(_workContextAccessor.WorkContext.CurrentCustomer, addressSettings);
+ : model.ShippingNewAddress.ToEntity(_contextAccessor.WorkContext.CurrentCustomer, addressSettings);
address.Attributes = await _mediator.Send(new GetParseCustomAddressAttributes
{ SelectedAttributes = model.ShippingNewAddress.SelectedAttributes });
@@ -392,32 +392,32 @@ public class CheckoutController : BasePublicController
? model.BillToTheSameAddress ? AddressType.Any : AddressType.Shipping
: AddressType.Any;
//other null validations
- _workContextAccessor.WorkContext.CurrentCustomer.Addresses.Add(address);
- await _customerService.InsertAddress(address, _workContextAccessor.WorkContext.CurrentCustomer.Id);
+ _contextAccessor.WorkContext.CurrentCustomer.Addresses.Add(address);
+ await _customerService.InsertAddress(address, _contextAccessor.WorkContext.CurrentCustomer.Id);
}
- _workContextAccessor.WorkContext.CurrentCustomer.ShippingAddress = address;
- await _customerService.UpdateShippingAddress(address, _workContextAccessor.WorkContext.CurrentCustomer.Id);
+ _contextAccessor.WorkContext.CurrentCustomer.ShippingAddress = address;
+ await _customerService.UpdateShippingAddress(address, _contextAccessor.WorkContext.CurrentCustomer.Id);
}
}
if (model.BillToTheSameAddress && !model.PickUpInStore &&
- _workContextAccessor.WorkContext.CurrentCustomer.ShippingAddress!.AddressType != AddressType.Shipping)
+ _contextAccessor.WorkContext.CurrentCustomer.ShippingAddress!.AddressType != AddressType.Shipping)
{
- _workContextAccessor.WorkContext.CurrentCustomer.BillingAddress = _workContextAccessor.WorkContext.CurrentCustomer.ShippingAddress;
- await _customerService.UpdateBillingAddress(_workContextAccessor.WorkContext.CurrentCustomer.BillingAddress,
- _workContextAccessor.WorkContext.CurrentCustomer.Id);
- await _customerService.UpdateUserField<ShippingOption>(_workContextAccessor.WorkContext.CurrentCustomer,
- SystemCustomerFieldNames.SelectedShippingOption, null, _workContextAccessor.WorkContext.CurrentStore.Id);
+ _contextAccessor.WorkContext.CurrentCustomer.BillingAddress = _contextAccessor.WorkContext.CurrentCustomer.ShippingAddress;
+ await _customerService.UpdateBillingAddress(_contextAccessor.WorkContext.CurrentCustomer.BillingAddress,
+ _contextAccessor.WorkContext.CurrentCustomer.Id);
+ await _customerService.UpdateUserField<ShippingOption>(_contextAccessor.WorkContext.CurrentCustomer,
+ SystemCustomerFieldNames.SelectedShippingOption, null, _contextAccessor.StoreContext.CurrentStore.Id);
return await LoadStepAfterBillingAddress(cart);
}
var billingAddressModel = await _mediator.Send(new GetBillingAddress {
Cart = cart,
- Currency = _workContextAccessor.WorkContext.WorkingCurrency,
- Customer = _workContextAccessor.WorkContext.CurrentCustomer,
- Language = _workContextAccessor.WorkContext.WorkingLanguage,
- Store = _workContextAccessor.WorkContext.CurrentStore,
+ Currency = _contextAccessor.WorkContext.WorkingCurrency,
+ Customer = _contextAccessor.WorkContext.CurrentCustomer,
+ Language = _contextAccessor.WorkContext.WorkingLanguage,
+ Store = _contextAccessor.StoreContext.CurrentStore,
SelectedCountryId = model.ShippingNewAddress.CountryId
});
if (!billingAddressModel.ExistingAddresses.Any())
@@ -444,10 +444,10 @@ public class CheckoutController : BasePublicController
try
{
//validation
- var customer = _workContextAccessor.WorkContext.CurrentCustomer;
- var store = _workContextAccessor.WorkContext.CurrentStore;
+ var customer = _contextAccessor.WorkContext.CurrentCustomer;
+ var store = _contextAccessor.StoreContext.CurrentStore;
- var cart = await _shoppingCartService.GetShoppingCart(_workContextAccessor.WorkContext.CurrentStore.Id,
+ var cart = await _shoppingCartService.GetShoppingCart(_contextAccessor.StoreContext.CurrentStore.Id,
ShoppingCartType.ShoppingCart, ShoppingCartType.Auctions);
await CartValidate(cart);
@@ -532,7 +532,7 @@ public class CheckoutController : BasePublicController
try
{
//validation
- var cart = await _shoppingCartService.GetShoppingCart(_workContextAccessor.WorkContext.CurrentStore.Id,
+ var cart = await _shoppingCartService.GetShoppingCart(_contextAccessor.StoreContext.CurrentStore.Id,
ShoppingCartType.ShoppingCart, ShoppingCartType.Auctions);
await CartValidate(cart);
@@ -542,9 +542,9 @@ public class CheckoutController : BasePublicController
//loyalty points
if (_loyaltyPointsSettings.Enabled)
- await _customerService.UpdateUserField(_workContextAccessor.WorkContext.CurrentCustomer,
+ await _customerService.UpdateUserField(_contextAccessor.WorkContext.CurrentCustomer,
SystemCustomerFieldNames.UseLoyaltyPointsDuringCheckout, model.UseLoyaltyPoints,
- _workContextAccessor.WorkContext.CurrentStore.Id);
+ _contextAccessor.StoreContext.CurrentStore.Id);
//Check whether payment workflow is required
var isPaymentWorkflowRequired =
@@ -552,12 +552,12 @@ public class CheckoutController : BasePublicController
if (!isPaymentWorkflowRequired)
{
//payment is not required
- await _customerService.UpdateUserField<string>(_workContextAccessor.WorkContext.CurrentCustomer,
- SystemCustomerFieldNames.SelectedPaymentMethod, null, _workContextAccessor.WorkContext.CurrentStore.Id);
+ await _customerService.UpdateUserField<string>(_contextAccessor.WorkContext.CurrentCustomer,
+ SystemCustomerFieldNames.SelectedPaymentMethod, null, _contextAccessor.StoreContext.CurrentStore.Id);
var confirmOrderModel = await _mediator.Send(new GetConfirmOrder {
- Cart = cart, Customer = _workContextAccessor.WorkContext.CurrentCustomer, Language = _workContextAccessor.WorkContext.WorkingLanguage,
- Store = _workContextAccessor.WorkContext.CurrentStore
+ Cart = cart, Customer = _contextAccessor.WorkContext.CurrentCustomer, Language = _contextAccessor.WorkContext.WorkingLanguage,
+ Store = _contextAccessor.StoreContext.CurrentStore
});
return Json(new {
update_section = new UpdateSectionJsonModel {
@@ -571,21 +571,21 @@ public class CheckoutController : BasePublicController
var paymentMethodInst = _paymentService.LoadPaymentMethodBySystemName(model.PaymentMethod);
if (paymentMethodInst == null ||
!paymentMethodInst.IsPaymentMethodActive(_paymentSettings) ||
- !paymentMethodInst.IsAuthenticateStore(_workContextAccessor.WorkContext.CurrentStore))
+ !paymentMethodInst.IsAuthenticateStore(_contextAccessor.StoreContext.CurrentStore))
throw new Exception("Selected payment method can't be parsed");
//save
- await _customerService.UpdateUserField(_workContextAccessor.WorkContext.CurrentCustomer,
- SystemCustomerFieldNames.SelectedPaymentMethod, model.PaymentMethod, _workContextAccessor.WorkContext.CurrentStore.Id);
+ await _customerService.UpdateUserField(_contextAccessor.WorkContext.CurrentCustomer,
+ SystemCustomerFieldNames.SelectedPaymentMethod, model.PaymentMethod, _contextAccessor.StoreContext.CurrentStore.Id);
var paymentTransaction = await paymentMethodInst.InitPaymentTransaction();
if (paymentTransaction != null)
- await _customerService.UpdateUserField(_workContextAccessor.WorkContext.CurrentCustomer,
+ await _customerService.UpdateUserField(_contextAccessor.WorkContext.CurrentCustomer,
SystemCustomerFieldNames.PaymentTransaction, paymentTransaction.Id,
- _workContextAccessor.WorkContext.CurrentStore.Id);
+ _contextAccessor.StoreContext.CurrentStore.Id);
else
- await _customerService.UpdateUserField<string>(_workContextAccessor.WorkContext.CurrentCustomer,
- SystemCustomerFieldNames.PaymentTransaction, null, _workContextAccessor.WorkContext.CurrentStore.Id);
+ await _customerService.UpdateUserField<string>(_contextAccessor.WorkContext.CurrentCustomer,
+ SystemCustomerFieldNames.PaymentTransaction, null, _contextAccessor.StoreContext.CurrentStore.Id);
return await LoadStepAfterPaymentMethod(paymentMethodInst, cart);
}
@@ -602,11 +602,11 @@ public class CheckoutController : BasePublicController
try
{
//validation
- var cart = await _shoppingCartService.GetShoppingCart(_workContextAccessor.WorkContext.CurrentStore.Id,
+ var cart = await _shoppingCartService.GetShoppingCart(_contextAccessor.StoreContext.CurrentStore.Id,
ShoppingCartType.ShoppingCart, ShoppingCartType.Auctions);
await CartValidate(cart);
- var paymentMethodSystemName = _workContextAccessor.WorkContext.CurrentCustomer.GetUserFieldFromEntity<string>(SystemCustomerFieldNames.SelectedPaymentMethod, _workContextAccessor.WorkContext.CurrentStore.Id);
+ var paymentMethodSystemName = _contextAccessor.WorkContext.CurrentCustomer.GetUserFieldFromEntity<string>(SystemCustomerFieldNames.SelectedPaymentMethod, _contextAccessor.StoreContext.CurrentStore.Id);
var paymentMethod = _paymentService.LoadPaymentMethodBySystemName(paymentMethodSystemName);
if (paymentMethod == null)
throw new Exception("Payment method is not selected");
@@ -618,13 +618,13 @@ public class CheckoutController : BasePublicController
var paymentTransaction = await paymentMethod.SavePaymentInfo(model);
if (paymentTransaction != null)
//save
- await _customerService.UpdateUserField(_workContextAccessor.WorkContext.CurrentCustomer,
+ await _customerService.UpdateUserField(_contextAccessor.WorkContext.CurrentCustomer,
SystemCustomerFieldNames.PaymentTransaction, paymentTransaction.Id,
- _workContextAccessor.WorkContext.CurrentStore.Id);
+ _contextAccessor.StoreContext.CurrentStore.Id);
var confirmOrderModel = await _mediator.Send(new GetConfirmOrder {
- Cart = cart, Customer = _workContextAccessor.WorkContext.CurrentCustomer, Language = _workContextAccessor.WorkContext.WorkingLanguage,
- Store = _workContextAccessor.WorkContext.CurrentStore
+ Cart = cart, Customer = _contextAccessor.WorkContext.CurrentCustomer, Language = _contextAccessor.WorkContext.WorkingLanguage,
+ Store = _contextAccessor.StoreContext.CurrentStore
});
return Json(new {
update_section = new UpdateSectionJsonModel {
@@ -656,17 +656,17 @@ public class CheckoutController : BasePublicController
public virtual async Task<IActionResult> Completed(string orderId)
{
//validation
- if (await _groupService.IsGuest(_workContextAccessor.WorkContext.CurrentCustomer) && !_orderSettings.AnonymousCheckoutAllowed)
+ if (await _groupService.IsGuest(_contextAccessor.WorkContext.CurrentCustomer) && !_orderSettings.AnonymousCheckoutAllowed)
return Challenge();
Order order = null;
if (!string.IsNullOrEmpty(orderId)) order = await _orderService.GetOrderById(orderId);
- order ??= (await _orderService.SearchOrders(_workContextAccessor.WorkContext.CurrentStore.Id,
- customerId: _workContextAccessor.WorkContext.CurrentCustomer.Id, pageSize: 1))
+ order ??= (await _orderService.SearchOrders(_contextAccessor.StoreContext.CurrentStore.Id,
+ customerId: _contextAccessor.WorkContext.CurrentCustomer.Id, pageSize: 1))
.FirstOrDefault();
- if (order == null || order.Deleted || _workContextAccessor.WorkContext.CurrentCustomer.Id != order.CustomerId)
+ if (order == null || order.Deleted || _contextAccessor.WorkContext.CurrentCustomer.Id != order.CustomerId)
return RedirectToRoute("HomePage");
//disable "order completed" page?
@@ -689,14 +689,14 @@ public class CheckoutController : BasePublicController
try
{
//validation
- var cart = await _shoppingCartService.GetShoppingCart(_workContextAccessor.WorkContext.CurrentStore.Id,
+ var cart = await _shoppingCartService.GetShoppingCart(_contextAccessor.StoreContext.CurrentStore.Id,
ShoppingCartType.ShoppingCart, ShoppingCartType.Auctions);
await CartValidate(cart);
//prevent 2 orders being placed within an X seconds time frame
if (!await _mediator.Send(new GetMinOrderPlaceIntervalValid {
- Customer = _workContextAccessor.WorkContext.CurrentCustomer,
- Store = _workContextAccessor.WorkContext.CurrentStore
+ Customer = _contextAccessor.WorkContext.CurrentCustomer,
+ Store = _contextAccessor.StoreContext.CurrentStore
}))
return Json(new {
error = 1, message = _translationService.GetResource("Checkout.MinOrderPlacementInterval")
@@ -716,7 +716,7 @@ public class CheckoutController : BasePublicController
if (paymentMethod.PaymentMethodType == PaymentMethodType.Redirection)
{
//Redirection will not work because it's AJAX request.
- var storeLocation = _workContextAccessor.WorkContext.CurrentHost.Url.TrimEnd('/');
+ var storeLocation = _contextAccessor.StoreContext.CurrentHost.Url.TrimEnd('/');
//redirect
return Json(new {
redirect =
@@ -731,8 +731,8 @@ public class CheckoutController : BasePublicController
//error
var confirmOrderModel = await _mediator.Send(new GetConfirmOrder {
- Cart = cart, Customer = _workContextAccessor.WorkContext.CurrentCustomer, Language = _workContextAccessor.WorkContext.WorkingLanguage,
- Store = _workContextAccessor.WorkContext.CurrentStore
+ Cart = cart, Customer = _contextAccessor.WorkContext.CurrentCustomer, Language = _contextAccessor.WorkContext.WorkingLanguage,
+ Store = _contextAccessor.StoreContext.CurrentStore
});
foreach (var error in placeOrderResult.Errors)
confirmOrderModel.Warnings.Add(error);
@@ -757,7 +757,7 @@ public class CheckoutController : BasePublicController
{
try
{
- if (await _groupService.IsGuest(_workContextAccessor.WorkContext.CurrentCustomer) &&
+ if (await _groupService.IsGuest(_contextAccessor.WorkContext.CurrentCustomer) &&
!_orderSettings.AnonymousCheckoutAllowed)
return Challenge();
@@ -799,7 +799,7 @@ public class CheckoutController : BasePublicController
#region Fields
- private readonly IWorkContextAccessor _workContextAccessor;
+ private readonly IContextAccessor _contextAccessor;
private readonly ITranslationService _translationService;
private readonly ICustomerService _customerService;
private readonly IGroupService _groupService;
@@ -859,7 +859,7 @@ public class CheckoutController : BasePublicController
if (!cart.Any())
throw new Exception("Your cart is empty");
- if (await _groupService.IsGuest(_workContextAccessor.WorkContext.CurrentCustomer) && !_orderSettings.AnonymousCheckoutAllowed)
+ if (await _groupService.IsGuest(_contextAccessor.WorkContext.CurrentCustomer) && !_orderSettings.AnonymousCheckoutAllowed)
throw new Exception("Anonymous checkout is not allowed");
}
@@ -868,16 +868,16 @@ public class CheckoutController : BasePublicController
{
var shippingMethodModel = await _mediator.Send(new GetShippingMethod {
Cart = cart,
- Currency = _workContextAccessor.WorkContext.WorkingCurrency,
- Customer = _workContextAccessor.WorkContext.CurrentCustomer,
- Language = _workContextAccessor.WorkContext.WorkingLanguage,
- ShippingAddress = _workContextAccessor.WorkContext.CurrentCustomer.ShippingAddress,
- Store = _workContextAccessor.WorkContext.CurrentStore
+ Currency = _contextAccessor.WorkContext.WorkingCurrency,
+ Customer = _contextAccessor.WorkContext.CurrentCustomer,
+ Language = _contextAccessor.WorkContext.WorkingLanguage,
+ ShippingAddress = _contextAccessor.WorkContext.CurrentCustomer.ShippingAddress,
+ Store = _contextAccessor.StoreContext.CurrentStore
});
var selectedPickupPoint =
- _workContextAccessor.WorkContext.CurrentCustomer.GetUserFieldFromEntity<string>(
- SystemCustomerFieldNames.SelectedPickupPoint, _workContextAccessor.WorkContext.CurrentStore.Id);
+ _contextAccessor.WorkContext.CurrentCustomer.GetUserFieldFromEntity<string>(
+ SystemCustomerFieldNames.SelectedPickupPoint, _contextAccessor.StoreContext.CurrentStore.Id);
if ((!_shippingSettings.SkipShippingMethodSelectionIfOnlyOne ||
shippingMethodModel.ShippingMethods.Count != 1) &&
@@ -890,10 +890,10 @@ public class CheckoutController : BasePublicController
goto_section = "shipping_method"
});
if (!(_shippingSettings.AllowPickUpInStore && !string.IsNullOrEmpty(selectedPickupPoint)))
- await _customerService.UpdateUserField(_workContextAccessor.WorkContext.CurrentCustomer,
+ await _customerService.UpdateUserField(_contextAccessor.WorkContext.CurrentCustomer,
SystemCustomerFieldNames.SelectedShippingOption,
shippingMethodModel.ShippingMethods.First().ShippingOption,
- _workContextAccessor.WorkContext.CurrentStore.Id);
+ _contextAccessor.StoreContext.CurrentStore.Id);
//load next step
return await LoadStepAfterShippingMethod(cart);
@@ -911,18 +911,18 @@ public class CheckoutController : BasePublicController
//filter by country
var filterByCountryId = "";
if (_addressSettings.CountryEnabled &&
- _workContextAccessor.WorkContext.CurrentCustomer.BillingAddress != null &&
- !string.IsNullOrEmpty(_workContextAccessor.WorkContext.CurrentCustomer.BillingAddress.CountryId))
- filterByCountryId = _workContextAccessor.WorkContext.CurrentCustomer.BillingAddress.CountryId;
+ _contextAccessor.WorkContext.CurrentCustomer.BillingAddress != null &&
+ !string.IsNullOrEmpty(_contextAccessor.WorkContext.CurrentCustomer.BillingAddress.CountryId))
+ filterByCountryId = _contextAccessor.WorkContext.CurrentCustomer.BillingAddress.CountryId;
//payment is required
var paymentMethodModel = await _mediator.Send(new GetPaymentMethod {
Cart = cart,
- Currency = _workContextAccessor.WorkContext.WorkingCurrency,
- Customer = _workContextAccessor.WorkContext.CurrentCustomer,
+ Currency = _contextAccessor.WorkContext.WorkingCurrency,
+ Customer = _contextAccessor.WorkContext.CurrentCustomer,
FilterByCountryId = filterByCountryId,
- Language = _workContextAccessor.WorkContext.WorkingLanguage,
- Store = _workContextAccessor.WorkContext.CurrentStore
+ Language = _contextAccessor.WorkContext.WorkingLanguage,
+ Store = _contextAccessor.StoreContext.CurrentStore
});
if (!_paymentSettings.SkipPaymentIfOnlyOne ||
@@ -938,15 +938,15 @@ public class CheckoutController : BasePublicController
//so customer doesn't have to choose a payment method
var selectedPaymentMethodSystemName = paymentMethodModel.PaymentMethods[0].PaymentMethodSystemName;
- await _customerService.UpdateUserField(_workContextAccessor.WorkContext.CurrentCustomer,
+ await _customerService.UpdateUserField(_contextAccessor.WorkContext.CurrentCustomer,
SystemCustomerFieldNames.SelectedPaymentMethod,
- selectedPaymentMethodSystemName, _workContextAccessor.WorkContext.CurrentStore.Id);
+ selectedPaymentMethodSystemName, _contextAccessor.StoreContext.CurrentStore.Id);
var paymentMethodInst =
_paymentService.LoadPaymentMethodBySystemName(selectedPaymentMethodSystemName);
if (paymentMethodInst == null ||
!paymentMethodInst.IsPaymentMethodActive(_paymentSettings) ||
- !paymentMethodInst.IsAuthenticateStore(_workContextAccessor.WorkContext.CurrentStore))
+ !paymentMethodInst.IsAuthenticateStore(_contextAccessor.StoreContext.CurrentStore))
throw new Exception("Selected payment method can't be parsed");
return await LoadStepAfterPaymentMethod(paymentMethodInst, cart);
@@ -955,12 +955,12 @@ public class CheckoutController : BasePublicController
}
//payment is not required
- await _customerService.UpdateUserField<string>(_workContextAccessor.WorkContext.CurrentCustomer,
- SystemCustomerFieldNames.SelectedPaymentMethod, null, _workContextAccessor.WorkContext.CurrentStore.Id);
+ await _customerService.UpdateUserField<string>(_contextAccessor.WorkContext.CurrentCustomer,
+ SystemCustomerFieldNames.SelectedPaymentMethod, null, _contextAccessor.StoreContext.CurrentStore.Id);
var confirmOrderModel = await _mediator.Send(new GetConfirmOrder {
- Cart = cart, Customer = _workContextAccessor.WorkContext.CurrentCustomer, Language = _workContextAccessor.WorkContext.WorkingLanguage,
- Store = _workContextAccessor.WorkContext.CurrentStore
+ Cart = cart, Customer = _contextAccessor.WorkContext.CurrentCustomer, Language = _contextAccessor.WorkContext.WorkingLanguage,
+ Store = _contextAccessor.StoreContext.CurrentStore
});
return Json(new {
update_section = new UpdateSectionJsonModel {
@@ -980,8 +980,8 @@ public class CheckoutController : BasePublicController
&& _paymentSettings.SkipPaymentInfo))
{
var confirmOrderModel = await _mediator.Send(new GetConfirmOrder {
- Cart = cart, Customer = _workContextAccessor.WorkContext.CurrentCustomer, Language = _workContextAccessor.WorkContext.WorkingLanguage,
- Store = _workContextAccessor.WorkContext.CurrentStore
+ Cart = cart, Customer = _contextAccessor.WorkContext.CurrentCustomer, Language = _contextAccessor.WorkContext.WorkingLanguage,
+ Store = _contextAccessor.StoreContext.CurrentStore
});
return Json(new {
update_section = new UpdateSectionJsonModel {
diff --git a/src/Web/Grand.Web/Controllers/CommonController.cs b/src/Web/Grand.Web/Controllers/CommonController.cs
index 9e9c71e6f..d4d0956e4 100644
--- a/src/Web/Grand.Web/Controllers/CommonController.cs
+++ b/src/Web/Grand.Web/Controllers/CommonController.cs
@@ -34,11 +34,11 @@ public class CommonController : BasePublicController
{
#region Constructors
- public CommonController(IWorkContextAccessor workContextAccessor,
+ public CommonController(IContextAccessor contextAccessor,
ILanguageService languageService,
IMediator mediator)
{
- _workContextAccessor = workContextAccessor;
+ _contextAccessor = contextAccessor;
_languageService = languageService;
_mediator = mediator;
}
@@ -48,7 +48,7 @@ public class CommonController : BasePublicController
#region Fields
private readonly ILanguageService _languageService;
- private readonly IWorkContextAccessor _workContextAccessor;
+ private readonly IContextAccessor _contextAccessor;
private readonly IMediator _mediator;
#endregion
@@ -152,7 +152,7 @@ public class CommonController : BasePublicController
{
var language = await _languageService.GetLanguageByCode(langCode);
if (!language?.Published ?? false)
- language = _workContextAccessor.WorkContext.WorkingLanguage;
+ language = _contextAccessor.WorkContext.WorkingLanguage;
//prevent open redirection attack
if (!Url.IsLocalUrl(returnUrl))
@@ -166,10 +166,10 @@ public class CommonController : BasePublicController
returnUrl = AddLanguageSeo(returnUrl, language);
}
- await customerService.UpdateUserField(_workContextAccessor.WorkContext.CurrentCustomer, SystemCustomerFieldNames.LanguageId, language.Id, _workContextAccessor.WorkContext.CurrentStore.Id);
+ await customerService.UpdateUserField(_contextAccessor.WorkContext.CurrentCustomer, SystemCustomerFieldNames.LanguageId, language.Id, _contextAccessor.StoreContext.CurrentStore.Id);
//notification
- await _mediator.Publish(new ChangeLanguageEvent(_workContextAccessor.WorkContext.CurrentCustomer, language));
+ await _mediator.Publish(new ChangeLanguageEvent(_contextAccessor.WorkContext.CurrentCustomer, language));
return Redirect(returnUrl);
}
@@ -216,17 +216,17 @@ public class CommonController : BasePublicController
{
var currency = await currencyService.GetCurrencyByCode(currencyCode);
if (currency != null)
- await customerService.UpdateUserField(_workContextAccessor.WorkContext.CurrentCustomer, SystemCustomerFieldNames.CurrencyId,
- currency.Id, _workContextAccessor.WorkContext.CurrentStore.Id);
+ await customerService.UpdateUserField(_contextAccessor.WorkContext.CurrentCustomer, SystemCustomerFieldNames.CurrencyId,
+ currency.Id, _contextAccessor.StoreContext.CurrentStore.Id);
//clear coupon code
- await customerService.UpdateUserField(_workContextAccessor.WorkContext.CurrentCustomer, SystemCustomerFieldNames.DiscountCoupons, "");
+ await customerService.UpdateUserField(_contextAccessor.WorkContext.CurrentCustomer, SystemCustomerFieldNames.DiscountCoupons, "");
//clear gift card
- await customerService.UpdateUserField(_workContextAccessor.WorkContext.CurrentCustomer, SystemCustomerFieldNames.GiftVoucherCoupons, "");
+ await customerService.UpdateUserField(_contextAccessor.WorkContext.CurrentCustomer, SystemCustomerFieldNames.GiftVoucherCoupons, "");
//notification
- await _mediator.Publish(new ChangeCurrencyEvent(_workContextAccessor.WorkContext.CurrentCustomer, currency));
+ await _mediator.Publish(new ChangeCurrencyEvent(_contextAccessor.WorkContext.CurrentCustomer, currency));
//prevent open redirection attack
if (!Url.IsLocalUrl(returnUrl))
@@ -245,7 +245,7 @@ public class CommonController : BasePublicController
[FromServices] SecurityConfig securityConfig,
string shortcut, string returnUrl = "")
{
- var currentstoreShortcut = _workContextAccessor.WorkContext.CurrentStore.Shortcut;
+ var currentstoreShortcut = _contextAccessor.StoreContext.CurrentStore.Shortcut;
if (currentstoreShortcut != shortcut)
if (commonSettings.AllowToSelectStore)
{
@@ -256,9 +256,9 @@ public class CommonController : BasePublicController
SetStoreCookie(selectedstore);
//notification
- await _mediator.Publish(new ChangeStoreEvent(_workContextAccessor.WorkContext.CurrentCustomer, selectedstore));
+ await _mediator.Publish(new ChangeStoreEvent(_contextAccessor.WorkContext.CurrentCustomer, selectedstore));
- if (selectedstore.Url != _workContextAccessor.WorkContext.CurrentStore.Url)
+ if (selectedstore.Url != _contextAccessor.StoreContext.CurrentStore.Url)
return Redirect(selectedstore.SslEnabled ? selectedstore.SecureUrl : selectedstore.Url);
}
}
@@ -309,11 +309,11 @@ public class CommonController : BasePublicController
return Redirect(returnUrl);
//save passed value
- await customerService.UpdateUserField(_workContextAccessor.WorkContext.CurrentCustomer,
- SystemCustomerFieldNames.TaxDisplayTypeId, (int)taxDisplayType, _workContextAccessor.WorkContext.CurrentStore.Id);
+ await customerService.UpdateUserField(_contextAccessor.WorkContext.CurrentCustomer,
+ SystemCustomerFieldNames.TaxDisplayTypeId, (int)taxDisplayType, _contextAccessor.StoreContext.CurrentStore.Id);
//notification
- await _mediator.Publish(new ChangeTaxTypeEvent(_workContextAccessor.WorkContext.CurrentCustomer, taxDisplayType));
+ await _mediator.Publish(new ChangeTaxTypeEvent(_contextAccessor.WorkContext.CurrentCustomer, taxDisplayType));
return Redirect(returnUrl);
}
@@ -334,7 +334,7 @@ public class CommonController : BasePublicController
if (themeContext != null) await themeContext.SetTheme(themeName);
//notification
- await _mediator.Publish(new ChangeThemeEvent(_workContextAccessor.WorkContext.CurrentCustomer, themeName));
+ await _mediator.Publish(new ChangeThemeEvent(_contextAccessor.WorkContext.CurrentCustomer, themeName));
return Redirect(returnUrl);
}
@@ -347,9 +347,9 @@ public class CommonController : BasePublicController
return RedirectToRoute("HomePage");
var model = await _mediator.Send(new GetSitemap {
- Customer = _workContextAccessor.WorkContext.CurrentCustomer,
- Language = _workContextAccessor.WorkContext.WorkingLanguage,
- Store = _workContextAccessor.WorkContext.CurrentStore
+ Customer = _contextAccessor.WorkContext.CurrentCustomer,
+ Language = _contextAccessor.WorkContext.WorkingLanguage,
+ Store = _contextAccessor.StoreContext.CurrentStore
});
return View(model);
}
@@ -368,18 +368,18 @@ public class CommonController : BasePublicController
return Json(new { stored = false });
//save consent cookies
- await customerService.UpdateUserField(_workContextAccessor.WorkContext.CurrentCustomer, SystemCustomerFieldNames.ConsentCookies, "",
- _workContextAccessor.WorkContext.CurrentStore.Id);
+ await customerService.UpdateUserField(_contextAccessor.WorkContext.CurrentCustomer, SystemCustomerFieldNames.ConsentCookies, "",
+ _contextAccessor.StoreContext.CurrentStore.Id);
var consentCookies = cookiePreference.GetConsentCookies();
var dictionary = consentCookies.Where(x => x.AllowToDisable).ToDictionary(item => item.SystemName, item => accept);
if (dictionary.Any())
- await customerService.UpdateUserField(_workContextAccessor.WorkContext.CurrentCustomer, SystemCustomerFieldNames.ConsentCookies,
- dictionary, _workContextAccessor.WorkContext.CurrentStore.Id);
+ await customerService.UpdateUserField(_contextAccessor.WorkContext.CurrentCustomer, SystemCustomerFieldNames.ConsentCookies,
+ dictionary, _contextAccessor.StoreContext.CurrentStore.Id);
//save setting - CookieAccepted
- await customerService.UpdateUserField(_workContextAccessor.WorkContext.CurrentCustomer, SystemCustomerFieldNames.CookieAccepted,
- true, _workContextAccessor.WorkContext.CurrentStore.Id);
+ await customerService.UpdateUserField(_contextAccessor.WorkContext.CurrentCustomer, SystemCustomerFieldNames.CookieAccepted,
+ true, _contextAccessor.StoreContext.CurrentStore.Id);
return Json(new { stored = true });
}
@@ -395,8 +395,8 @@ public class CommonController : BasePublicController
return Json(new { html = "" });
var model = await _mediator.Send(new GetPrivacyPreference {
- Customer = _workContextAccessor.WorkContext.CurrentCustomer,
- Store = _workContextAccessor.WorkContext.CurrentStore
+ Customer = _contextAccessor.WorkContext.CurrentCustomer,
+ Store = _contextAccessor.StoreContext.CurrentStore
});
return Json(new
@@ -419,8 +419,8 @@ public class CommonController : BasePublicController
return Json(new { success = false });
const string consent = "ConsentCookies";
- await customerService.UpdateUserField(_workContextAccessor.WorkContext.CurrentCustomer, SystemCustomerFieldNames.ConsentCookies, "",
- _workContextAccessor.WorkContext.CurrentStore.Id);
+ await customerService.UpdateUserField(_contextAccessor.WorkContext.CurrentCustomer, SystemCustomerFieldNames.ConsentCookies, "",
+ _contextAccessor.StoreContext.CurrentStore.Id);
var selectedConsentCookies = new List<string>();
foreach (var item in model)
if (item.Key.StartsWith(consent))
@@ -432,7 +432,7 @@ public class CommonController : BasePublicController
if (item.AllowToDisable)
dictionary.Add(item.SystemName, selectedConsentCookies.Contains(item.SystemName));
- await customerService.UpdateUserField(_workContextAccessor.WorkContext.CurrentCustomer, SystemCustomerFieldNames.ConsentCookies, dictionary, _workContextAccessor.WorkContext.CurrentStore.Id);
+ await customerService.UpdateUserField(_contextAccessor.WorkContext.CurrentCustomer, SystemCustomerFieldNames.ConsentCookies, dictionary, _contextAccessor.StoreContext.CurrentStore.Id);
return Json(new { success = true });
}
@@ -443,7 +443,7 @@ public class CommonController : BasePublicController
[HttpGet]
public virtual async Task<IActionResult> RobotsTextFile()
{
- var sb = await _mediator.Send(new GetRobotsTextFile { StoreId = _workContextAccessor.WorkContext.CurrentStore.Id });
+ var sb = await _mediator.Send(new GetRobotsTextFile { StoreId = _contextAccessor.StoreContext.CurrentStore.Id });
return Content(sb, "text/plain");
}
@@ -475,7 +475,7 @@ public class CommonController : BasePublicController
if (!customerSettings.GeoEnabled)
return Content("");
- await _mediator.Send(new CurrentPositionCommand { Customer = _workContextAccessor.WorkContext.CurrentCustomer, Model = model });
+ await _mediator.Send(new CurrentPositionCommand { Customer = _contextAccessor.WorkContext.CurrentCustomer, Model = model });
return Content("");
}
diff --git a/src/Web/Grand.Web/Controllers/ContactController.cs b/src/Web/Grand.Web/Controllers/ContactController.cs
index b82df5ee5..7f303bfc3 100644
--- a/src/Web/Grand.Web/Controllers/ContactController.cs
+++ b/src/Web/Grand.Web/Controllers/ContactController.cs
@@ -26,11 +26,11 @@ public class ContactController : BasePublicController
public ContactController(
ITranslationService translationService,
- IWorkContextAccessor workContextAccessor,
+ IContextAccessor contextAccessor,
IMediator mediator)
{
_translationService = translationService;
- _workContextAccessor = workContextAccessor;
+ _contextAccessor = contextAccessor;
_mediator = mediator;
}
@@ -52,9 +52,9 @@ public class ContactController : BasePublicController
}
var model = await _mediator.Send(new ContactUsCommand {
- Customer = _workContextAccessor.WorkContext.CurrentCustomer,
- Language = _workContextAccessor.WorkContext.WorkingLanguage,
- Store = _workContextAccessor.WorkContext.CurrentStore
+ Customer = _contextAccessor.WorkContext.CurrentCustomer,
+ Language = _contextAccessor.WorkContext.WorkingLanguage,
+ Store = _contextAccessor.StoreContext.CurrentStore
});
return View(model);
}
@@ -84,15 +84,15 @@ public class ContactController : BasePublicController
});
//notification
- await _mediator.Publish(new ContactUsEvent(_workContextAccessor.WorkContext.CurrentCustomer, result));
+ await _mediator.Publish(new ContactUsEvent(_contextAccessor.WorkContext.CurrentCustomer, result));
return View(result);
}
var modelReturn = await _mediator.Send(new ContactUsCommand {
- Customer = _workContextAccessor.WorkContext.CurrentCustomer,
- Language = _workContextAccessor.WorkContext.WorkingLanguage,
- Store = _workContextAccessor.WorkContext.CurrentStore,
+ Customer = _contextAccessor.WorkContext.CurrentCustomer,
+ Language = _contextAccessor.WorkContext.WorkingLanguage,
+ Store = _contextAccessor.StoreContext.CurrentStore,
Model = model
});
@@ -105,8 +105,8 @@ public class ContactController : BasePublicController
{
var result = await _mediator.Send(new ContactAttributeChangeCommand {
Attributes = model.Attributes,
- Customer = _workContextAccessor.WorkContext.CurrentCustomer,
- Store = _workContextAccessor.WorkContext.CurrentStore
+ Customer = _contextAccessor.WorkContext.CurrentCustomer,
+ Store = _contextAccessor.StoreContext.CurrentStore
});
return Json(new {
enabledattributeids = result.enabledAttributeIds.ToArray(),
@@ -178,7 +178,7 @@ public class ContactController : BasePublicController
var download = new Download {
DownloadGuid = Guid.NewGuid(),
- CustomerId = _workContextAccessor.WorkContext.CurrentCustomer.Id,
+ CustomerId = _contextAccessor.WorkContext.CurrentCustomer.Id,
UseDownloadUrl = false,
DownloadUrl = "",
DownloadBinary = fileBinary,
@@ -204,7 +204,7 @@ public class ContactController : BasePublicController
#region Fields
private readonly ITranslationService _translationService;
- private readonly IWorkContextAccessor _workContextAccessor;
+ private readonly IContextAccessor _contextAccessor;
private readonly IMediator _mediator;
#endregion
diff --git a/src/Web/Grand.Web/Controllers/CourseController.cs b/src/Web/Grand.Web/Controllers/CourseController.cs
index 067f22cc1..e104210de 100644
--- a/src/Web/Grand.Web/Controllers/CourseController.cs
+++ b/src/Web/Grand.Web/Controllers/CourseController.cs
@@ -28,12 +28,12 @@ public class CourseController : BasePublicController
private readonly IMediator _mediator;
private readonly IPermissionService _permissionService;
private readonly ITranslationService _translationService;
- private readonly IWorkContextAccessor _workContextAccessor;
+ private readonly IContextAccessor _contextAccessor;
public CourseController(
IPermissionService permissionService,
IAclService aclService,
- IWorkContextAccessor workContextAccessor,
+ IContextAccessor contextAccessor,
IGroupService groupService,
ITranslationService translationService,
ICourseService courseService,
@@ -44,7 +44,7 @@ public class CourseController : BasePublicController
{
_permissionService = permissionService;
_aclService = aclService;
- _workContextAccessor = workContextAccessor;
+ _contextAccessor = contextAccessor;
_groupService = groupService;
_translationService = translationService;
_courseService = courseService;
@@ -72,13 +72,13 @@ public class CourseController : BasePublicController
//ACL (access control list)
return _aclService.Authorize(course, customer) &&
//Store access
- _aclService.Authorize(course, _workContextAccessor.WorkContext.CurrentStore.Id);
+ _aclService.Authorize(course, _contextAccessor.StoreContext.CurrentStore.Id);
}
[HttpGet]
public virtual async Task<IActionResult> Details(string courseId)
{
- var customer = _workContextAccessor.WorkContext.CurrentCustomer;
+ var customer = _contextAccessor.WorkContext.CurrentCustomer;
var course = await _courseService.GetById(courseId);
if (course == null)
@@ -95,8 +95,8 @@ public class CourseController : BasePublicController
//model
var model = await _mediator.Send(new GetCourse {
Course = course,
- Customer = _workContextAccessor.WorkContext.CurrentCustomer,
- Language = _workContextAccessor.WorkContext.WorkingLanguage
+ Customer = _contextAccessor.WorkContext.CurrentCustomer,
+ Language = _contextAccessor.WorkContext.WorkingLanguage
});
return View(model);
@@ -105,7 +105,7 @@ public class CourseController : BasePublicController
[HttpGet]
public virtual async Task<IActionResult> Lesson(string id)
{
- var customer = _workContextAccessor.WorkContext.CurrentCustomer;
+ var customer = _contextAccessor.WorkContext.CurrentCustomer;
var lesson = await _courseLessonService.GetById(id);
if (lesson == null)
@@ -126,8 +126,8 @@ public class CourseController : BasePublicController
//model
var model = await _mediator.Send(new GetLesson {
Course = course,
- Customer = _workContextAccessor.WorkContext.CurrentCustomer,
- Language = _workContextAccessor.WorkContext.WorkingLanguage,
+ Customer = _contextAccessor.WorkContext.CurrentCustomer,
+ Language = _contextAccessor.WorkContext.WorkingLanguage,
Lesson = lesson
});
@@ -137,7 +137,7 @@ public class CourseController : BasePublicController
[HttpGet]
public virtual async Task<IActionResult> DownloadFile(string id)
{
- var customer = _workContextAccessor.WorkContext.CurrentCustomer;
+ var customer = _contextAccessor.WorkContext.CurrentCustomer;
var lesson = await _courseLessonService.GetById(id);
if (lesson == null || string.IsNullOrEmpty(lesson.AttachmentId))
@@ -173,7 +173,7 @@ public class CourseController : BasePublicController
[HttpGet]
public virtual async Task<IActionResult> VideoFile(string id)
{
- var customer = _workContextAccessor.WorkContext.CurrentCustomer;
+ var customer = _contextAccessor.WorkContext.CurrentCustomer;
var lesson = await _courseLessonService.GetById(id);
if (lesson == null || string.IsNullOrEmpty(lesson.VideoFile))
@@ -209,7 +209,7 @@ public class CourseController : BasePublicController
[HttpGet]
public virtual async Task<IActionResult> Approved(string id)
{
- var customer = _workContextAccessor.WorkContext.CurrentCustomer;
+ var customer = _contextAccessor.WorkContext.CurrentCustomer;
var lesson = await _courseLessonService.GetById(id);
if (lesson == null)
@@ -223,7 +223,7 @@ public class CourseController : BasePublicController
return Json(new { result = false });
await _mediator.Send(new CourseLessonApprovedCommand
- { Course = course, Lesson = lesson, Customer = _workContextAccessor.WorkContext.CurrentCustomer });
+ { Course = course, Lesson = lesson, Customer = _contextAccessor.WorkContext.CurrentCustomer });
return Json(new { result = true });
}
diff --git a/src/Web/Grand.Web/Controllers/DownloadController.cs b/src/Web/Grand.Web/Controllers/DownloadController.cs
index c17178b0a..7901784ff 100644
--- a/src/Web/Grand.Web/Controllers/DownloadController.cs
+++ b/src/Web/Grand.Web/Controllers/DownloadController.cs
@@ -29,13 +29,13 @@ public class DownloadController : BasePublicController
private readonly IOrderService _orderService;
private readonly IProductService _productService;
private readonly ITranslationService _translationService;
- private readonly IWorkContextAccessor _workContextAccessor;
+ private readonly IContextAccessor _contextAccessor;
public DownloadController(IDownloadService downloadService,
IProductService productService,
IOrderService orderService,
IMerchandiseReturnService merchandiseReturnService,
- IWorkContextAccessor workContextAccessor,
+ IContextAccessor contextAccessor,
ITranslationService translationService,
CustomerSettings customerSettings)
{
@@ -43,7 +43,7 @@ public class DownloadController : BasePublicController
_productService = productService;
_orderService = orderService;
_merchandiseReturnService = merchandiseReturnService;
- _workContextAccessor = workContextAccessor;
+ _contextAccessor = contextAccessor;
_translationService = translationService;
_customerSettings = customerSettings;
}
@@ -90,10 +90,10 @@ public class DownloadController : BasePublicController
if (_customerSettings.DownloadableProductsValidateUser)
{
- if (_workContextAccessor.WorkContext.CurrentCustomer == null)
+ if (_contextAccessor.WorkContext.CurrentCustomer == null)
return Challenge();
- if (order.CustomerId != _workContextAccessor.WorkContext.CurrentCustomer.Id && order.OwnerId != _workContextAccessor.WorkContext.CurrentCustomer.Id)
+ if (order.CustomerId != _contextAccessor.WorkContext.CurrentCustomer.Id && order.OwnerId != _contextAccessor.WorkContext.CurrentCustomer.Id)
return Content("This is not your order");
}
@@ -194,7 +194,7 @@ public class DownloadController : BasePublicController
return Content("Downloads are not allowed");
if (_customerSettings.DownloadableProductsValidateUser)
- if (order.CustomerId != _workContextAccessor.WorkContext.CurrentCustomer.Id && order.OwnerId != _workContextAccessor.WorkContext.CurrentCustomer.Id)
+ if (order.CustomerId != _contextAccessor.WorkContext.CurrentCustomer.Id && order.OwnerId != _contextAccessor.WorkContext.CurrentCustomer.Id)
return Challenge();
var download = await _downloadService.GetDownloadById(!string.IsNullOrEmpty(orderItem.LicenseDownloadId)
@@ -226,7 +226,7 @@ public class DownloadController : BasePublicController
if (download == null)
return Content("Download is not available any more.");
- if (_workContextAccessor.WorkContext.CurrentCustomer == null || download.CustomerId != _workContextAccessor.WorkContext.CurrentCustomer.Id)
+ if (_contextAccessor.WorkContext.CurrentCustomer == null || download.CustomerId != _contextAccessor.WorkContext.CurrentCustomer.Id)
return Challenge();
if (download.UseDownloadUrl)
@@ -256,8 +256,8 @@ public class DownloadController : BasePublicController
if (order == null)
return InvokeHttp404();
- if (_workContextAccessor.WorkContext.CurrentCustomer == null || (order.CustomerId != _workContextAccessor.WorkContext.CurrentCustomer.Id &&
- order.OwnerId != _workContextAccessor.WorkContext.CurrentCustomer.Id))
+ if (_contextAccessor.WorkContext.CurrentCustomer == null || (order.CustomerId != _contextAccessor.WorkContext.CurrentCustomer.Id &&
+ order.OwnerId != _contextAccessor.WorkContext.CurrentCustomer.Id))
return Challenge();
var download = await _downloadService.GetDownloadById(orderNote.DownloadId);
@@ -296,8 +296,8 @@ public class DownloadController : BasePublicController
if (order == null)
return InvokeHttp404();
- if (_workContextAccessor.WorkContext.CurrentCustomer == null || (order.CustomerId != _workContextAccessor.WorkContext.CurrentCustomer.Id &&
- order.OwnerId != _workContextAccessor.WorkContext.CurrentCustomer.Id))
+ if (_contextAccessor.WorkContext.CurrentCustomer == null || (order.CustomerId != _contextAccessor.WorkContext.CurrentCustomer.Id &&
+ order.OwnerId != _contextAccessor.WorkContext.CurrentCustomer.Id))
return Challenge();
var download = await _downloadService.GetDownloadById(shipmentNote.DownloadId);
@@ -331,7 +331,7 @@ public class DownloadController : BasePublicController
if (customerNote == null)
return InvokeHttp404();
- if (_workContextAccessor.WorkContext.CurrentCustomer == null || customerNote.CustomerId != _workContextAccessor.WorkContext.CurrentCustomer.Id)
+ if (_contextAccessor.WorkContext.CurrentCustomer == null || customerNote.CustomerId != _contextAccessor.WorkContext.CurrentCustomer.Id)
return Challenge();
var download = await _downloadService.GetDownloadById(customerNote.DownloadId);
@@ -366,7 +366,7 @@ public class DownloadController : BasePublicController
if (merchandiseReturn == null)
return InvokeHttp404();
- if (_workContextAccessor.WorkContext.CurrentCustomer == null || merchandiseReturn.CustomerId != _workContextAccessor.WorkContext.CurrentCustomer.Id)
+ if (_contextAccessor.WorkContext.CurrentCustomer == null || merchandiseReturn.CustomerId != _contextAccessor.WorkContext.CurrentCustomer.Id)
return Challenge();
var download = await _downloadService.GetDownloadById(merchandiseReturnNote.DownloadId);
@@ -400,7 +400,7 @@ public class DownloadController : BasePublicController
if (document is not { Published: true })
return InvokeHttp404();
- if (_workContextAccessor.WorkContext.CurrentCustomer == null || document.CustomerId != _workContextAccessor.WorkContext.CurrentCustomer.Id)
+ if (_contextAccessor.WorkContext.CurrentCustomer == null || document.CustomerId != _contextAccessor.WorkContext.CurrentCustomer.Id)
return Challenge();
var download = await _downloadService.GetDownloadById(document.DownloadId);
diff --git a/src/Web/Grand.Web/Controllers/KnowledgebaseController.cs b/src/Web/Grand.Web/Controllers/KnowledgebaseController.cs
index ff77326fa..40d38d9d1 100644
--- a/src/Web/Grand.Web/Controllers/KnowledgebaseController.cs
+++ b/src/Web/Grand.Web/Controllers/KnowledgebaseController.cs
@@ -36,12 +36,12 @@ public class KnowledgebaseController : BasePublicController
private readonly IMessageProviderService _messageProviderService;
private readonly IPermissionService _permissionService;
private readonly ITranslationService _translationService;
- private readonly IWorkContextAccessor _workContextAccessor;
+ private readonly IContextAccessor _contextAccessor;
public KnowledgebaseController(
KnowledgebaseSettings knowledgebaseSettings,
IKnowledgebaseService knowledgebaseService,
- IWorkContextAccessor workContextAccessor,
+ IContextAccessor contextAccessor,
ICacheBase cacheBase,
IAclService aclService,
ITranslationService translationService,
@@ -54,7 +54,7 @@ public class KnowledgebaseController : BasePublicController
{
_knowledgebaseSettings = knowledgebaseSettings;
_knowledgebaseService = knowledgebaseService;
- _workContextAccessor = workContextAccessor;
+ _contextAccessor = contextAccessor;
_cacheBase = cacheBase;
_aclService = aclService;
_translationService = translationService;
@@ -90,38 +90,38 @@ public class KnowledgebaseController : BasePublicController
var model = new KnowledgebaseHomePageModel();
var articles = await _knowledgebaseService.GetPublicKnowledgebaseArticlesByCategory(categoryId);
articles.ForEach(x => model.Items.Add(new KnowledgebaseItemModel {
- Name = x.GetTranslation(y => y.Name, _workContextAccessor.WorkContext.WorkingLanguage.Id),
+ Name = x.GetTranslation(y => y.Name, _contextAccessor.WorkContext.WorkingLanguage.Id),
Id = x.Id,
- SeName = x.GetTranslation(y => y.SeName, _workContextAccessor.WorkContext.WorkingLanguage.Id),
+ SeName = x.GetTranslation(y => y.SeName, _contextAccessor.WorkContext.WorkingLanguage.Id),
IsArticle = true
}));
//display "edit" (manage) link
- var customer = _workContextAccessor.WorkContext.CurrentCustomer;
+ var customer = _contextAccessor.WorkContext.CurrentCustomer;
if (await _permissionService.Authorize(StandardPermission.ManageAccessAdminPanel, customer) &&
await _permissionService.Authorize(StandardPermission.ManageKnowledgebase, customer))
DisplayEditLink(Url.Action("EditCategory", "Knowledgebase", new { id = categoryId, area = "Admin" }));
model.CurrentCategoryId = categoryId;
- model.CurrentCategoryDescription = category.GetTranslation(y => y.Description, _workContextAccessor.WorkContext.WorkingLanguage.Id);
+ model.CurrentCategoryDescription = category.GetTranslation(y => y.Description, _contextAccessor.WorkContext.WorkingLanguage.Id);
model.CurrentCategoryMetaDescription =
- category.GetTranslation(y => y.MetaDescription, _workContextAccessor.WorkContext.WorkingLanguage.Id);
+ category.GetTranslation(y => y.MetaDescription, _contextAccessor.WorkContext.WorkingLanguage.Id);
model.CurrentCategoryMetaKeywords =
- category.GetTranslation(y => y.MetaKeywords, _workContextAccessor.WorkContext.WorkingLanguage.Id);
- model.CurrentCategoryMetaTitle = category.GetTranslation(y => y.MetaTitle, _workContextAccessor.WorkContext.WorkingLanguage.Id);
- model.CurrentCategoryName = category.GetTranslation(y => y.Name, _workContextAccessor.WorkContext.WorkingLanguage.Id);
- model.CurrentCategorySeName = category.GetTranslation(y => y.SeName, _workContextAccessor.WorkContext.WorkingLanguage.Id);
+ category.GetTranslation(y => y.MetaKeywords, _contextAccessor.WorkContext.WorkingLanguage.Id);
+ model.CurrentCategoryMetaTitle = category.GetTranslation(y => y.MetaTitle, _contextAccessor.WorkContext.WorkingLanguage.Id);
+ model.CurrentCategoryName = category.GetTranslation(y => y.Name, _contextAccessor.WorkContext.WorkingLanguage.Id);
+ model.CurrentCategorySeName = category.GetTranslation(y => y.SeName, _contextAccessor.WorkContext.WorkingLanguage.Id);
var breadcrumbCacheKey = string.Format(CacheKeyConst.KNOWLEDGEBASE_CATEGORY_BREADCRUMB_KEY, category.Id,
- string.Join(",", _workContextAccessor.WorkContext.CurrentCustomer.GetCustomerGroupIds()), _workContextAccessor.WorkContext.CurrentStore.Id,
- _workContextAccessor.WorkContext.WorkingLanguage.Id);
+ string.Join(",", _contextAccessor.WorkContext.CurrentCustomer.GetCustomerGroupIds()), _contextAccessor.StoreContext.CurrentStore.Id,
+ _contextAccessor.WorkContext.WorkingLanguage.Id);
model.CategoryBreadcrumb = await _cacheBase.GetAsync(breadcrumbCacheKey, async () =>
(await GetCategoryBreadCrumb(category))
.Select(catBr => new KnowledgebaseCategoryModel {
Id = catBr.Id,
- Name = catBr.GetTranslation(x => x.Name, _workContextAccessor.WorkContext.WorkingLanguage.Id),
- SeName = catBr.GetSeName(_workContextAccessor.WorkContext.WorkingLanguage.Id)
+ Name = catBr.GetTranslation(x => x.Name, _contextAccessor.WorkContext.WorkingLanguage.Id),
+ SeName = catBr.GetSeName(_contextAccessor.WorkContext.WorkingLanguage.Id)
})
.ToList()
);
@@ -142,9 +142,9 @@ public class KnowledgebaseController : BasePublicController
var categories = await _knowledgebaseService.GetPublicKnowledgebaseCategoriesByKeyword(keyword);
var allCategories = await _knowledgebaseService.GetPublicKnowledgebaseCategories();
categories.ForEach(x => model.Items.Add(new KnowledgebaseItemModel {
- Name = x.GetTranslation(y => y.Name, _workContextAccessor.WorkContext.WorkingLanguage.Id),
+ Name = x.GetTranslation(y => y.Name, _contextAccessor.WorkContext.WorkingLanguage.Id),
Id = x.Id,
- SeName = x.GetTranslation(y => y.SeName, _workContextAccessor.WorkContext.WorkingLanguage.Id),
+ SeName = x.GetTranslation(y => y.SeName, _contextAccessor.WorkContext.WorkingLanguage.Id),
IsArticle = false,
FormattedBreadcrumbs = x.GetFormattedBreadCrumb(allCategories, ">")
}));
@@ -153,14 +153,14 @@ public class KnowledgebaseController : BasePublicController
foreach (var item in articles)
{
var kbm = new KnowledgebaseItemModel {
- Name = item.GetTranslation(y => y.Name, _workContextAccessor.WorkContext.WorkingLanguage.Id),
+ Name = item.GetTranslation(y => y.Name, _contextAccessor.WorkContext.WorkingLanguage.Id),
Id = item.Id,
- SeName = item.GetTranslation(y => y.SeName, _workContextAccessor.WorkContext.WorkingLanguage.Id),
+ SeName = item.GetTranslation(y => y.SeName, _contextAccessor.WorkContext.WorkingLanguage.Id),
IsArticle = true,
FormattedBreadcrumbs =
(await _knowledgebaseService.GetPublicKnowledgebaseCategory(item.ParentCategoryId))
?.GetFormattedBreadCrumb(allCategories, ">") +
- " > " + item.GetTranslation(y => y.Name, _workContextAccessor.WorkContext.WorkingLanguage.Id)
+ " > " + item.GetTranslation(y => y.Name, _contextAccessor.WorkContext.WorkingLanguage.Id)
};
model.Items.Add(kbm);
}
@@ -179,7 +179,7 @@ public class KnowledgebaseController : BasePublicController
if (!_knowledgebaseSettings.Enabled)
return RedirectToRoute("HomePage");
- var customer = _workContextAccessor.WorkContext.CurrentCustomer;
+ var customer = _contextAccessor.WorkContext.CurrentCustomer;
var article = await _knowledgebaseService.GetKnowledgebaseArticle(articleId);
if (article == null)
return RedirectToAction("List");
@@ -189,7 +189,7 @@ public class KnowledgebaseController : BasePublicController
return InvokeHttp404();
//Store acl
- if (!_aclService.Authorize(article, _workContextAccessor.WorkContext.CurrentStore.Id))
+ if (!_aclService.Authorize(article, _contextAccessor.StoreContext.CurrentStore.Id))
return InvokeHttp404();
//display "edit" (manage) link
@@ -206,17 +206,17 @@ public class KnowledgebaseController : BasePublicController
private async Task PrepareKnowledgebaseArticleModel(KnowledgebaseArticleModel model, KnowledgebaseArticle article,
ICustomerService customerService)
{
- model.Content = article.GetTranslation(y => y.Content, _workContextAccessor.WorkContext.WorkingLanguage.Id);
- model.Name = article.GetTranslation(y => y.Name, _workContextAccessor.WorkContext.WorkingLanguage.Id);
+ model.Content = article.GetTranslation(y => y.Content, _contextAccessor.WorkContext.WorkingLanguage.Id);
+ model.Name = article.GetTranslation(y => y.Name, _contextAccessor.WorkContext.WorkingLanguage.Id);
model.Id = article.Id;
model.ParentCategoryId = article.ParentCategoryId;
- model.SeName = article.GetTranslation(y => y.SeName, _workContextAccessor.WorkContext.WorkingLanguage.Id);
+ model.SeName = article.GetTranslation(y => y.SeName, _contextAccessor.WorkContext.WorkingLanguage.Id);
model.AllowComments = article.AllowComments;
model.AddNewComment.DisplayCaptcha = _captchaSettings.Enabled && _captchaSettings.ShowOnArticleCommentPage;
- model.MetaTitle = article.GetTranslation(y => y.MetaTitle, _workContextAccessor.WorkContext.WorkingLanguage.Id);
- model.MetaDescription = article.GetTranslation(y => y.MetaDescription, _workContextAccessor.WorkContext.WorkingLanguage.Id);
- model.MetaKeywords = article.GetTranslation(y => y.MetaKeywords, _workContextAccessor.WorkContext.WorkingLanguage.Id);
+ model.MetaTitle = article.GetTranslation(y => y.MetaTitle, _contextAccessor.WorkContext.WorkingLanguage.Id);
+ model.MetaDescription = article.GetTranslation(y => y.MetaDescription, _contextAccessor.WorkContext.WorkingLanguage.Id);
+ model.MetaKeywords = article.GetTranslation(y => y.MetaKeywords, _contextAccessor.WorkContext.WorkingLanguage.Id);
var articleComments = await _knowledgebaseService.GetArticleCommentsByArticleId(article.Id);
foreach (var ac in articleComments)
@@ -248,15 +248,15 @@ public class KnowledgebaseController : BasePublicController
{
var breadcrumbCacheKey = string.Format(CacheKeyConst.KNOWLEDGEBASE_CATEGORY_BREADCRUMB_KEY,
article.ParentCategoryId,
- string.Join(",", _workContextAccessor.WorkContext.CurrentCustomer.GetCustomerGroupIds()),
- _workContextAccessor.WorkContext.CurrentStore.Id,
- _workContextAccessor.WorkContext.WorkingLanguage.Id);
+ string.Join(",", _contextAccessor.WorkContext.CurrentCustomer.GetCustomerGroupIds()),
+ _contextAccessor.StoreContext.CurrentStore.Id,
+ _contextAccessor.WorkContext.WorkingLanguage.Id);
model.CategoryBreadcrumb = await _cacheBase.GetAsync(breadcrumbCacheKey, async () =>
(await GetCategoryBreadCrumb(category))
.Select(catBr => new KnowledgebaseCategoryModel {
Id = catBr.Id,
- Name = catBr.GetTranslation(x => x.Name, _workContextAccessor.WorkContext.WorkingLanguage.Id),
- SeName = catBr.GetSeName(_workContextAccessor.WorkContext.WorkingLanguage.Id)
+ Name = catBr.GetTranslation(x => x.Name, _contextAccessor.WorkContext.WorkingLanguage.Id),
+ SeName = catBr.GetSeName(_contextAccessor.WorkContext.WorkingLanguage.Id)
})
.ToList()
);
@@ -278,7 +278,7 @@ public class KnowledgebaseController : BasePublicController
if (ModelState.IsValid)
{
- var customer = _workContextAccessor.WorkContext.CurrentCustomer;
+ var customer = _contextAccessor.WorkContext.CurrentCustomer;
var comment = new KnowledgebaseArticleComment {
ArticleId = article.Id,
CustomerId = customer.Id,
@@ -299,7 +299,7 @@ public class KnowledgebaseController : BasePublicController
TempData["Grand.knowledgebase.addarticlecomment.result"] =
_translationService.GetResource("Knowledgebase.Article.Comments.SuccessfullyAdded");
return RedirectToRoute("KnowledgebaseArticle",
- new { SeName = article.GetSeName(_workContextAccessor.WorkContext.WorkingLanguage.Id) });
+ new { SeName = article.GetSeName(_contextAccessor.WorkContext.WorkingLanguage.Id) });
}
//If we got this far, something failed, redisplay form
@@ -318,8 +318,8 @@ public class KnowledgebaseController : BasePublicController
while (category != null && //not null
(showHidden || category.Published) && //published
- (showHidden || _aclService.Authorize(category, _workContextAccessor.WorkContext.CurrentCustomer)) && //ACL
- (showHidden || _aclService.Authorize(category, _workContextAccessor.WorkContext.CurrentStore.Id)) && //Store acl
+ (showHidden || _aclService.Authorize(category, _contextAccessor.WorkContext.CurrentCustomer)) && //ACL
+ (showHidden || _aclService.Authorize(category, _contextAccessor.StoreContext.CurrentStore.Id)) && //Store acl
!alreadyProcessedCategoryIds.Contains(category.Id)) //prevent circular references
{
result.Add(category);
diff --git a/src/Web/Grand.Web/Controllers/MerchandiseReturnController.cs b/src/Web/Grand.Web/Controllers/MerchandiseReturnController.cs
index 3f9e8bc0f..dbcef4154 100644
--- a/src/Web/Grand.Web/Controllers/MerchandiseReturnController.cs
+++ b/src/Web/Grand.Web/Controllers/MerchandiseReturnController.cs
@@ -29,7 +29,7 @@ public class MerchandiseReturnController : BasePublicController
public MerchandiseReturnController(
IMerchandiseReturnService merchandiseReturnService,
IOrderService orderService,
- IWorkContextAccessor workContextAccessor,
+ IContextAccessor contextAccessor,
IGroupService groupService,
ITranslationService translationService,
IMediator mediator,
@@ -38,7 +38,7 @@ public class MerchandiseReturnController : BasePublicController
{
_merchandiseReturnService = merchandiseReturnService;
_orderService = orderService;
- _workContextAccessor = workContextAccessor;
+ _contextAccessor = contextAccessor;
_groupService = groupService;
_translationService = translationService;
_mediator = mediator;
@@ -52,7 +52,7 @@ public class MerchandiseReturnController : BasePublicController
private readonly IMerchandiseReturnService _merchandiseReturnService;
private readonly IOrderService _orderService;
- private readonly IWorkContextAccessor _workContextAccessor;
+ private readonly IContextAccessor _contextAccessor;
private readonly IGroupService _groupService;
private readonly ITranslationService _translationService;
private readonly IMediator _mediator;
@@ -67,11 +67,11 @@ public class MerchandiseReturnController : BasePublicController
{
var countryService = HttpContext.RequestServices.GetRequiredService<ICountryService>();
var countries =
- await countryService.GetAllCountries(_workContextAccessor.WorkContext.WorkingLanguage.Id, _workContextAccessor.WorkContext.CurrentStore.Id);
+ await countryService.GetAllCountries(_contextAccessor.WorkContext.WorkingLanguage.Id, _contextAccessor.StoreContext.CurrentStore.Id);
addressModel = await _mediator.Send(new GetAddressModel {
- Language = _workContextAccessor.WorkContext.WorkingLanguage,
- Store = _workContextAccessor.WorkContext.CurrentStore,
- Customer = _workContextAccessor.WorkContext.CurrentCustomer,
+ Language = _contextAccessor.WorkContext.WorkingLanguage,
+ Store = _contextAccessor.StoreContext.CurrentStore,
+ Customer = _contextAccessor.WorkContext.CurrentCustomer,
Model = addressModel,
Address = address,
ExcludeProperties = true,
@@ -87,13 +87,13 @@ public class MerchandiseReturnController : BasePublicController
if (!string.IsNullOrEmpty(model.PickupAddressId))
{
- address = _workContextAccessor.WorkContext.CurrentCustomer.Addresses.FirstOrDefault(a => a.Id == model.PickupAddressId);
+ address = _contextAccessor.WorkContext.CurrentCustomer.Addresses.FirstOrDefault(a => a.Id == model.PickupAddressId);
}
else
{
var customAttributes = await _mediator.Send(new GetParseCustomAddressAttributes
{ SelectedAttributes = model.MerchandiseReturnNewAddress.SelectedAttributes });
- address = model.MerchandiseReturnNewAddress.ToEntity(_workContextAccessor.WorkContext.CurrentCustomer, _addressSettings);
+ address = model.MerchandiseReturnNewAddress.ToEntity(_contextAccessor.WorkContext.CurrentCustomer, _addressSettings);
model.NewAddressPreselected = true;
address.Attributes = customAttributes;
}
@@ -108,13 +108,13 @@ public class MerchandiseReturnController : BasePublicController
[HttpGet]
public virtual async Task<IActionResult> CustomerMerchandiseReturns()
{
- if (!await _groupService.IsRegistered(_workContextAccessor.WorkContext.CurrentCustomer))
+ if (!await _groupService.IsRegistered(_contextAccessor.WorkContext.CurrentCustomer))
return Challenge();
var model = await _mediator.Send(new GetMerchandiseReturns {
- Customer = _workContextAccessor.WorkContext.CurrentCustomer,
- Store = _workContextAccessor.WorkContext.CurrentStore,
- Language = _workContextAccessor.WorkContext.WorkingLanguage
+ Customer = _contextAccessor.WorkContext.CurrentCustomer,
+ Store = _contextAccessor.StoreContext.CurrentStore,
+ Language = _contextAccessor.WorkContext.WorkingLanguage
});
return View(model);
@@ -124,7 +124,7 @@ public class MerchandiseReturnController : BasePublicController
public virtual async Task<IActionResult> MerchandiseReturn(string orderId)
{
var order = await _orderService.GetOrderById(orderId);
- if (!await order.Access(_workContextAccessor.WorkContext.CurrentCustomer, _groupService))
+ if (!await order.Access(_contextAccessor.WorkContext.CurrentCustomer, _groupService))
return Challenge();
if (!await _mediator.Send(new IsMerchandiseReturnAllowedQuery { Order = order }))
@@ -132,8 +132,8 @@ public class MerchandiseReturnController : BasePublicController
var model = await _mediator.Send(new GetMerchandiseReturn {
Order = order,
- Language = _workContextAccessor.WorkContext.WorkingLanguage,
- Store = _workContextAccessor.WorkContext.CurrentStore
+ Language = _contextAccessor.WorkContext.WorkingLanguage,
+ Store = _contextAccessor.StoreContext.CurrentStore
});
return View(model);
}
@@ -143,7 +143,7 @@ public class MerchandiseReturnController : BasePublicController
public virtual async Task<IActionResult> MerchandiseReturn(MerchandiseReturnModel model)
{
var order = await _orderService.GetOrderById(model.OrderId);
- if (!await order.Access(_workContextAccessor.WorkContext.CurrentCustomer, _groupService))
+ if (!await order.Access(_contextAccessor.WorkContext.CurrentCustomer, _groupService))
return Challenge();
if (!await _mediator.Send(new IsMerchandiseReturnAllowedQuery { Order = order }))
@@ -166,8 +166,8 @@ public class MerchandiseReturnController : BasePublicController
var returnModel = await _mediator.Send(new GetMerchandiseReturn {
Order = order,
- Language = _workContextAccessor.WorkContext.WorkingLanguage,
- Store = _workContextAccessor.WorkContext.CurrentStore
+ Language = _contextAccessor.WorkContext.WorkingLanguage,
+ Store = _contextAccessor.StoreContext.CurrentStore
});
returnModel.Error = string.Join(", ",
ModelState.Keys.SelectMany(k => ModelState[k]!.Errors).Select(m => m.ErrorMessage).ToArray());
@@ -185,16 +185,16 @@ public class MerchandiseReturnController : BasePublicController
public virtual async Task<IActionResult> MerchandiseReturnDetails(string merchandiseReturnId)
{
var rr = await _merchandiseReturnService.GetMerchandiseReturnById(merchandiseReturnId);
- if (!await rr.Access(_workContextAccessor.WorkContext.CurrentCustomer, _groupService))
+ if (!await rr.Access(_contextAccessor.WorkContext.CurrentCustomer, _groupService))
return Challenge();
var order = await _orderService.GetOrderById(rr.OrderId);
- if (!await order.Access(_workContextAccessor.WorkContext.CurrentCustomer, _groupService))
+ if (!await order.Access(_contextAccessor.WorkContext.CurrentCustomer, _groupService))
return Challenge();
var model = await _mediator.Send(new GetMerchandiseReturnDetails {
Order = order,
- Language = _workContextAccessor.WorkContext.WorkingLanguage,
+ Language = _contextAccessor.WorkContext.WorkingLanguage,
MerchandiseReturn = rr
});
diff --git a/src/Web/Grand.Web/Controllers/NewsController.cs b/src/Web/Grand.Web/Controllers/NewsController.cs
index 3efd252fb..7c1e32043 100644
--- a/src/Web/Grand.Web/Controllers/NewsController.cs
+++ b/src/Web/Grand.Web/Controllers/NewsController.cs
@@ -26,7 +26,7 @@ public class NewsController : BasePublicController
#region Constructors
public NewsController(INewsService newsService,
- IWorkContextAccessor workContextAccessor,
+ IContextAccessor contextAccessor,
ITranslationService translationService,
IAclService aclService,
IPermissionService permissionService,
@@ -34,7 +34,7 @@ public class NewsController : BasePublicController
NewsSettings newsSettings)
{
_newsService = newsService;
- _workContextAccessor = workContextAccessor;
+ _contextAccessor = contextAccessor;
_translationService = translationService;
_aclService = aclService;
_permissionService = permissionService;
@@ -47,7 +47,7 @@ public class NewsController : BasePublicController
#region Fields
private readonly INewsService _newsService;
- private readonly IWorkContextAccessor _workContextAccessor;
+ private readonly IContextAccessor _contextAccessor;
private readonly ITranslationService _translationService;
private readonly IAclService _aclService;
private readonly IPermissionService _permissionService;
@@ -81,7 +81,7 @@ public class NewsController : BasePublicController
(newsItem.StartDateUtc.HasValue && newsItem.StartDateUtc.Value >= DateTime.UtcNow) ||
(newsItem.EndDateUtc.HasValue && newsItem.EndDateUtc.Value <= DateTime.UtcNow) ||
//Store acl
- !_aclService.Authorize(newsItem, _workContextAccessor.WorkContext.CurrentStore.Id))
+ !_aclService.Authorize(newsItem, _contextAccessor.StoreContext.CurrentStore.Id))
return RedirectToRoute("HomePage");
var model = await _mediator.Send(new GetNewsItem { NewsItem = newsItem });
@@ -125,7 +125,7 @@ public class NewsController : BasePublicController
newsComment.CommentTitle,
CreatedOn = HttpContext.RequestServices.GetService<IDateTimeService>()
.ConvertToUserTime(newsComment.CreatedOnUtc, DateTimeKind.Utc),
- CustomerName = _workContextAccessor.WorkContext.CurrentCustomer.FormatUserName(HttpContext.RequestServices
+ CustomerName = _contextAccessor.WorkContext.CurrentCustomer.FormatUserName(HttpContext.RequestServices
.GetService<CustomerSettings>().CustomerNameFormat)
}
});
diff --git a/src/Web/Grand.Web/Controllers/OrderController.cs b/src/Web/Grand.Web/Controllers/OrderController.cs
index ab21431e3..5020fe39c 100644
--- a/src/Web/Grand.Web/Controllers/OrderController.cs
+++ b/src/Web/Grand.Web/Controllers/OrderController.cs
@@ -33,7 +33,7 @@ public class OrderController : BasePublicController
#region Constructors
public OrderController(IOrderService orderService,
- IWorkContextAccessor workContextAccessor,
+ IContextAccessor contextAccessor,
IPaymentService paymentService,
IPaymentTransactionService paymentTransactionService,
ITranslationService translationService,
@@ -42,7 +42,7 @@ public class OrderController : BasePublicController
OrderSettings orderSettings)
{
_orderService = orderService;
- _workContextAccessor = workContextAccessor;
+ _contextAccessor = contextAccessor;
_paymentService = paymentService;
_paymentTransactionService = paymentTransactionService;
_translationService = translationService;
@@ -56,7 +56,7 @@ public class OrderController : BasePublicController
#region Fields
private readonly IOrderService _orderService;
- private readonly IWorkContextAccessor _workContextAccessor;
+ private readonly IContextAccessor _contextAccessor;
private readonly IPaymentService _paymentService;
private readonly IPaymentTransactionService _paymentTransactionService;
private readonly ITranslationService _translationService;
@@ -75,9 +75,9 @@ public class OrderController : BasePublicController
public virtual async Task<IActionResult> CustomerOrders(OrderPagingModel command)
{
var model = await _mediator.Send(new GetCustomerOrderList {
- Customer = _workContextAccessor.WorkContext.CurrentCustomer,
- Language = _workContextAccessor.WorkContext.WorkingLanguage,
- Store = _workContextAccessor.WorkContext.CurrentStore,
+ Customer = _contextAccessor.WorkContext.CurrentCustomer,
+ Language = _contextAccessor.WorkContext.WorkingLanguage,
+ Store = _contextAccessor.StoreContext.CurrentStore,
Command = command
});
return View(model);
@@ -89,11 +89,11 @@ public class OrderController : BasePublicController
public virtual async Task<IActionResult> Details(string orderId)
{
var order = await _orderService.GetOrderById(orderId);
- if (!await order.Access(_workContextAccessor.WorkContext.CurrentCustomer, _groupService))
+ if (!await order.Access(_contextAccessor.WorkContext.CurrentCustomer, _groupService))
return Challenge();
var model = await _mediator.Send(new GetOrderDetails
- { Order = order, Language = _workContextAccessor.WorkContext.WorkingLanguage });
+ { Order = order, Language = _contextAccessor.WorkContext.WorkingLanguage });
return View(model);
}
@@ -103,7 +103,7 @@ public class OrderController : BasePublicController
public virtual async Task<IActionResult> CancelOrder(string orderId)
{
var order = await _orderService.GetOrderById(orderId);
- if (!await order.Access(_workContextAccessor.WorkContext.CurrentCustomer, _groupService)
+ if (!await order.Access(_contextAccessor.WorkContext.CurrentCustomer, _groupService)
|| order.PaymentStatusId != PaymentStatus.Pending
|| (order.ShippingStatusId != ShippingStatus.ShippingNotRequired &&
order.ShippingStatusId != ShippingStatus.Pending)
@@ -122,14 +122,14 @@ public class OrderController : BasePublicController
public virtual async Task<IActionResult> GetPdfInvoice(string orderId, [FromServices] IPdfService pdfService)
{
var order = await _orderService.GetOrderById(orderId);
- if (!await order.Access(_workContextAccessor.WorkContext.CurrentCustomer, _groupService))
+ if (!await order.Access(_contextAccessor.WorkContext.CurrentCustomer, _groupService))
return Challenge();
var orders = new List<Order> { order };
byte[] bytes;
using (var stream = new MemoryStream())
{
- await pdfService.PrintOrdersToPdf(stream, orders, _workContextAccessor.WorkContext.WorkingLanguage.Id);
+ await pdfService.PrintOrdersToPdf(stream, orders, _contextAccessor.WorkContext.WorkingLanguage.Id);
bytes = stream.ToArray();
}
@@ -148,11 +148,11 @@ public class OrderController : BasePublicController
if (!ModelState.IsValid) return View("AddOrderNote", model);
var order = await _orderService.GetOrderById(model.OrderId);
- if (!await order.Access(_workContextAccessor.WorkContext.CurrentCustomer, _groupService))
+ if (!await order.Access(_contextAccessor.WorkContext.CurrentCustomer, _groupService))
return Challenge();
await _mediator.Send(new InsertOrderNoteCommand
- { Order = order, OrderNote = model, Language = _workContextAccessor.WorkContext.WorkingLanguage });
+ { Order = order, OrderNote = model, Language = _contextAccessor.WorkContext.WorkingLanguage });
//notification
await _mediator.Publish(new OrderNoteEvent(order, model));
@@ -166,7 +166,7 @@ public class OrderController : BasePublicController
public virtual async Task<IActionResult> ReOrder(string orderId)
{
var order = await _orderService.GetOrderById(orderId);
- if (!await order.Access(_workContextAccessor.WorkContext.CurrentCustomer, _groupService))
+ if (!await order.Access(_contextAccessor.WorkContext.CurrentCustomer, _groupService))
return Challenge();
var warnings = await _mediator.Send(new ReOrderCommand { Order = order });
@@ -182,7 +182,7 @@ public class OrderController : BasePublicController
public virtual async Task<IActionResult> RePostPayment(string orderId)
{
var order = await _orderService.GetOrderById(orderId);
- if (!await order.Access(_workContextAccessor.WorkContext.CurrentCustomer, _groupService))
+ if (!await order.Access(_contextAccessor.WorkContext.CurrentCustomer, _groupService))
return Challenge();
var paymentTransaction = await _paymentTransactionService.GetOrderByGuid(order.OrderGuid);
@@ -208,12 +208,12 @@ public class OrderController : BasePublicController
return Challenge();
var order = await _orderService.GetOrderById(shipment.OrderId);
- if (!await order.Access(_workContextAccessor.WorkContext.CurrentCustomer, _groupService))
+ if (!await order.Access(_contextAccessor.WorkContext.CurrentCustomer, _groupService))
return Challenge();
var model = await _mediator.Send(new GetShipmentDetails {
- Customer = _workContextAccessor.WorkContext.CurrentCustomer,
- Language = _workContextAccessor.WorkContext.WorkingLanguage,
+ Customer = _contextAccessor.WorkContext.CurrentCustomer,
+ Language = _contextAccessor.WorkContext.WorkingLanguage,
Order = order,
Shipment = shipment
});
@@ -232,9 +232,9 @@ public class OrderController : BasePublicController
return RedirectToRoute("CustomerInfo");
var model = await _mediator.Send(new GetCustomerLoyaltyPoints {
- Customer = _workContextAccessor.WorkContext.CurrentCustomer,
- Store = _workContextAccessor.WorkContext.CurrentStore,
- Currency = _workContextAccessor.WorkContext.WorkingCurrency
+ Customer = _contextAccessor.WorkContext.CurrentCustomer,
+ Store = _contextAccessor.StoreContext.CurrentStore,
+ Currency = _contextAccessor.WorkContext.WorkingCurrency
});
return View(model);
}
diff --git a/src/Web/Grand.Web/Controllers/OutOfStockSubscriptionController.cs b/src/Web/Grand.Web/Controllers/OutOfStockSubscriptionController.cs
index e54281bf0..3e54c6ed8 100644
--- a/src/Web/Grand.Web/Controllers/OutOfStockSubscriptionController.cs
+++ b/src/Web/Grand.Web/Controllers/OutOfStockSubscriptionController.cs
@@ -23,7 +23,7 @@ public class OutOfStockSubscriptionController : BasePublicController
#region Constructors
public OutOfStockSubscriptionController(IProductService productService,
- IWorkContextAccessor workContextAccessor,
+ IContextAccessor contextAccessor,
IGroupService groupService,
ITranslationService translationService,
IOutOfStockSubscriptionService outOfStockSubscriptionService,
@@ -34,7 +34,7 @@ public class OutOfStockSubscriptionController : BasePublicController
ShoppingCartSettings shoppingCartSettings)
{
_productService = productService;
- _workContextAccessor = workContextAccessor;
+ _contextAccessor = contextAccessor;
_groupService = groupService;
_translationService = translationService;
_outOfStockSubscriptionService = outOfStockSubscriptionService;
@@ -50,7 +50,7 @@ public class OutOfStockSubscriptionController : BasePublicController
#region Fields
private readonly IProductService _productService;
- private readonly IWorkContextAccessor _workContextAccessor;
+ private readonly IContextAccessor _contextAccessor;
private readonly IGroupService _groupService;
private readonly ITranslationService _translationService;
private readonly IOutOfStockSubscriptionService _outOfStockSubscriptionService;
@@ -72,7 +72,7 @@ public class OutOfStockSubscriptionController : BasePublicController
if (product == null)
throw new ArgumentException("No product found with the specified id");
- var customer = _workContextAccessor.WorkContext.CurrentCustomer;
+ var customer = _contextAccessor.WorkContext.CurrentCustomer;
if (!await _groupService.IsRegistered(customer))
return Content(_translationService.GetResource("OutOfStockSubscriptions.OnlyRegistered"));
@@ -81,12 +81,12 @@ public class OutOfStockSubscriptionController : BasePublicController
warehouseId = _shoppingCartSettings.AllowToSelectWarehouse
? string.IsNullOrEmpty(warehouseId) ? "" : warehouseId
- : string.IsNullOrEmpty(_workContextAccessor.WorkContext.CurrentStore.DefaultWarehouseId)
+ : string.IsNullOrEmpty(_contextAccessor.StoreContext.CurrentStore.DefaultWarehouseId)
? product.WarehouseId
- : _workContextAccessor.WorkContext.CurrentStore.DefaultWarehouseId;
+ : _contextAccessor.StoreContext.CurrentStore.DefaultWarehouseId;
var subscription = await _outOfStockSubscriptionService
- .FindSubscription(customer.Id, product.Id, null, _workContextAccessor.WorkContext.CurrentStore.Id,
+ .FindSubscription(customer.Id, product.Id, null, _contextAccessor.StoreContext.CurrentStore.Id,
warehouseId);
return Content(subscription != null
@@ -101,11 +101,11 @@ public class OutOfStockSubscriptionController : BasePublicController
if (product == null)
throw new ArgumentException("No product found with the specified id");
- var customer = _workContextAccessor.WorkContext.CurrentCustomer;
+ var customer = _contextAccessor.WorkContext.CurrentCustomer;
var warehouseId = _shoppingCartSettings.AllowToSelectWarehouse ? model.WarehouseId :
- product.UseMultipleWarehouses ? _workContextAccessor.WorkContext.CurrentStore.DefaultWarehouseId :
- string.IsNullOrEmpty(_workContextAccessor.WorkContext.CurrentStore.DefaultWarehouseId) ? product.WarehouseId :
- _workContextAccessor.WorkContext.CurrentStore.DefaultWarehouseId;
+ product.UseMultipleWarehouses ? _contextAccessor.StoreContext.CurrentStore.DefaultWarehouseId :
+ string.IsNullOrEmpty(_contextAccessor.StoreContext.CurrentStore.DefaultWarehouseId) ? product.WarehouseId :
+ _contextAccessor.StoreContext.CurrentStore.DefaultWarehouseId;
if (!await _groupService.IsRegistered(customer))
return Json(new {
@@ -120,7 +120,7 @@ public class OutOfStockSubscriptionController : BasePublicController
_stockQuantityService.GetTotalStockQuantity(product, warehouseId: warehouseId) <= 0)
{
var subscription = await _outOfStockSubscriptionService
- .FindSubscription(customer.Id, product.Id, null, _workContextAccessor.WorkContext.CurrentStore.Id, warehouseId);
+ .FindSubscription(customer.Id, product.Id, null, _contextAccessor.StoreContext.CurrentStore.Id, warehouseId);
if (subscription != null)
{
//subscription already exists
@@ -138,7 +138,7 @@ public class OutOfStockSubscriptionController : BasePublicController
subscription = new OutOfStockSubscription {
CustomerId = customer.Id,
ProductId = product.Id,
- StoreId = _workContextAccessor.WorkContext.CurrentStore.Id,
+ StoreId = _contextAccessor.StoreContext.CurrentStore.Id,
WarehouseId = warehouseId
};
await _outOfStockSubscriptionService.InsertSubscription(subscription);
@@ -161,7 +161,7 @@ public class OutOfStockSubscriptionController : BasePublicController
var attributes = await _mediator.Send(new GetParseProductAttributes
{ Product = product, Attributes = model.Attributes });
var subscriptionAttributes = await _outOfStockSubscriptionService
- .FindSubscription(customer.Id, product.Id, attributes, _workContextAccessor.WorkContext.CurrentStore.Id, warehouseId);
+ .FindSubscription(customer.Id, product.Id, attributes, _contextAccessor.StoreContext.CurrentStore.Id, warehouseId);
if (subscriptionAttributes != null)
{
@@ -182,7 +182,7 @@ public class OutOfStockSubscriptionController : BasePublicController
AttributeInfo = !attributes.Any()
? ""
: await _productAttributeFormatter.FormatAttributes(product, attributes),
- StoreId = _workContextAccessor.WorkContext.CurrentStore.Id,
+ StoreId = _contextAccessor.StoreContext.CurrentStore.Id,
WarehouseId = warehouseId
};
@@ -206,9 +206,9 @@ public class OutOfStockSubscriptionController : BasePublicController
const int pageSize = 10;
- var customer = _workContextAccessor.WorkContext.CurrentCustomer;
+ var customer = _contextAccessor.WorkContext.CurrentCustomer;
var list = await _outOfStockSubscriptionService.GetAllSubscriptionsByCustomerId(customer.Id,
- _workContextAccessor.WorkContext.CurrentStore.Id, pageIndex, pageSize);
+ _contextAccessor.StoreContext.CurrentStore.Id, pageIndex, pageSize);
var model = new CustomerOutOfStockSubscriptionsModel();
@@ -219,11 +219,11 @@ public class OutOfStockSubscriptionController : BasePublicController
var subscriptionModel = new CustomerOutOfStockSubscriptionsModel.OutOfStockSubscriptionModel {
Id = subscription.Id,
ProductId = product.Id,
- ProductName = product.GetTranslation(x => x.Name, _workContextAccessor.WorkContext.WorkingLanguage.Id),
+ ProductName = product.GetTranslation(x => x.Name, _contextAccessor.WorkContext.WorkingLanguage.Id),
AttributeDescription = !subscription.Attributes.Any()
? ""
: await _productAttributeFormatter.FormatAttributes(product, subscription.Attributes),
- SeName = product.GetSeName(_workContextAccessor.WorkContext.WorkingLanguage.Id)
+ SeName = product.GetSeName(_contextAccessor.WorkContext.WorkingLanguage.Id)
};
model.Subscriptions.Add(subscriptionModel);
}
@@ -239,7 +239,7 @@ public class OutOfStockSubscriptionController : BasePublicController
foreach (var id in subscriptions)
{
var subscription = await _outOfStockSubscriptionService.GetSubscriptionById(id);
- if (subscription != null && subscription.CustomerId == _workContextAccessor.WorkContext.CurrentCustomer.Id)
+ if (subscription != null && subscription.CustomerId == _contextAccessor.WorkContext.CurrentCustomer.Id)
await _outOfStockSubscriptionService.DeleteSubscription(subscription);
}
diff --git a/src/Web/Grand.Web/Controllers/ProductController.cs b/src/Web/Grand.Web/Controllers/ProductController.cs
index 6b6732c38..30b5c3d56 100644
--- a/src/Web/Grand.Web/Controllers/ProductController.cs
+++ b/src/Web/Grand.Web/Controllers/ProductController.cs
@@ -36,7 +36,7 @@ public class ProductController : BasePublicController
public ProductController(
IProductService productService,
- IWorkContextAccessor workContextAccessor,
+ IContextAccessor contextAccessor,
ITranslationService translationService,
IRecentlyViewedProductsService recentlyViewedProductsService,
IShoppingCartService shoppingCartService,
@@ -48,7 +48,7 @@ public class ProductController : BasePublicController
)
{
_productService = productService;
- _workContextAccessor = workContextAccessor;
+ _contextAccessor = contextAccessor;
_translationService = translationService;
_recentlyViewedProductsService = recentlyViewedProductsService;
_shoppingCartService = shoppingCartService;
@@ -69,7 +69,7 @@ public class ProductController : BasePublicController
if (!_catalogSettings.RecentlyViewedProductsEnabled)
return Content("");
- var products = await _recentlyViewedProductsService.GetRecentlyViewedProducts(_workContextAccessor.WorkContext.CurrentCustomer.Id,
+ var products = await _recentlyViewedProductsService.GetRecentlyViewedProducts(_contextAccessor.WorkContext.CurrentCustomer.Id,
_catalogSettings.RecentlyViewedProductsNumber);
//prepare model
@@ -116,7 +116,7 @@ public class ProductController : BasePublicController
return Content("");
var products = (await _productService.SearchProducts(
- storeId: _workContextAccessor.WorkContext.CurrentStore.Id,
+ storeId: _contextAccessor.StoreContext.CurrentStore.Id,
visibleIndividuallyOnly: true,
markedAsNewOnly: true,
orderBy: ProductSortingEnum.CreatedOn,
@@ -148,16 +148,16 @@ public class ProductController : BasePublicController
if (ModelState.IsValid)
{
await _mediator.Send(new SendProductEmailAFriendMessageCommand {
- Customer = _workContextAccessor.WorkContext.CurrentCustomer,
+ Customer = _contextAccessor.WorkContext.CurrentCustomer,
Product = product,
- Language = _workContextAccessor.WorkContext.WorkingLanguage,
- Store = _workContextAccessor.WorkContext.CurrentStore,
+ Language = _contextAccessor.WorkContext.WorkingLanguage,
+ Store = _contextAccessor.StoreContext.CurrentStore,
Model = model
});
model.ProductId = product.Id;
- model.ProductName = product.GetTranslation(x => x.Name, _workContextAccessor.WorkContext.WorkingLanguage.Id);
- model.ProductSeName = product.GetSeName(_workContextAccessor.WorkContext.WorkingLanguage.Id);
+ model.ProductName = product.GetTranslation(x => x.Name, _contextAccessor.WorkContext.WorkingLanguage.Id);
+ model.ProductSeName = product.GetSeName(_contextAccessor.WorkContext.WorkingLanguage.Id);
model.SuccessfullySent = true;
model.Result = _translationService.GetResource("Products.EmailAFriend.SuccessfullySent");
@@ -167,8 +167,8 @@ public class ProductController : BasePublicController
//If we got this far, something failed, redisplay form
model.ProductId = product.Id;
- model.ProductName = product.GetTranslation(x => x.Name, _workContextAccessor.WorkContext.WorkingLanguage.Id);
- model.ProductSeName = product.GetSeName(_workContextAccessor.WorkContext.WorkingLanguage.Id);
+ model.ProductName = product.GetTranslation(x => x.Name, _contextAccessor.WorkContext.WorkingLanguage.Id);
+ model.ProductSeName = product.GetSeName(_contextAccessor.WorkContext.WorkingLanguage.Id);
model.DisplayCaptcha = _captchaSettings.Enabled && _captchaSettings.ShowOnEmailProductToFriendPage;
model.SuccessfullySent = false;
model.Result = string.Join(",", ModelState.Values.SelectMany(v => v.Errors).Select(x => x.ErrorMessage));
@@ -208,9 +208,9 @@ public class ProductController : BasePublicController
// email
await _mediator.Send(new SendProductAskQuestionMessageCommand {
- Customer = _workContextAccessor.WorkContext.CurrentCustomer,
- Language = _workContextAccessor.WorkContext.WorkingLanguage,
- Store = _workContextAccessor.WorkContext.CurrentStore,
+ Customer = _contextAccessor.WorkContext.CurrentCustomer,
+ Language = _contextAccessor.WorkContext.WorkingLanguage,
+ Store = _contextAccessor.StoreContext.CurrentStore,
Model = productaskqestionmodel,
Product = product,
RemoteIpAddress = HttpContext.Connection?.RemoteIpAddress?.ToString()
@@ -237,7 +237,7 @@ public class ProductController : BasePublicController
if (!string.IsNullOrEmpty(parameter)) query = query.Where(x => x.Parameter == parameter);
var reservations = query.ToList();
- var inCart = (await _shoppingCartService.GetShoppingCart(_workContextAccessor.WorkContext.CurrentStore.Id))
+ var inCart = (await _shoppingCartService.GetShoppingCart(_contextAccessor.StoreContext.CurrentStore.Id))
.Where(x => !string.IsNullOrEmpty(x.ReservationId)).ToList();
foreach (var cartItem in inCart)
{
@@ -255,7 +255,7 @@ public class ProductController : BasePublicController
#region Fields
private readonly IProductService _productService;
- private readonly IWorkContextAccessor _workContextAccessor;
+ private readonly IContextAccessor _contextAccessor;
private readonly ITranslationService _translationService;
private readonly IRecentlyViewedProductsService _recentlyViewedProductsService;
private readonly IShoppingCartService _shoppingCartService;
@@ -277,7 +277,7 @@ public class ProductController : BasePublicController
if (product == null)
return InvokeHttp404();
- var customer = _workContextAccessor.WorkContext.CurrentCustomer;
+ var customer = _contextAccessor.WorkContext.CurrentCustomer;
//published?
if (!_catalogSettings.AllowViewUnpublishedProductPage)
@@ -291,7 +291,7 @@ public class ProductController : BasePublicController
return InvokeHttp404();
//Store access
- if (!_aclService.Authorize(product, _workContextAccessor.WorkContext.CurrentStore.Id))
+ if (!_aclService.Authorize(product, _contextAccessor.StoreContext.CurrentStore.Id))
return InvokeHttp404();
//availability dates
@@ -306,12 +306,12 @@ public class ProductController : BasePublicController
return parentGroupedProduct == null
? RedirectToRoute("HomePage")
: RedirectToRoute("Product",
- new { SeName = parentGroupedProduct.GetSeName(_workContextAccessor.WorkContext.WorkingLanguage.Id) });
+ new { SeName = parentGroupedProduct.GetSeName(_contextAccessor.WorkContext.WorkingLanguage.Id) });
}
//prepare the model
var model = await _mediator.Send(new GetProductDetailsPage {
- Store = _workContextAccessor.WorkContext.CurrentStore,
+ Store = _contextAccessor.StoreContext.CurrentStore,
Product = product,
IsAssociatedProduct = false
});
@@ -327,7 +327,7 @@ public class ProductController : BasePublicController
if (await _permissionService.Authorize(StandardPermission.ManageAccessAdminPanel, customer) &&
await _permissionService.Authorize(StandardPermission.ManageProducts, customer))
//a vendor should have access only to his products
- if (_workContextAccessor.WorkContext.CurrentVendor == null || _workContextAccessor.WorkContext.CurrentVendor.Id == product.VendorId)
+ if (_contextAccessor.WorkContext.CurrentVendor == null || _contextAccessor.WorkContext.CurrentVendor.Id == product.VendorId)
DisplayEditLink(Url.Action("Edit", "Product", new { id = product.Id, area = "Admin" }));
_ = _productService.IncrementProductField(product, x => x.Viewed, 1);
@@ -345,9 +345,9 @@ public class ProductController : BasePublicController
return new JsonResult("");
var modelProduct = await _mediator.Send(new GetProductDetailsAttributeChange {
- Currency = _workContextAccessor.WorkContext.WorkingCurrency,
- Customer = _workContextAccessor.WorkContext.CurrentCustomer,
- Store = _workContextAccessor.WorkContext.CurrentStore,
+ Currency = _contextAccessor.WorkContext.WorkingCurrency,
+ Customer = _contextAccessor.WorkContext.CurrentCustomer,
+ Store = _contextAccessor.StoreContext.CurrentStore,
Model = model,
Product = product
});
@@ -446,7 +446,7 @@ public class ProductController : BasePublicController
var download = new Download {
DownloadGuid = Guid.NewGuid(),
- CustomerId = _workContextAccessor.WorkContext.CurrentCustomer.Id,
+ CustomerId = _contextAccessor.WorkContext.CurrentCustomer.Id,
UseDownloadUrl = false,
DownloadUrl = "",
DownloadBinary = fileBinary,
@@ -480,7 +480,7 @@ public class ProductController : BasePublicController
message = "No product found with the specified ID"
});
- var customer = _workContextAccessor.WorkContext.CurrentCustomer;
+ var customer = _contextAccessor.WorkContext.CurrentCustomer;
//published?
if (!_catalogSettings.AllowViewUnpublishedProductPage)
@@ -500,7 +500,7 @@ public class ProductController : BasePublicController
});
//Store access
- if (!_aclService.Authorize(product, _workContextAccessor.WorkContext.CurrentStore.Id))
+ if (!_aclService.Authorize(product, _contextAccessor.StoreContext.CurrentStore.Id))
return Json(new {
success = false,
message = "No product found with the specified ID"
@@ -523,13 +523,13 @@ public class ProductController : BasePublicController
redirect = Url.RouteUrl("HomePage")
});
return Json(new {
- redirect = Url.RouteUrl("Product", new { SeName = product.GetSeName(_workContextAccessor.WorkContext.WorkingLanguage.Id) })
+ redirect = Url.RouteUrl("Product", new { SeName = product.GetSeName(_contextAccessor.WorkContext.WorkingLanguage.Id) })
});
}
//prepare the model
var model = await _mediator.Send(new GetProductDetailsPage {
- Store = _workContextAccessor.WorkContext.CurrentStore,
+ Store = _contextAccessor.StoreContext.CurrentStore,
Product = product,
IsAssociatedProduct = false,
UpdateCartItem = null
@@ -571,8 +571,8 @@ public class ProductController : BasePublicController
if (ModelState.IsValid)
{
var productReview = await _mediator.Send(new InsertProductReviewCommand {
- Customer = _workContextAccessor.WorkContext.CurrentCustomer,
- Store = _workContextAccessor.WorkContext.CurrentStore,
+ Customer = _contextAccessor.WorkContext.CurrentCustomer,
+ Store = _contextAccessor.StoreContext.CurrentStore,
Model = model,
Product = product
});
@@ -585,10 +585,10 @@ public class ProductController : BasePublicController
await _mediator.Publish(new ProductReviewApprovedEvent(productReview));
model = await _mediator.Send(new GetProductReviews {
- Customer = _workContextAccessor.WorkContext.CurrentCustomer,
- Language = _workContextAccessor.WorkContext.WorkingLanguage,
+ Customer = _contextAccessor.WorkContext.CurrentCustomer,
+ Language = _contextAccessor.WorkContext.WorkingLanguage,
Product = product,
- Store = _workContextAccessor.WorkContext.CurrentStore,
+ Store = _contextAccessor.StoreContext.CurrentStore,
Size = _catalogSettings.NumberOfReview
});
@@ -605,8 +605,8 @@ public class ProductController : BasePublicController
model.AddProductReview.Result = _translationService.GetResource("Reviews.SuccessfullyAdded");
model.ProductReviewOverviewModel = await _mediator.Send(new GetProductReviewOverview {
Product = product,
- Language = _workContextAccessor.WorkContext.WorkingLanguage,
- Store = _workContextAccessor.WorkContext.CurrentStore
+ Language = _contextAccessor.WorkContext.WorkingLanguage,
+ Store = _contextAccessor.StoreContext.CurrentStore
});
}
@@ -615,10 +615,10 @@ public class ProductController : BasePublicController
//If we got this far, something failed, redisplay form
var newmodel = await _mediator.Send(new GetProductReviews {
- Customer = _workContextAccessor.WorkContext.CurrentCustomer,
- Language = _workContextAccessor.WorkContext.WorkingLanguage,
+ Customer = _contextAccessor.WorkContext.CurrentCustomer,
+ Language = _contextAccessor.WorkContext.WorkingLanguage,
Product = product,
- Store = _workContextAccessor.WorkContext.CurrentStore,
+ Store = _contextAccessor.StoreContext.CurrentStore,
Size = _catalogSettings.NumberOfReview
});
@@ -643,7 +643,7 @@ public class ProductController : BasePublicController
if (productReview == null)
throw new ArgumentException("No product review found with the specified id");
- if (await groupService.IsGuest(_workContextAccessor.WorkContext.CurrentCustomer) &&
+ if (await groupService.IsGuest(_contextAccessor.WorkContext.CurrentCustomer) &&
!_catalogSettings.AllowAnonymousUsersToReviewProduct)
return Json(new {
Result = _translationService.GetResource("Reviews.Helpfulness.OnlyRegistered"),
@@ -652,7 +652,7 @@ public class ProductController : BasePublicController
});
//customers aren't allowed to vote for their own reviews
- if (productReview.CustomerId == _workContextAccessor.WorkContext.CurrentCustomer.Id)
+ if (productReview.CustomerId == _contextAccessor.WorkContext.CurrentCustomer.Id)
return Json(new {
Result = _translationService.GetResource("Reviews.Helpfulness.YourOwnReview"),
TotalYes = productReview.HelpfulYesTotal,
@@ -661,7 +661,7 @@ public class ProductController : BasePublicController
//delete previous helpfulness
var prh = productReview.ProductReviewHelpfulnessEntries
- .FirstOrDefault(x => x.CustomerId == _workContextAccessor.WorkContext.CurrentCustomer.Id);
+ .FirstOrDefault(x => x.CustomerId == _contextAccessor.WorkContext.CurrentCustomer.Id);
if (prh != null)
{
//existing one
@@ -672,13 +672,13 @@ public class ProductController : BasePublicController
//insert new helpfulness
prh = new ProductReviewHelpfulness {
ProductReviewId = productReview.Id,
- CustomerId = _workContextAccessor.WorkContext.CurrentCustomer.Id,
+ CustomerId = _contextAccessor.WorkContext.CurrentCustomer.Id,
WasHelpful = washelpful
};
productReview.ProductReviewHelpfulnessEntries.Add(prh);
await productReviewService.UpdateProductReview(productReview);
- if (!_workContextAccessor.WorkContext.CurrentCustomer.HasContributions)
- await customerService.UpdateContributions(_workContextAccessor.WorkContext.CurrentCustomer);
+ if (!_contextAccessor.WorkContext.CurrentCustomer.HasContributions)
+ await customerService.UpdateContributions(_contextAccessor.WorkContext.CurrentCustomer);
}
//new totals
diff --git a/src/Web/Grand.Web/Controllers/PushNotificationsController.cs b/src/Web/Grand.Web/Controllers/PushNotificationsController.cs
index 08eee95c6..410edc66c 100644
--- a/src/Web/Grand.Web/Controllers/PushNotificationsController.cs
+++ b/src/Web/Grand.Web/Controllers/PushNotificationsController.cs
@@ -10,11 +10,11 @@ namespace Grand.Web.Controllers;
public class PushNotificationsController : BasePublicController
{
private readonly IPushNotificationsService _pushNotificationsService;
- private readonly IWorkContextAccessor _workContextAccessor;
+ private readonly IContextAccessor _contextAccessor;
- public PushNotificationsController(IWorkContextAccessor workContextAccessor, IPushNotificationsService pushNotificationsService)
+ public PushNotificationsController(IContextAccessor contextAccessor, IPushNotificationsService pushNotificationsService)
{
- _workContextAccessor = workContextAccessor;
+ _contextAccessor = contextAccessor;
_pushNotificationsService = pushNotificationsService;
}
@@ -24,12 +24,12 @@ public class PushNotificationsController : BasePublicController
{
if (success)
{
- var toUpdate = await _pushNotificationsService.GetPushReceiverByCustomerId(_workContextAccessor.WorkContext.CurrentCustomer.Id);
+ var toUpdate = await _pushNotificationsService.GetPushReceiverByCustomerId(_contextAccessor.WorkContext.CurrentCustomer.Id);
if (toUpdate == null)
{
await _pushNotificationsService.InsertPushReceiver(new PushRegistration {
- CustomerId = _workContextAccessor.WorkContext.CurrentCustomer.Id,
+ CustomerId = _contextAccessor.WorkContext.CurrentCustomer.Id,
Token = value,
RegisteredOn = DateTime.UtcNow,
Allowed = true
@@ -46,12 +46,12 @@ public class PushNotificationsController : BasePublicController
else
{
if (value != "Permission denied") return new JsonResult("");
- var toUpdate = await _pushNotificationsService.GetPushReceiverByCustomerId(_workContextAccessor.WorkContext.CurrentCustomer.Id);
+ var toUpdate = await _pushNotificationsService.GetPushReceiverByCustomerId(_contextAccessor.WorkContext.CurrentCustomer.Id);
if (toUpdate == null)
{
await _pushNotificationsService.InsertPushReceiver(new PushRegistration {
- CustomerId = _workContextAccessor.WorkContext.CurrentCustomer.Id,
+ CustomerId = _contextAccessor.WorkContext.CurrentCustomer.Id,
Token = "[DENIED]",
RegisteredOn = DateTime.UtcNow,
Allowed = false
diff --git a/src/Web/Grand.Web/Controllers/ShoppingCartController.cs b/src/Web/Grand.Web/Controllers/ShoppingCartController.cs
index 2a5dbc592..e0ac28a04 100644
--- a/src/Web/Grand.Web/Controllers/ShoppingCartController.cs
+++ b/src/Web/Grand.Web/Controllers/ShoppingCartController.cs
@@ -33,7 +33,7 @@ public class ShoppingCartController : BasePublicController
#region Constructors
public ShoppingCartController(
- IWorkContextAccessor workContextAccessor,
+ IContextAccessor contextAccessor,
IShoppingCartService shoppingCartService,
ITranslationService translationService,
IDiscountService discountService,
@@ -46,7 +46,7 @@ public class ShoppingCartController : BasePublicController
ShoppingCartSettings shoppingCartSettings,
OrderSettings orderSettings)
{
- _workContextAccessor = workContextAccessor;
+ _contextAccessor = contextAccessor;
_shoppingCartService = shoppingCartService;
_translationService = translationService;
_discountService = discountService;
@@ -80,7 +80,7 @@ public class ShoppingCartController : BasePublicController
#region Fields
- private readonly IWorkContextAccessor _workContextAccessor;
+ private readonly IContextAccessor _contextAccessor;
private readonly IShoppingCartService _shoppingCartService;
private readonly ITranslationService _translationService;
private readonly IDiscountService _discountService;
@@ -108,11 +108,11 @@ public class ShoppingCartController : BasePublicController
return Content("");
var model = await _mediator.Send(new GetMiniShoppingCart {
- Customer = _workContextAccessor.WorkContext.CurrentCustomer,
- Currency = _workContextAccessor.WorkContext.WorkingCurrency,
- Language = _workContextAccessor.WorkContext.WorkingLanguage,
- TaxDisplayType = _workContextAccessor.WorkContext.TaxDisplayType,
- Store = _workContextAccessor.WorkContext.CurrentStore
+ Customer = _contextAccessor.WorkContext.CurrentCustomer,
+ Currency = _contextAccessor.WorkContext.WorkingCurrency,
+ Language = _contextAccessor.WorkContext.WorkingLanguage,
+ TaxDisplayType = _contextAccessor.WorkContext.TaxDisplayType,
+ Store = _contextAccessor.StoreContext.CurrentStore
});
return Json(model);
}
@@ -123,12 +123,12 @@ public class ShoppingCartController : BasePublicController
[FromServices] ICheckoutAttributeParser checkoutAttributeParser,
[FromServices] ICheckoutAttributeFormatter checkoutAttributeFormatter)
{
- var cart = await _shoppingCartService.GetShoppingCart(_workContextAccessor.WorkContext.CurrentStore.Id,
+ var cart = await _shoppingCartService.GetShoppingCart(_contextAccessor.StoreContext.CurrentStore.Id,
ShoppingCartType.ShoppingCart, ShoppingCartType.Auctions);
var checkoutAttributes = await _mediator.Send(new SaveCheckoutAttributesCommand {
- Customer = _workContextAccessor.WorkContext.CurrentCustomer,
- Store = _workContextAccessor.WorkContext.CurrentStore,
+ Customer = _contextAccessor.WorkContext.CurrentCustomer,
+ Store = _contextAccessor.StoreContext.CurrentStore,
Cart = cart,
SelectedAttributes = model.Attributes
});
@@ -136,7 +136,7 @@ public class ShoppingCartController : BasePublicController
var enabledAttributeIds = new List<string>();
var disabledAttributeIds = new List<string>();
var attributes =
- await _checkoutAttributeService.GetAllCheckoutAttributes(_workContextAccessor.WorkContext.CurrentStore.Id,
+ await _checkoutAttributeService.GetAllCheckoutAttributes(_contextAccessor.StoreContext.CurrentStore.Id,
!cart.RequiresShipping());
foreach (var attribute in attributes)
{
@@ -152,11 +152,11 @@ public class ShoppingCartController : BasePublicController
var orderTotals = await _mediator.Send(new GetOrderTotals {
Cart = cart,
IsEditable = true,
- Store = _workContextAccessor.WorkContext.CurrentStore,
- Currency = _workContextAccessor.WorkContext.WorkingCurrency,
- Customer = _workContextAccessor.WorkContext.CurrentCustomer,
- Language = _workContextAccessor.WorkContext.WorkingLanguage,
- TaxDisplayType = _workContextAccessor.WorkContext.TaxDisplayType
+ Store = _contextAccessor.StoreContext.CurrentStore,
+ Currency = _contextAccessor.WorkContext.WorkingCurrency,
+ Customer = _contextAccessor.WorkContext.CurrentCustomer,
+ Language = _contextAccessor.WorkContext.WorkingLanguage,
+ TaxDisplayType = _contextAccessor.WorkContext.TaxDisplayType
});
return Json(new {
@@ -164,7 +164,7 @@ public class ShoppingCartController : BasePublicController
disabledattributeids = disabledAttributeIds.ToArray(),
model = orderTotals,
checkoutattributeinfo =
- await checkoutAttributeFormatter.FormatAttributes(checkoutAttributes, _workContextAccessor.WorkContext.CurrentCustomer)
+ await checkoutAttributeFormatter.FormatAttributes(checkoutAttributes, _contextAccessor.WorkContext.CurrentCustomer)
});
}
@@ -230,7 +230,7 @@ public class ShoppingCartController : BasePublicController
var download = new Download {
DownloadGuid = Guid.NewGuid(),
- CustomerId = _workContextAccessor.WorkContext.CurrentCustomer.Id,
+ CustomerId = _contextAccessor.WorkContext.CurrentCustomer.Id,
UseDownloadUrl = false,
DownloadUrl = "",
DownloadBinary = fileBinary,
@@ -259,15 +259,15 @@ public class ShoppingCartController : BasePublicController
if (!await _permissionService.Authorize(StandardPermission.EnableShoppingCart))
return RedirectToRoute("HomePage");
- var cart = await _shoppingCartService.GetShoppingCart(_workContextAccessor.WorkContext.CurrentStore.Id, PrepareCartTypes());
+ var cart = await _shoppingCartService.GetShoppingCart(_contextAccessor.StoreContext.CurrentStore.Id, PrepareCartTypes());
var model = await _mediator.Send(new GetShoppingCart {
Cart = cart,
ValidateCheckoutAttributes = checkoutAttributes,
- Customer = _workContextAccessor.WorkContext.CurrentCustomer,
- Currency = _workContextAccessor.WorkContext.WorkingCurrency,
- Language = _workContextAccessor.WorkContext.WorkingLanguage,
- TaxDisplayType = _workContextAccessor.WorkContext.TaxDisplayType,
- Store = _workContextAccessor.WorkContext.CurrentStore
+ Customer = _contextAccessor.WorkContext.CurrentCustomer,
+ Currency = _contextAccessor.WorkContext.WorkingCurrency,
+ Language = _contextAccessor.WorkContext.WorkingLanguage,
+ TaxDisplayType = _contextAccessor.WorkContext.TaxDisplayType,
+ Store = _contextAccessor.StoreContext.CurrentStore
});
return View(model);
}
@@ -277,17 +277,17 @@ public class ShoppingCartController : BasePublicController
[ProducesResponseType(typeof(ShoppingCartModel), StatusCodes.Status200OK)]
public async Task<IActionResult> CartSummary()
{
- var cart = await _shoppingCartService.GetShoppingCart(_workContextAccessor.WorkContext.CurrentStore.Id,
+ var cart = await _shoppingCartService.GetShoppingCart(_contextAccessor.StoreContext.CurrentStore.Id,
ShoppingCartType.ShoppingCart, ShoppingCartType.Auctions);
var model = await _mediator.Send(new GetShoppingCart {
Cart = cart,
IsEditable = false,
- Customer = _workContextAccessor.WorkContext.CurrentCustomer,
- Currency = _workContextAccessor.WorkContext.WorkingCurrency,
- Language = _workContextAccessor.WorkContext.WorkingLanguage,
- Store = _workContextAccessor.WorkContext.CurrentStore,
- TaxDisplayType = _workContextAccessor.WorkContext.TaxDisplayType
+ Customer = _contextAccessor.WorkContext.CurrentCustomer,
+ Currency = _contextAccessor.WorkContext.WorkingCurrency,
+ Language = _contextAccessor.WorkContext.WorkingLanguage,
+ Store = _contextAccessor.StoreContext.CurrentStore,
+ TaxDisplayType = _contextAccessor.WorkContext.TaxDisplayType
});
return Json(model);
@@ -298,16 +298,16 @@ public class ShoppingCartController : BasePublicController
[ProducesResponseType(typeof(OrderTotalsModel), StatusCodes.Status200OK)]
public async Task<IActionResult> CartTotal()
{
- var cart = await _shoppingCartService.GetShoppingCart(_workContextAccessor.WorkContext.CurrentStore.Id,
+ var cart = await _shoppingCartService.GetShoppingCart(_contextAccessor.StoreContext.CurrentStore.Id,
ShoppingCartType.ShoppingCart, ShoppingCartType.Auctions);
var model = await _mediator.Send(new GetOrderTotals {
Cart = cart,
- Store = _workContextAccessor.WorkContext.CurrentStore,
- Currency = _workContextAccessor.WorkContext.WorkingCurrency,
- Customer = _workContextAccessor.WorkContext.CurrentCustomer,
- Language = _workContextAccessor.WorkContext.WorkingLanguage,
- TaxDisplayType = _workContextAccessor.WorkContext.TaxDisplayType
+ Store = _contextAccessor.StoreContext.CurrentStore,
+ Currency = _contextAccessor.WorkContext.WorkingCurrency,
+ Customer = _contextAccessor.WorkContext.CurrentCustomer,
+ Language = _contextAccessor.WorkContext.WorkingLanguage,
+ TaxDisplayType = _contextAccessor.WorkContext.TaxDisplayType
});
return Json(model);
}
@@ -324,13 +324,13 @@ public class ShoppingCartController : BasePublicController
warnings = string.Join(',', ModelState.Values.SelectMany(x => x.Errors.Select(x => x.ErrorMessage)))
});
- var cart = (await _shoppingCartService.GetShoppingCart(_workContextAccessor.WorkContext.CurrentStore.Id, PrepareCartTypes()))
+ var cart = (await _shoppingCartService.GetShoppingCart(_contextAccessor.StoreContext.CurrentStore.Id, PrepareCartTypes()))
.FirstOrDefault(x => x.Id == model.ShoppingCartId);
var warnings = new List<string>();
if (cart != null)
{
- var currSciWarnings = await _shoppingCartService.UpdateShoppingCartItem(_workContextAccessor.WorkContext.CurrentCustomer,
+ var currSciWarnings = await _shoppingCartService.UpdateShoppingCartItem(_contextAccessor.WorkContext.CurrentCustomer,
cart.Id, cart.WarehouseId, cart.Attributes, cart.EnteredPrice,
cart.RentalStartDateUtc, cart.RentalEndDateUtc,
model.Quantity);
@@ -338,12 +338,12 @@ public class ShoppingCartController : BasePublicController
}
var cartModel = await _mediator.Send(new GetShoppingCart {
- Cart = await _shoppingCartService.GetShoppingCart(_workContextAccessor.WorkContext.CurrentStore.Id, PrepareCartTypes()),
- Customer = _workContextAccessor.WorkContext.CurrentCustomer,
- Currency = _workContextAccessor.WorkContext.WorkingCurrency,
- Language = _workContextAccessor.WorkContext.WorkingLanguage,
- Store = _workContextAccessor.WorkContext.CurrentStore,
- TaxDisplayType = _workContextAccessor.WorkContext.TaxDisplayType
+ Cart = await _shoppingCartService.GetShoppingCart(_contextAccessor.StoreContext.CurrentStore.Id, PrepareCartTypes()),
+ Customer = _contextAccessor.WorkContext.CurrentCustomer,
+ Currency = _contextAccessor.WorkContext.WorkingCurrency,
+ Language = _contextAccessor.WorkContext.WorkingLanguage,
+ Store = _contextAccessor.StoreContext.CurrentStore,
+ TaxDisplayType = _contextAccessor.WorkContext.TaxDisplayType
});
return Json(new {
@@ -362,10 +362,10 @@ public class ShoppingCartController : BasePublicController
if (!await _permissionService.Authorize(StandardPermission.EnableShoppingCart))
return RedirectToRoute("HomePage");
- var cart = await _shoppingCartService.GetShoppingCart(_workContextAccessor.WorkContext.CurrentStore.Id, PrepareCartTypes());
+ var cart = await _shoppingCartService.GetShoppingCart(_contextAccessor.StoreContext.CurrentStore.Id, PrepareCartTypes());
foreach (var sci in cart)
- await _shoppingCartService.DeleteShoppingCartItem(_workContextAccessor.WorkContext.CurrentCustomer, sci,
+ await _shoppingCartService.DeleteShoppingCartItem(_contextAccessor.WorkContext.CurrentCustomer, sci,
ensureOnlyActiveCheckoutAttributes: true);
return RedirectToRoute("HomePage");
@@ -382,20 +382,20 @@ public class ShoppingCartController : BasePublicController
if (_shoppingCartSettings.AllowOnHoldCart)
shoppingCartTypes.Add(ShoppingCartType.OnHoldCart);
- var item = (await _shoppingCartService.GetShoppingCart(_workContextAccessor.WorkContext.CurrentStore.Id,
+ var item = (await _shoppingCartService.GetShoppingCart(_contextAccessor.StoreContext.CurrentStore.Id,
shoppingCartTypes.ToArray()))
.FirstOrDefault(sci => sci.Id == model.Id);
if (item != null)
- await _shoppingCartService.DeleteShoppingCartItem(_workContextAccessor.WorkContext.CurrentCustomer, item,
+ await _shoppingCartService.DeleteShoppingCartItem(_contextAccessor.WorkContext.CurrentCustomer, item,
ensureOnlyActiveCheckoutAttributes: true);
var miniShoppingCartmodel = await _mediator.Send(new GetMiniShoppingCart {
- Customer = _workContextAccessor.WorkContext.CurrentCustomer,
- Currency = _workContextAccessor.WorkContext.WorkingCurrency,
- Language = _workContextAccessor.WorkContext.WorkingLanguage,
- TaxDisplayType = _workContextAccessor.WorkContext.TaxDisplayType,
- Store = _workContextAccessor.WorkContext.CurrentStore
+ Customer = _contextAccessor.WorkContext.CurrentCustomer,
+ Currency = _contextAccessor.WorkContext.WorkingCurrency,
+ Language = _contextAccessor.WorkContext.WorkingLanguage,
+ TaxDisplayType = _contextAccessor.WorkContext.TaxDisplayType,
+ Store = _contextAccessor.StoreContext.CurrentStore
});
if (!model.ShoppingCartPage)
return Json(new {
@@ -404,14 +404,14 @@ public class ShoppingCartController : BasePublicController
sidebarshoppingcartmodel = miniShoppingCartmodel
});
- var cart = await _shoppingCartService.GetShoppingCart(_workContextAccessor.WorkContext.CurrentStore.Id, PrepareCartTypes());
+ var cart = await _shoppingCartService.GetShoppingCart(_contextAccessor.StoreContext.CurrentStore.Id, PrepareCartTypes());
var shoppingcartmodel = await _mediator.Send(new GetShoppingCart {
Cart = cart,
- Customer = _workContextAccessor.WorkContext.CurrentCustomer,
- Currency = _workContextAccessor.WorkContext.WorkingCurrency,
- Language = _workContextAccessor.WorkContext.WorkingLanguage,
- Store = _workContextAccessor.WorkContext.CurrentStore,
- TaxDisplayType = _workContextAccessor.WorkContext.TaxDisplayType
+ Customer = _contextAccessor.WorkContext.CurrentCustomer,
+ Currency = _contextAccessor.WorkContext.WorkingCurrency,
+ Language = _contextAccessor.WorkContext.WorkingLanguage,
+ Store = _contextAccessor.StoreContext.CurrentStore,
+ TaxDisplayType = _contextAccessor.WorkContext.TaxDisplayType
});
return Json(new {
@@ -436,32 +436,32 @@ public class ShoppingCartController : BasePublicController
if (_shoppingCartSettings.AllowOnHoldCart)
shoppingCartTypes.Add(ShoppingCartType.OnHoldCart);
- var item = (await _shoppingCartService.GetShoppingCart(_workContextAccessor.WorkContext.CurrentStore.Id,
+ var item = (await _shoppingCartService.GetShoppingCart(_contextAccessor.StoreContext.CurrentStore.Id,
shoppingCartTypes.ToArray()))
.FirstOrDefault(sci => sci.Id == model.Id);
if (item != null)
{
item.ShoppingCartTypeId = model.Status ? ShoppingCartType.ShoppingCart : ShoppingCartType.OnHoldCart;
- await _customerService.UpdateShoppingCartItem(_workContextAccessor.WorkContext.CurrentCustomer.Id, item);
+ await _customerService.UpdateShoppingCartItem(_contextAccessor.WorkContext.CurrentCustomer.Id, item);
}
var miniShoppingCart = await _mediator.Send(new GetMiniShoppingCart {
- Customer = _workContextAccessor.WorkContext.CurrentCustomer,
- Currency = _workContextAccessor.WorkContext.WorkingCurrency,
- Language = _workContextAccessor.WorkContext.WorkingLanguage,
- TaxDisplayType = _workContextAccessor.WorkContext.TaxDisplayType,
- Store = _workContextAccessor.WorkContext.CurrentStore
+ Customer = _contextAccessor.WorkContext.CurrentCustomer,
+ Currency = _contextAccessor.WorkContext.WorkingCurrency,
+ Language = _contextAccessor.WorkContext.WorkingLanguage,
+ TaxDisplayType = _contextAccessor.WorkContext.TaxDisplayType,
+ Store = _contextAccessor.StoreContext.CurrentStore
});
- var cart = await _shoppingCartService.GetShoppingCart(_workContextAccessor.WorkContext.CurrentStore.Id, PrepareCartTypes());
+ var cart = await _shoppingCartService.GetShoppingCart(_contextAccessor.StoreContext.CurrentStore.Id, PrepareCartTypes());
var shoppingcartmodel = await _mediator.Send(new GetShoppingCart {
Cart = cart,
- Customer = _workContextAccessor.WorkContext.CurrentCustomer,
- Currency = _workContextAccessor.WorkContext.WorkingCurrency,
- Language = _workContextAccessor.WorkContext.WorkingLanguage,
- Store = _workContextAccessor.WorkContext.CurrentStore,
- TaxDisplayType = _workContextAccessor.WorkContext.TaxDisplayType
+ Customer = _contextAccessor.WorkContext.CurrentCustomer,
+ Currency = _contextAccessor.WorkContext.WorkingCurrency,
+ Language = _contextAccessor.WorkContext.WorkingLanguage,
+ Store = _contextAccessor.StoreContext.CurrentStore,
+ TaxDisplayType = _contextAccessor.WorkContext.TaxDisplayType
});
return Json(new {
@@ -481,28 +481,28 @@ public class ShoppingCartController : BasePublicController
[DenySystemAccount]
public virtual async Task<IActionResult> StartCheckout(CheckoutAttributeSelectedModel model)
{
- var cart = await _shoppingCartService.GetShoppingCart(_workContextAccessor.WorkContext.CurrentStore.Id,
+ var cart = await _shoppingCartService.GetShoppingCart(_contextAccessor.StoreContext.CurrentStore.Id,
ShoppingCartType.ShoppingCart, ShoppingCartType.Auctions);
List<CustomAttribute> checkoutAttributes;
//parse and save checkout attributes
if (model?.Attributes is { Count: > 0 })
checkoutAttributes = (await _mediator.Send(new SaveCheckoutAttributesCommand {
- Customer = _workContextAccessor.WorkContext.CurrentCustomer,
- Store = _workContextAccessor.WorkContext.CurrentStore,
+ Customer = _contextAccessor.WorkContext.CurrentCustomer,
+ Store = _contextAccessor.StoreContext.CurrentStore,
Cart = cart,
SelectedAttributes = model.Attributes
})).ToList();
else
checkoutAttributes =
- _workContextAccessor.WorkContext.CurrentCustomer.GetUserFieldFromEntity<List<CustomAttribute>>(
- SystemCustomerFieldNames.CheckoutAttributes, _workContextAccessor.WorkContext.CurrentStore.Id);
+ _contextAccessor.WorkContext.CurrentCustomer.GetUserFieldFromEntity<List<CustomAttribute>>(
+ SystemCustomerFieldNames.CheckoutAttributes, _contextAccessor.StoreContext.CurrentStore.Id);
var checkoutAttributeWarnings =
await _shoppingCartValidator.GetShoppingCartWarnings(cart, checkoutAttributes, true, true);
if (checkoutAttributeWarnings.Any()) return RedirectToRoute("ShoppingCart", new { checkoutAttributes = true });
//everything is OK
- if (!await _groupService.IsGuest(_workContextAccessor.WorkContext.CurrentCustomer)) return RedirectToRoute("Checkout");
+ if (!await _groupService.IsGuest(_contextAccessor.WorkContext.CurrentCustomer)) return RedirectToRoute("Checkout");
if (!_orderSettings.AnonymousCheckoutAllowed)
return Challenge();
@@ -514,7 +514,7 @@ public class ShoppingCartController : BasePublicController
[HttpPost]
public virtual async Task<IActionResult> ApplyDiscountCoupon(DiscountCouponModel model)
{
- var cart = await _shoppingCartService.GetShoppingCart(_workContextAccessor.WorkContext.CurrentStore.Id, PrepareCartTypes());
+ var cart = await _shoppingCartService.GetShoppingCart(_contextAccessor.StoreContext.CurrentStore.Id, PrepareCartTypes());
var message = string.Empty;
var isApplied = false;
@@ -523,10 +523,10 @@ public class ShoppingCartController : BasePublicController
{
//valid
var applyCouponCode =
- _workContextAccessor.WorkContext.CurrentCustomer.ApplyCouponCode(SystemCustomerFieldNames.DiscountCoupons,
+ _contextAccessor.WorkContext.CurrentCustomer.ApplyCouponCode(SystemCustomerFieldNames.DiscountCoupons,
model.DiscountCouponCode);
//apply new value
- await _customerService.UpdateUserField(_workContextAccessor.WorkContext.CurrentCustomer,
+ await _customerService.UpdateUserField(_contextAccessor.WorkContext.CurrentCustomer,
SystemCustomerFieldNames.DiscountCoupons, applyCouponCode);
message = _translationService.GetResource("ShoppingCart.DiscountCouponCode.Applied");
isApplied = true;
@@ -538,11 +538,11 @@ public class ShoppingCartController : BasePublicController
var cartModel = await _mediator.Send(new GetShoppingCart {
Cart = cart,
- Customer = _workContextAccessor.WorkContext.CurrentCustomer,
- Currency = _workContextAccessor.WorkContext.WorkingCurrency,
- Language = _workContextAccessor.WorkContext.WorkingLanguage,
- Store = _workContextAccessor.WorkContext.CurrentStore,
- TaxDisplayType = _workContextAccessor.WorkContext.TaxDisplayType
+ Customer = _contextAccessor.WorkContext.CurrentCustomer,
+ Currency = _contextAccessor.WorkContext.WorkingCurrency,
+ Language = _contextAccessor.WorkContext.WorkingLanguage,
+ Store = _contextAccessor.StoreContext.CurrentStore,
+ TaxDisplayType = _contextAccessor.WorkContext.TaxDisplayType
});
cartModel.DiscountBox.Message = message;
@@ -558,7 +558,7 @@ public class ShoppingCartController : BasePublicController
[HttpPost]
public virtual async Task<IActionResult> ApplyGiftVoucher(GiftVoucherCouponModel model)
{
- var cart = await _shoppingCartService.GetShoppingCart(_workContextAccessor.WorkContext.CurrentStore.Id, PrepareCartTypes());
+ var cart = await _shoppingCartService.GetShoppingCart(_contextAccessor.StoreContext.CurrentStore.Id, PrepareCartTypes());
var message = string.Empty;
var isApplied = false;
@@ -567,10 +567,10 @@ public class ShoppingCartController : BasePublicController
{
model.GiftVoucherCouponCode = model.GiftVoucherCouponCode.Trim();
- var result = _workContextAccessor.WorkContext.CurrentCustomer.ApplyCouponCode(SystemCustomerFieldNames.GiftVoucherCoupons,
+ var result = _contextAccessor.WorkContext.CurrentCustomer.ApplyCouponCode(SystemCustomerFieldNames.GiftVoucherCoupons,
model.GiftVoucherCouponCode.ToLower());
//apply new value
- await _customerService.UpdateUserField(_workContextAccessor.WorkContext.CurrentCustomer,
+ await _customerService.UpdateUserField(_contextAccessor.WorkContext.CurrentCustomer,
SystemCustomerFieldNames.GiftVoucherCoupons, result);
message = _translationService.GetResource("ShoppingCart.Code.Applied");
@@ -583,11 +583,11 @@ public class ShoppingCartController : BasePublicController
var cartModel = await _mediator.Send(new GetShoppingCart {
Cart = cart,
- Customer = _workContextAccessor.WorkContext.CurrentCustomer,
- Currency = _workContextAccessor.WorkContext.WorkingCurrency,
- Language = _workContextAccessor.WorkContext.WorkingLanguage,
- Store = _workContextAccessor.WorkContext.CurrentStore,
- TaxDisplayType = _workContextAccessor.WorkContext.TaxDisplayType
+ Customer = _contextAccessor.WorkContext.CurrentCustomer,
+ Currency = _contextAccessor.WorkContext.WorkingCurrency,
+ Language = _contextAccessor.WorkContext.WorkingLanguage,
+ Store = _contextAccessor.StoreContext.CurrentStore,
+ TaxDisplayType = _contextAccessor.WorkContext.TaxDisplayType
});
cartModel.GiftVoucherBox.Message = message;
@@ -602,14 +602,14 @@ public class ShoppingCartController : BasePublicController
[HttpPost]
public virtual async Task<IActionResult> GetEstimateShipping(EstimateShippingModel model)
{
- var cart = await _shoppingCartService.GetShoppingCart(_workContextAccessor.WorkContext.CurrentStore.Id,
+ var cart = await _shoppingCartService.GetShoppingCart(_contextAccessor.StoreContext.CurrentStore.Id,
ShoppingCartType.ShoppingCart, ShoppingCartType.Auctions);
var result = await _mediator.Send(new GetEstimateShippingResult {
Cart = cart,
- Currency = _workContextAccessor.WorkContext.WorkingCurrency,
- Customer = _workContextAccessor.WorkContext.CurrentCustomer,
- Store = _workContextAccessor.WorkContext.CurrentStore,
+ Currency = _contextAccessor.WorkContext.WorkingCurrency,
+ Customer = _contextAccessor.WorkContext.CurrentCustomer,
+ Store = _contextAccessor.StoreContext.CurrentStore,
CountryId = model.CountryId,
StateProvinceId = model.StateProvinceId,
ZipPostalCode = model.ZipPostalCode
@@ -626,7 +626,7 @@ public class ShoppingCartController : BasePublicController
if (discount != null)
{
var coupons =
- _workContextAccessor.WorkContext.CurrentCustomer.ParseAppliedCouponCodes(SystemCustomerFieldNames.DiscountCoupons);
+ _contextAccessor.WorkContext.CurrentCustomer.ParseAppliedCouponCodes(SystemCustomerFieldNames.DiscountCoupons);
foreach (var item in coupons)
{
var dd = await _discountService.GetDiscountByCouponCode(item);
@@ -634,21 +634,21 @@ public class ShoppingCartController : BasePublicController
//remove coupon
var result =
- _workContextAccessor.WorkContext.CurrentCustomer.RemoveCouponCode(SystemCustomerFieldNames.DiscountCoupons, item);
- await _customerService.UpdateUserField(_workContextAccessor.WorkContext.CurrentCustomer,
+ _contextAccessor.WorkContext.CurrentCustomer.RemoveCouponCode(SystemCustomerFieldNames.DiscountCoupons, item);
+ await _customerService.UpdateUserField(_contextAccessor.WorkContext.CurrentCustomer,
SystemCustomerFieldNames.DiscountCoupons, result);
}
}
- var cart = await _shoppingCartService.GetShoppingCart(_workContextAccessor.WorkContext.CurrentStore.Id, PrepareCartTypes());
+ var cart = await _shoppingCartService.GetShoppingCart(_contextAccessor.StoreContext.CurrentStore.Id, PrepareCartTypes());
var model = await _mediator.Send(new GetShoppingCart {
Cart = cart,
- Customer = _workContextAccessor.WorkContext.CurrentCustomer,
- Currency = _workContextAccessor.WorkContext.WorkingCurrency,
- Language = _workContextAccessor.WorkContext.WorkingLanguage,
- Store = _workContextAccessor.WorkContext.CurrentStore,
- TaxDisplayType = _workContextAccessor.WorkContext.TaxDisplayType
+ Customer = _contextAccessor.WorkContext.CurrentCustomer,
+ Currency = _contextAccessor.WorkContext.WorkingCurrency,
+ Language = _contextAccessor.WorkContext.WorkingLanguage,
+ Store = _contextAccessor.StoreContext.CurrentStore,
+ TaxDisplayType = _contextAccessor.WorkContext.TaxDisplayType
});
return Json(new {
@@ -668,22 +668,22 @@ public class ShoppingCartController : BasePublicController
if (giftvoucher != null)
{
var result =
- _workContextAccessor.WorkContext.CurrentCustomer.RemoveCouponCode(SystemCustomerFieldNames.GiftVoucherCoupons,
+ _contextAccessor.WorkContext.CurrentCustomer.RemoveCouponCode(SystemCustomerFieldNames.GiftVoucherCoupons,
giftvoucher.Code);
- await _customerService.UpdateUserField(_workContextAccessor.WorkContext.CurrentCustomer,
+ await _customerService.UpdateUserField(_contextAccessor.WorkContext.CurrentCustomer,
SystemCustomerFieldNames.GiftVoucherCoupons, result);
}
}
- var cart = await _shoppingCartService.GetShoppingCart(_workContextAccessor.WorkContext.CurrentStore.Id, PrepareCartTypes());
+ var cart = await _shoppingCartService.GetShoppingCart(_contextAccessor.StoreContext.CurrentStore.Id, PrepareCartTypes());
var model = await _mediator.Send(new GetShoppingCart {
Cart = cart,
- Customer = _workContextAccessor.WorkContext.CurrentCustomer,
- Currency = _workContextAccessor.WorkContext.WorkingCurrency,
- Language = _workContextAccessor.WorkContext.WorkingLanguage,
- Store = _workContextAccessor.WorkContext.CurrentStore,
- TaxDisplayType = _workContextAccessor.WorkContext.TaxDisplayType
+ Customer = _contextAccessor.WorkContext.CurrentCustomer,
+ Currency = _contextAccessor.WorkContext.WorkingCurrency,
+ Language = _contextAccessor.WorkContext.WorkingLanguage,
+ Store = _contextAccessor.StoreContext.CurrentStore,
+ TaxDisplayType = _contextAccessor.WorkContext.TaxDisplayType
});
return Json(new {
diff --git a/src/Web/Grand.Web/Controllers/VendorController.cs b/src/Web/Grand.Web/Controllers/VendorController.cs
index 955cfeff7..4b7efcdaf 100644
--- a/src/Web/Grand.Web/Controllers/VendorController.cs
+++ b/src/Web/Grand.Web/Controllers/VendorController.cs
@@ -30,7 +30,7 @@ public class VendorController : BasePublicController
#region Constructors
public VendorController(
- IWorkContextAccessor workContextAccessor,
+ IContextAccessor contextAccessor,
ITranslationService translationService,
ICustomerService customerService,
IMessageProviderService messageProviderService,
@@ -44,7 +44,7 @@ public class VendorController : BasePublicController
CaptchaSettings captchaSettings,
CommonSettings commonSettings)
{
- _workContextAccessor = workContextAccessor;
+ _contextAccessor = contextAccessor;
_translationService = translationService;
_customerService = customerService;
_messageProviderService = messageProviderService;
@@ -74,7 +74,7 @@ public class VendorController : BasePublicController
#region Fields
- private readonly IWorkContextAccessor _workContextAccessor;
+ private readonly IContextAccessor _contextAccessor;
private readonly ITranslationService _translationService;
private readonly ICustomerService _customerService;
private readonly IMessageProviderService _messageProviderService;
@@ -100,7 +100,7 @@ public class VendorController : BasePublicController
return RedirectToRoute("HomePage");
var model = new ApplyVendorModel();
- if (!string.IsNullOrEmpty(_workContextAccessor.WorkContext.CurrentCustomer.VendorId))
+ if (!string.IsNullOrEmpty(_contextAccessor.WorkContext.CurrentCustomer.VendorId))
{
//already applied for vendor account
model.DisableFormInput = true;
@@ -109,17 +109,17 @@ public class VendorController : BasePublicController
}
model.DisplayCaptcha = _captchaSettings.Enabled && _captchaSettings.ShowOnApplyVendorPage;
- model.Email = _workContextAccessor.WorkContext.CurrentCustomer.Email;
+ model.Email = _contextAccessor.WorkContext.CurrentCustomer.Email;
model.TermsOfServiceEnabled = _vendorSettings.TermsOfServiceEnabled;
model.TermsOfServicePopup = _commonSettings.PopupForTermsOfServiceLinks;
var countries =
- await _countryService.GetAllCountries(_workContextAccessor.WorkContext.WorkingLanguage.Id, _workContextAccessor.WorkContext.CurrentStore.Id);
+ await _countryService.GetAllCountries(_contextAccessor.WorkContext.WorkingLanguage.Id, _contextAccessor.StoreContext.CurrentStore.Id);
model.Address = await _mediator.Send(new GetVendorAddress {
- Language = _workContextAccessor.WorkContext.WorkingLanguage,
+ Language = _contextAccessor.WorkContext.WorkingLanguage,
Address = null,
ExcludeProperties = false,
PrePopulateWithCustomerFields = true,
- Customer = _workContextAccessor.WorkContext.CurrentCustomer,
+ Customer = _contextAccessor.WorkContext.CurrentCustomer,
LoadCountries = () => countries
});
@@ -163,13 +163,13 @@ public class VendorController : BasePublicController
//associate to the current customer
//but a store owner will have to manually activate this vendor
//if he wants to grant access to admin area
- _workContextAccessor.WorkContext.CurrentCustomer.VendorId = vendor.Id;
- await _customerService.UpdateCustomerField(_workContextAccessor.WorkContext.CurrentCustomer.Id, x => x.VendorId,
- _workContextAccessor.WorkContext.CurrentCustomer.VendorId);
+ _contextAccessor.WorkContext.CurrentCustomer.VendorId = vendor.Id;
+ await _customerService.UpdateCustomerField(_contextAccessor.WorkContext.CurrentCustomer.Id, x => x.VendorId,
+ _contextAccessor.WorkContext.CurrentCustomer.VendorId);
//notify store owner here (email)
- await _messageProviderService.SendNewVendorAccountApplyStoreOwnerMessage(_workContextAccessor.WorkContext.CurrentCustomer,
- vendor, _workContextAccessor.WorkContext.CurrentStore, _languageSettings.DefaultAdminLanguageId);
+ await _messageProviderService.SendNewVendorAccountApplyStoreOwnerMessage(_contextAccessor.WorkContext.CurrentCustomer,
+ vendor, _contextAccessor.StoreContext.CurrentStore, _languageSettings.DefaultAdminLanguageId);
model.DisableFormInput = true;
model.Result = _translationService.GetResource("Vendors.ApplyAccount.Submitted");
@@ -181,14 +181,14 @@ public class VendorController : BasePublicController
model.TermsOfServiceEnabled = _vendorSettings.TermsOfServiceEnabled;
model.TermsOfServicePopup = _commonSettings.PopupForTermsOfServiceLinks;
var countries =
- await _countryService.GetAllCountries(_workContextAccessor.WorkContext.WorkingLanguage.Id, _workContextAccessor.WorkContext.CurrentStore.Id);
+ await _countryService.GetAllCountries(_contextAccessor.WorkContext.WorkingLanguage.Id, _contextAccessor.StoreContext.CurrentStore.Id);
model.Address = await _mediator.Send(new GetVendorAddress {
- Language = _workContextAccessor.WorkContext.WorkingLanguage,
+ Language = _contextAccessor.WorkContext.WorkingLanguage,
Address = null,
Model = model.Address,
ExcludeProperties = false,
PrePopulateWithCustomerFields = true,
- Customer = _workContextAccessor.WorkContext.CurrentCustomer,
+ Customer = _contextAccessor.WorkContext.CurrentCustomer,
LoadCountries = () => countries
});
return View(model);
@@ -211,7 +211,7 @@ public class VendorController : BasePublicController
model = await _mediator.Send(new ContactVendorSendCommand {
Model = model,
Vendor = vendor,
- Store = _workContextAccessor.WorkContext.CurrentStore,
+ Store = _contextAccessor.StoreContext.CurrentStore,
IpAddress = HttpContext.Connection.RemoteIpAddress?.ToString()
});
return Json(model);
diff --git a/src/Web/Grand.Web/Controllers/WishlistController.cs b/src/Web/Grand.Web/Controllers/WishlistController.cs
index 7aef63aef..3a9fa2741 100644
--- a/src/Web/Grand.Web/Controllers/WishlistController.cs
+++ b/src/Web/Grand.Web/Controllers/WishlistController.cs
@@ -26,7 +26,7 @@ public class WishlistController : BasePublicController
#region Constructors
public WishlistController(
- IWorkContextAccessor workContextAccessor,
+ IContextAccessor contextAccessor,
IShoppingCartService shoppingCartService,
ITranslationService translationService,
ICustomerService customerService,
@@ -34,7 +34,7 @@ public class WishlistController : BasePublicController
IMediator mediator,
ShoppingCartSettings shoppingCartSettings)
{
- _workContextAccessor = workContextAccessor;
+ _contextAccessor = contextAccessor;
_shoppingCartService = shoppingCartService;
_translationService = translationService;
_customerService = customerService;
@@ -47,7 +47,7 @@ public class WishlistController : BasePublicController
#region Fields
- private readonly IWorkContextAccessor _workContextAccessor;
+ private readonly IContextAccessor _contextAccessor;
private readonly IShoppingCartService _shoppingCartService;
private readonly ITranslationService _translationService;
private readonly ICustomerService _customerService;
@@ -66,18 +66,18 @@ public class WishlistController : BasePublicController
if (!await _permissionService.Authorize(StandardPermission.EnableWishlist))
return Content("");
- var cart = _workContextAccessor.WorkContext.CurrentCustomer.ShoppingCartItems.Where(sci =>
+ var cart = _contextAccessor.WorkContext.CurrentCustomer.ShoppingCartItems.Where(sci =>
sci.ShoppingCartTypeId == ShoppingCartType.Wishlist);
- if (!string.IsNullOrEmpty(_workContextAccessor.WorkContext.CurrentStore.Id))
- cart = cart.LimitPerStore(_shoppingCartSettings.SharedCartBetweenStores, _workContextAccessor.WorkContext.CurrentStore.Id);
+ if (!string.IsNullOrEmpty(_contextAccessor.StoreContext.CurrentStore.Id))
+ cart = cart.LimitPerStore(_shoppingCartSettings.SharedCartBetweenStores, _contextAccessor.StoreContext.CurrentStore.Id);
var model = await _mediator.Send(new GetMiniWishlist {
Cart = cart.ToList(),
- Customer = _workContextAccessor.WorkContext.CurrentCustomer,
- Language = _workContextAccessor.WorkContext.WorkingLanguage,
- Currency = _workContextAccessor.WorkContext.WorkingCurrency,
- Store = _workContextAccessor.WorkContext.CurrentStore
+ Customer = _contextAccessor.WorkContext.CurrentCustomer,
+ Language = _contextAccessor.WorkContext.WorkingLanguage,
+ Currency = _contextAccessor.WorkContext.WorkingCurrency,
+ Store = _contextAccessor.StoreContext.CurrentStore
});
return Json(model);
@@ -92,23 +92,23 @@ public class WishlistController : BasePublicController
var customer = customerGuid.HasValue
? await _customerService.GetCustomerByGuid(customerGuid.Value)
- : _workContextAccessor.WorkContext.CurrentCustomer;
+ : _contextAccessor.WorkContext.CurrentCustomer;
if (customer == null)
return RedirectToRoute("HomePage");
var cart = customer.ShoppingCartItems.Where(sci => sci.ShoppingCartTypeId == ShoppingCartType.Wishlist);
- if (!string.IsNullOrEmpty(_workContextAccessor.WorkContext.CurrentStore.Id))
- cart = cart.LimitPerStore(_shoppingCartSettings.SharedCartBetweenStores, _workContextAccessor.WorkContext.CurrentStore.Id);
+ if (!string.IsNullOrEmpty(_contextAccessor.StoreContext.CurrentStore.Id))
+ cart = cart.LimitPerStore(_shoppingCartSettings.SharedCartBetweenStores, _contextAccessor.StoreContext.CurrentStore.Id);
var model = await _mediator.Send(new GetWishlist {
Cart = cart.ToList(),
Customer = customer,
- Language = _workContextAccessor.WorkContext.WorkingLanguage,
- Currency = _workContextAccessor.WorkContext.WorkingCurrency,
- Store = _workContextAccessor.WorkContext.CurrentStore,
+ Language = _contextAccessor.WorkContext.WorkingLanguage,
+ Currency = _contextAccessor.WorkContext.WorkingCurrency,
+ Store = _contextAccessor.StoreContext.CurrentStore,
IsEditable = !customerGuid.HasValue,
- TaxDisplayType = _workContextAccessor.WorkContext.TaxDisplayType
+ TaxDisplayType = _contextAccessor.WorkContext.TaxDisplayType
});
return View(model);
@@ -123,12 +123,12 @@ public class WishlistController : BasePublicController
if (ModelState.IsValid)
{
var cart =
- (await _shoppingCartService.GetShoppingCart(_workContextAccessor.WorkContext.CurrentStore.Id, ShoppingCartType.Wishlist))
+ (await _shoppingCartService.GetShoppingCart(_contextAccessor.StoreContext.CurrentStore.Id, ShoppingCartType.Wishlist))
.FirstOrDefault(x => x.Id == model.ShoppingCartId);
if (cart != null)
{
var currSciWarnings = await _shoppingCartService.UpdateShoppingCartItem(
- _workContextAccessor.WorkContext.CurrentCustomer,
+ _contextAccessor.WorkContext.CurrentCustomer,
cart.Id, cart.WarehouseId, cart.Attributes, cart.EnteredPrice,
cart.RentalStartDateUtc, cart.RentalEndDateUtc,
model.Quantity);
@@ -145,7 +145,7 @@ public class WishlistController : BasePublicController
success = !warnings.Any(),
warnings = string.Join(", ", warnings),
totalproducts =
- (await _shoppingCartService.GetShoppingCart(_workContextAccessor.WorkContext.CurrentStore.Id, ShoppingCartType.Wishlist))
+ (await _shoppingCartService.GetShoppingCart(_contextAccessor.StoreContext.CurrentStore.Id, ShoppingCartType.Wishlist))
.Sum(x => x.Quantity)
});
}
@@ -162,7 +162,7 @@ public class WishlistController : BasePublicController
var pageCustomer = model.CustomerGuid.HasValue
? await _customerService.GetCustomerByGuid(model.CustomerGuid.Value)
- : _workContextAccessor.WorkContext.CurrentCustomer;
+ : _contextAccessor.WorkContext.CurrentCustomer;
if (pageCustomer == null)
return Json(new { success = false, message = "Customer not found" });
@@ -173,9 +173,9 @@ public class WishlistController : BasePublicController
if (itemCart == null)
return Json(new { success = false, message = "Shopping cart ident not found" });
- var warnings = (await _shoppingCartService.AddToCart(_workContextAccessor.WorkContext.CurrentCustomer,
+ var warnings = (await _shoppingCartService.AddToCart(_contextAccessor.WorkContext.CurrentCustomer,
itemCart.ProductId, ShoppingCartType.ShoppingCart,
- _workContextAccessor.WorkContext.CurrentStore.Id, itemCart.WarehouseId,
+ _contextAccessor.StoreContext.CurrentStore.Id, itemCart.WarehouseId,
itemCart.Attributes, itemCart.EnteredPrice,
itemCart.RentalStartDateUtc, itemCart.RentalEndDateUtc, itemCart.Quantity,
validator: new ShoppingCartValidatorOptions { GetRequiredProductWarnings = false })).warnings;
@@ -184,7 +184,7 @@ public class WishlistController : BasePublicController
return Json(new { success = false, message = string.Join(',', warnings) });
if (_shoppingCartSettings.MoveItemsFromWishlistToCart)
- await _shoppingCartService.DeleteShoppingCartItem(_workContextAccessor.WorkContext.CurrentCustomer, itemCart);
+ await _shoppingCartService.DeleteShoppingCartItem(_contextAccessor.WorkContext.CurrentCustomer, itemCart);
return Json(new { success = true, message = "" });
}
@@ -199,13 +199,13 @@ public class WishlistController : BasePublicController
if (!await _permissionService.Authorize(StandardPermission.EnableWishlist))
return Json(new { success = false, message = "No permission" });
- var itemCart = _workContextAccessor.WorkContext.CurrentCustomer.ShoppingCartItems
+ var itemCart = _contextAccessor.WorkContext.CurrentCustomer.ShoppingCartItems
.FirstOrDefault(sci => sci.ShoppingCartTypeId == ShoppingCartType.Wishlist && sci.Id == shoppingCartId);
if (itemCart == null)
return Json(new { success = false, message = "Shopping cart ident not found" });
- await _shoppingCartService.DeleteShoppingCartItem(_workContextAccessor.WorkContext.CurrentCustomer, itemCart);
+ await _shoppingCartService.DeleteShoppingCartItem(_contextAccessor.WorkContext.CurrentCustomer, itemCart);
return Json(new { success = true, message = "" });
}
@@ -221,16 +221,16 @@ public class WishlistController : BasePublicController
!_shoppingCartSettings.EmailWishlistEnabled)
return Content("");
- var cart = await _shoppingCartService.GetShoppingCart(_workContextAccessor.WorkContext.CurrentStore.Id, ShoppingCartType.Wishlist);
+ var cart = await _shoppingCartService.GetShoppingCart(_contextAccessor.StoreContext.CurrentStore.Id, ShoppingCartType.Wishlist);
if (!cart.Any())
return Content("");
if (ModelState.IsValid)
{
//email
- await messageProviderService.SendWishlistEmailAFriendMessage(_workContextAccessor.WorkContext.CurrentCustomer,
- _workContextAccessor.WorkContext.CurrentStore,
- _workContextAccessor.WorkContext.WorkingLanguage.Id, model.YourEmailAddress,
+ await messageProviderService.SendWishlistEmailAFriendMessage(_contextAccessor.WorkContext.CurrentCustomer,
+ _contextAccessor.StoreContext.CurrentStore,
+ _contextAccessor.WorkContext.WorkingLanguage.Id, model.YourEmailAddress,
model.FriendEmail, FormatText.ConvertText(model.PersonalMessage));
model.SuccessfullySent = true;
diff --git a/src/Web/Grand.Web/Features/Handlers/Blogs/GetBlogPostCategoryHandler.cs b/src/Web/Grand.Web/Features/Handlers/Blogs/GetBlogPostCategoryHandler.cs
index 7f756c06a..725d5ef60 100644
--- a/src/Web/Grand.Web/Features/Handlers/Blogs/GetBlogPostCategoryHandler.cs
+++ b/src/Web/Grand.Web/Features/Handlers/Blogs/GetBlogPostCategoryHandler.cs
@@ -13,29 +13,29 @@ public class GetBlogPostCategoryHandler : IRequestHandler<GetBlogPostCategory, I
{
private readonly IBlogService _blogService;
private readonly ICacheBase _cacheBase;
- private readonly IWorkContextAccessor _workContextAccessor;
+ private readonly IContextAccessor _contextAccessor;
public GetBlogPostCategoryHandler(IBlogService blogService, ICacheBase cacheBase,
- IWorkContextAccessor workContextAccessor)
+ IContextAccessor contextAccessor)
{
_blogService = blogService;
_cacheBase = cacheBase;
- _workContextAccessor = workContextAccessor;
+ _contextAccessor = contextAccessor;
}
public async Task<IList<BlogPostCategoryModel>> Handle(GetBlogPostCategory request,
CancellationToken cancellationToken)
{
- var cacheKey = string.Format(CacheKeyConst.BLOG_CATEGORY_MODEL_KEY, _workContextAccessor.WorkContext.WorkingLanguage.Id,
- _workContextAccessor.WorkContext.CurrentStore.Id);
+ var cacheKey = string.Format(CacheKeyConst.BLOG_CATEGORY_MODEL_KEY, _contextAccessor.WorkContext.WorkingLanguage.Id,
+ _contextAccessor.StoreContext.CurrentStore.Id);
var cachedModel = await _cacheBase.GetAsync(cacheKey, async () =>
{
var model = new List<BlogPostCategoryModel>();
- var categories = await _blogService.GetAllBlogCategories(_workContextAccessor.WorkContext.CurrentStore.Id);
+ var categories = await _blogService.GetAllBlogCategories(_contextAccessor.StoreContext.CurrentStore.Id);
foreach (var item in categories)
model.Add(new BlogPostCategoryModel {
Id = item.Id,
- Name = item.GetTranslation(x => x.Name, _workContextAccessor.WorkContext.WorkingLanguage.Id),
+ Name = item.GetTranslation(x => x.Name, _contextAccessor.WorkContext.WorkingLanguage.Id),
SeName = item.SeName,
BlogPostCount = item.BlogPosts.Count
});
diff --git a/src/Web/Grand.Web/Features/Handlers/Blogs/GetBlogPostHandler.cs b/src/Web/Grand.Web/Features/Handlers/Blogs/GetBlogPostHandler.cs
index ae47936ab..bb42eeef8 100644
--- a/src/Web/Grand.Web/Features/Handlers/Blogs/GetBlogPostHandler.cs
+++ b/src/Web/Grand.Web/Features/Handlers/Blogs/GetBlogPostHandler.cs
@@ -27,11 +27,11 @@ public class GetBlogPostHandler : IRequestHandler<GetBlogPost, BlogPostModel>
private readonly MediaSettings _mediaSettings;
private readonly IPictureService _pictureService;
private readonly ITranslationService _translationService;
- private readonly IWorkContextAccessor _workContextAccessor;
+ private readonly IContextAccessor _contextAccessor;
public GetBlogPostHandler(
IBlogService blogService,
- IWorkContextAccessor workContextAccessor,
+ IContextAccessor contextAccessor,
IPictureService pictureService,
ITranslationService translationService,
IDateTimeService dateTimeService,
@@ -41,7 +41,7 @@ public class GetBlogPostHandler : IRequestHandler<GetBlogPost, BlogPostModel>
CustomerSettings customerSettings)
{
_blogService = blogService;
- _workContextAccessor = workContextAccessor;
+ _contextAccessor = contextAccessor;
_pictureService = pictureService;
_translationService = translationService;
_dateTimeService = dateTimeService;
@@ -59,13 +59,13 @@ public class GetBlogPostHandler : IRequestHandler<GetBlogPost, BlogPostModel>
var model = new BlogPostModel {
Id = request.BlogPost.Id,
- MetaTitle = request.BlogPost.GetTranslation(x => x.MetaTitle, _workContextAccessor.WorkContext.WorkingLanguage.Id),
- MetaDescription = request.BlogPost.GetTranslation(x => x.MetaDescription, _workContextAccessor.WorkContext.WorkingLanguage.Id),
- MetaKeywords = request.BlogPost.GetTranslation(x => x.MetaKeywords, _workContextAccessor.WorkContext.WorkingLanguage.Id),
- SeName = request.BlogPost.GetSeName(_workContextAccessor.WorkContext.WorkingLanguage.Id),
- Title = request.BlogPost.GetTranslation(x => x.Title, _workContextAccessor.WorkContext.WorkingLanguage.Id),
- Body = request.BlogPost.GetTranslation(x => x.Body, _workContextAccessor.WorkContext.WorkingLanguage.Id),
- BodyOverview = request.BlogPost.GetTranslation(x => x.BodyOverview, _workContextAccessor.WorkContext.WorkingLanguage.Id),
+ MetaTitle = request.BlogPost.GetTranslation(x => x.MetaTitle, _contextAccessor.WorkContext.WorkingLanguage.Id),
+ MetaDescription = request.BlogPost.GetTranslation(x => x.MetaDescription, _contextAccessor.WorkContext.WorkingLanguage.Id),
+ MetaKeywords = request.BlogPost.GetTranslation(x => x.MetaKeywords, _contextAccessor.WorkContext.WorkingLanguage.Id),
+ SeName = request.BlogPost.GetSeName(_contextAccessor.WorkContext.WorkingLanguage.Id),
+ Title = request.BlogPost.GetTranslation(x => x.Title, _contextAccessor.WorkContext.WorkingLanguage.Id),
+ Body = request.BlogPost.GetTranslation(x => x.Body, _contextAccessor.WorkContext.WorkingLanguage.Id),
+ BodyOverview = request.BlogPost.GetTranslation(x => x.BodyOverview, _contextAccessor.WorkContext.WorkingLanguage.Id),
AllowComments = request.BlogPost.AllowComments,
CreatedOn = _dateTimeService.ConvertToUserTime(
request.BlogPost.StartDateUtc ?? request.BlogPost.CreatedOnUtc, DateTimeKind.Utc),
@@ -105,15 +105,15 @@ public class GetBlogPostHandler : IRequestHandler<GetBlogPost, BlogPostModel>
Title =
picture != null &&
!string.IsNullOrEmpty(
- picture.GetTranslation(x => x.TitleAttribute, _workContextAccessor.WorkContext.WorkingLanguage.Id))
- ? picture.GetTranslation(x => x.TitleAttribute, _workContextAccessor.WorkContext.WorkingLanguage.Id)
+ picture.GetTranslation(x => x.TitleAttribute, _contextAccessor.WorkContext.WorkingLanguage.Id))
+ ? picture.GetTranslation(x => x.TitleAttribute, _contextAccessor.WorkContext.WorkingLanguage.Id)
: string.Format(_translationService.GetResource("Media.Blog.ImageLinkTitleFormat"),
blogPost.Title),
//"alt" attribute
AlternateText =
picture != null &&
- !string.IsNullOrEmpty(picture.GetTranslation(x => x.AltAttribute, _workContextAccessor.WorkContext.WorkingLanguage.Id))
- ? picture.GetTranslation(x => x.AltAttribute, _workContextAccessor.WorkContext.WorkingLanguage.Id)
+ !string.IsNullOrEmpty(picture.GetTranslation(x => x.AltAttribute, _contextAccessor.WorkContext.WorkingLanguage.Id))
+ ? picture.GetTranslation(x => x.AltAttribute, _contextAccessor.WorkContext.WorkingLanguage.Id)
: string.Format(_translationService.GetResource("Media.Blog.ImageAlternateTextFormat"),
blogPost.Title)
};
diff --git a/src/Web/Grand.Web/Features/Handlers/Blogs/GetBlogPostListHandler.cs b/src/Web/Grand.Web/Features/Handlers/Blogs/GetBlogPostListHandler.cs
index 21ea87c2d..e73e56fda 100644
--- a/src/Web/Grand.Web/Features/Handlers/Blogs/GetBlogPostListHandler.cs
+++ b/src/Web/Grand.Web/Features/Handlers/Blogs/GetBlogPostListHandler.cs
@@ -17,17 +17,19 @@ namespace Grand.Web.Features.Handlers.Blogs;
public class GetBlogPostListHandler : IRequestHandler<GetBlogPostList, BlogPostListModel>
{
private readonly IBlogService _blogService;
-
- private readonly BlogSettings _blogSettings;
private readonly IDateTimeService _dateTimeService;
- private readonly MediaSettings _mediaSettings;
private readonly IPictureService _pictureService;
private readonly ITranslationService _translationService;
- private readonly IWorkContextAccessor _workContextAccessor;
+ private readonly IContextAccessor _contextAccessor;
+ private readonly MediaSettings _mediaSettings;
+ private readonly BlogSettings _blogSettings;
+
+ private string WorkingLanguageId => _contextAccessor.WorkContext.WorkingLanguage.Id;
+ private string CurrentStoreId => _contextAccessor.StoreContext.CurrentStore.Id;
public GetBlogPostListHandler(
IBlogService blogService,
- IWorkContextAccessor workContextAccessor,
+ IContextAccessor contextAccessor,
IPictureService pictureService,
ITranslationService translationService,
IDateTimeService dateTimeService,
@@ -35,7 +37,7 @@ public class GetBlogPostListHandler : IRequestHandler<GetBlogPostList, BlogPostL
MediaSettings mediaSettings)
{
_blogService = blogService;
- _workContextAccessor = workContextAccessor;
+ _contextAccessor = contextAccessor;
_pictureService = pictureService;
_translationService = translationService;
_dateTimeService = dateTimeService;
@@ -52,7 +54,7 @@ public class GetBlogPostListHandler : IRequestHandler<GetBlogPostList, BlogPostL
Month = request.Command.Month,
CategorySeName = request.Command.CategorySeName
},
- WorkingLanguageId = _workContextAccessor.WorkContext.WorkingLanguage.Id,
+ WorkingLanguageId = WorkingLanguageId,
SearchKeyword = request.Command.SearchKeyword
};
@@ -66,18 +68,18 @@ public class GetBlogPostListHandler : IRequestHandler<GetBlogPostList, BlogPostL
if (string.IsNullOrEmpty(request.Command.CategorySeName))
{
if (string.IsNullOrEmpty(request.Command.Tag))
- blogPosts = await _blogService.GetAllBlogPosts(_workContextAccessor.WorkContext.CurrentStore.Id,
+ blogPosts = await _blogService.GetAllBlogPosts(CurrentStoreId,
dateFrom, dateTo, request.Command.PageNumber - 1, request.Command.PageSize,
blogPostName: model.SearchKeyword);
else
- blogPosts = await _blogService.GetAllBlogPostsByTag(_workContextAccessor.WorkContext.CurrentStore.Id,
+ blogPosts = await _blogService.GetAllBlogPostsByTag(CurrentStoreId,
request.Command.Tag, request.Command.PageNumber - 1, request.Command.PageSize);
}
else
{
var categoryblog = await _blogService.GetBlogCategoryBySeName(request.Command.CategorySeName);
var categoryId = categoryblog != null ? categoryblog.Id : "";
- blogPosts = await _blogService.GetAllBlogPosts(_workContextAccessor.WorkContext.CurrentStore.Id,
+ blogPosts = await _blogService.GetAllBlogPosts(CurrentStoreId,
dateFrom, dateTo, request.Command.PageNumber - 1, request.Command.PageSize, categoryId: categoryId,
blogPostName: model.SearchKeyword);
}
@@ -100,13 +102,13 @@ public class GetBlogPostListHandler : IRequestHandler<GetBlogPostList, BlogPostL
ArgumentNullException.ThrowIfNull(model);
model.Id = blogPost.Id;
- model.MetaTitle = blogPost.GetTranslation(x => x.MetaTitle, _workContextAccessor.WorkContext.WorkingLanguage.Id);
- model.MetaDescription = blogPost.GetTranslation(x => x.MetaDescription, _workContextAccessor.WorkContext.WorkingLanguage.Id);
- model.MetaKeywords = blogPost.GetTranslation(x => x.MetaKeywords, _workContextAccessor.WorkContext.WorkingLanguage.Id);
- model.SeName = blogPost.GetSeName(_workContextAccessor.WorkContext.WorkingLanguage.Id);
- model.Title = blogPost.GetTranslation(x => x.Title, _workContextAccessor.WorkContext.WorkingLanguage.Id);
- model.Body = blogPost.GetTranslation(x => x.Body, _workContextAccessor.WorkContext.WorkingLanguage.Id);
- model.BodyOverview = blogPost.GetTranslation(x => x.BodyOverview, _workContextAccessor.WorkContext.WorkingLanguage.Id);
+ model.MetaTitle = blogPost.GetTranslation(x => x.MetaTitle, WorkingLanguageId);
+ model.MetaDescription = blogPost.GetTranslation(x => x.MetaDescription, WorkingLanguageId);
+ model.MetaKeywords = blogPost.GetTranslation(x => x.MetaKeywords, WorkingLanguageId);
+ model.SeName = blogPost.GetSeName(WorkingLanguageId);
+ model.Title = blogPost.GetTranslation(x => x.Title, WorkingLanguageId);
+ model.Body = blogPost.GetTranslation(x => x.Body, WorkingLanguageId);
+ model.BodyOverview = blogPost.GetTranslation(x => x.BodyOverview, WorkingLanguageId);
model.AllowComments = blogPost.AllowComments;
model.CreatedOn =
_dateTimeService.ConvertToUserTime(blogPost.StartDateUtc ?? blogPost.CreatedOnUtc, DateTimeKind.Utc);
@@ -134,15 +136,15 @@ public class GetBlogPostListHandler : IRequestHandler<GetBlogPostList, BlogPostL
Title =
picture != null &&
!string.IsNullOrEmpty(
- picture.GetTranslation(x => x.TitleAttribute, _workContextAccessor.WorkContext.WorkingLanguage.Id))
- ? picture.GetTranslation(x => x.TitleAttribute, _workContextAccessor.WorkContext.WorkingLanguage.Id)
+ picture.GetTranslation(x => x.TitleAttribute, WorkingLanguageId))
+ ? picture.GetTranslation(x => x.TitleAttribute, WorkingLanguageId)
: string.Format(_translationService.GetResource("Media.Blog.ImageLinkTitleFormat"),
blogPost.Title),
//"alt" attribute
AlternateText =
picture != null &&
- !string.IsNullOrEmpty(picture.GetTranslation(x => x.AltAttribute, _workContextAccessor.WorkContext.WorkingLanguage.Id))
- ? picture.GetTranslation(x => x.AltAttribute, _workContextAccessor.WorkContext.WorkingLanguage.Id)
+ !string.IsNullOrEmpty(picture.GetTranslation(x => x.AltAttribute, WorkingLanguageId))
+ ? picture.GetTranslation(x => x.AltAttribute, WorkingLanguageId)
: string.Format(_translationService.GetResource("Media.Blog.ImageAlternateTextFormat"),
blogPost.Title)
};
diff --git a/src/Web/Grand.Web/Features/Handlers/Blogs/GetBlogPostTagListHandler.cs b/src/Web/Grand.Web/Features/Handlers/Blogs/GetBlogPostTagListHandler.cs
index 5de34fe57..643cff7d3 100644
--- a/src/Web/Grand.Web/Features/Handlers/Blogs/GetBlogPostTagListHandler.cs
+++ b/src/Web/Grand.Web/Features/Handlers/Blogs/GetBlogPostTagListHandler.cs
@@ -15,27 +15,27 @@ public class GetBlogPostTagListHandler : IRequestHandler<GetBlogPostTagList, Blo
private readonly BlogSettings _blogSettings;
private readonly ICacheBase _cacheBase;
- private readonly IWorkContextAccessor _workContextAccessor;
+ private readonly IContextAccessor _contextAccessor;
- public GetBlogPostTagListHandler(IBlogService blogService, ICacheBase cacheBase, IWorkContextAccessor workContextAccessor,
+ public GetBlogPostTagListHandler(IBlogService blogService, ICacheBase cacheBase, IContextAccessor contextAccessor,
BlogSettings blogSettings)
{
_blogService = blogService;
_cacheBase = cacheBase;
- _workContextAccessor = workContextAccessor;
+ _contextAccessor = contextAccessor;
_blogSettings = blogSettings;
}
public async Task<BlogPostTagListModel> Handle(GetBlogPostTagList request, CancellationToken cancellationToken)
{
- var cacheKey = string.Format(CacheKeyConst.BLOG_TAGS_MODEL_KEY, _workContextAccessor.WorkContext.WorkingLanguage.Id,
- _workContextAccessor.WorkContext.CurrentStore.Id);
+ var cacheKey = string.Format(CacheKeyConst.BLOG_TAGS_MODEL_KEY, _contextAccessor.WorkContext.WorkingLanguage.Id,
+ _contextAccessor.StoreContext.CurrentStore.Id);
var cachedModel = await _cacheBase.GetAsync(cacheKey, async () =>
{
var model = new BlogPostTagListModel();
//get tags
- var tags = await _blogService.GetAllBlogPostTags(_workContextAccessor.WorkContext.CurrentStore.Id);
+ var tags = await _blogService.GetAllBlogPostTags(_contextAccessor.StoreContext.CurrentStore.Id);
tags = tags.OrderByDescending(x => x.BlogPostCount)
.Take(_blogSettings.NumberOfTags)
.ToList();
diff --git a/src/Web/Grand.Web/Features/Handlers/Blogs/GetBlogPostYearHandler.cs b/src/Web/Grand.Web/Features/Handlers/Blogs/GetBlogPostYearHandler.cs
index 74cd92b36..a5262487d 100644
--- a/src/Web/Grand.Web/Features/Handlers/Blogs/GetBlogPostYearHandler.cs
+++ b/src/Web/Grand.Web/Features/Handlers/Blogs/GetBlogPostYearHandler.cs
@@ -13,25 +13,25 @@ public class GetBlogPostYearHandler : IRequestHandler<GetBlogPostYear, IList<Blo
{
private readonly IBlogService _blogService;
private readonly ICacheBase _cacheBase;
- private readonly IWorkContextAccessor _workContextAccessor;
+ private readonly IContextAccessor _contextAccessor;
public GetBlogPostYearHandler(IBlogService blogService, ICacheBase cacheBase,
- IWorkContextAccessor workContextAccessor)
+ IContextAccessor contextAccessor)
{
_blogService = blogService;
_cacheBase = cacheBase;
- _workContextAccessor = workContextAccessor;
+ _contextAccessor = contextAccessor;
}
public async Task<IList<BlogPostYearModel>> Handle(GetBlogPostYear request, CancellationToken cancellationToken)
{
- var cacheKey = string.Format(CacheKeyConst.BLOG_MONTHS_MODEL_KEY, _workContextAccessor.WorkContext.WorkingLanguage.Id,
- _workContextAccessor.WorkContext.CurrentStore.Id);
+ var cacheKey = string.Format(CacheKeyConst.BLOG_MONTHS_MODEL_KEY, _contextAccessor.WorkContext.WorkingLanguage.Id,
+ _contextAccessor.StoreContext.CurrentStore.Id);
var cachedModel = await _cacheBase.GetAsync(cacheKey, async () =>
{
var model = new List<BlogPostYearModel>();
- var blogPosts = await _blogService.GetAllBlogPosts(_workContextAccessor.WorkContext.CurrentStore.Id);
+ var blogPosts = await _blogService.GetAllBlogPosts(_contextAccessor.StoreContext.CurrentStore.Id);
if (!blogPosts.Any()) return model;
var months = new SortedDictionary<DateTime, int>();
diff --git a/src/Web/Grand.Web/Features/Handlers/Blogs/GetHomePageBlogHandler.cs b/src/Web/Grand.Web/Features/Handlers/Blogs/GetHomePageBlogHandler.cs
index a21ccade8..fed1088f6 100644
--- a/src/Web/Grand.Web/Features/Handlers/Blogs/GetHomePageBlogHandler.cs
+++ b/src/Web/Grand.Web/Features/Handlers/Blogs/GetHomePageBlogHandler.cs
@@ -25,10 +25,10 @@ public class GetHomePageBlogHandler : IRequestHandler<GetHomePageBlog, HomePageB
private readonly MediaSettings _mediaSettings;
private readonly IPictureService _pictureService;
private readonly ITranslationService _translationService;
- private readonly IWorkContextAccessor _workContextAccessor;
+ private readonly IContextAccessor _contextAccessor;
public GetHomePageBlogHandler(IBlogService blogService,
- IWorkContextAccessor workContextAccessor,
+ IContextAccessor contextAccessor,
IPictureService pictureService,
ITranslationService translationService,
IDateTimeService dateTimeService,
@@ -37,7 +37,7 @@ public class GetHomePageBlogHandler : IRequestHandler<GetHomePageBlog, HomePageB
MediaSettings mediaSettings)
{
_blogService = blogService;
- _workContextAccessor = workContextAccessor;
+ _contextAccessor = contextAccessor;
_pictureService = pictureService;
_translationService = translationService;
_dateTimeService = dateTimeService;
@@ -50,21 +50,21 @@ public class GetHomePageBlogHandler : IRequestHandler<GetHomePageBlog, HomePageB
public async Task<HomePageBlogItemsModel> Handle(GetHomePageBlog request, CancellationToken cancellationToken)
{
var cacheKey = string.Format(CacheKeyConst.BLOG_HOMEPAGE_MODEL_KEY,
- _workContextAccessor.WorkContext.WorkingLanguage.Id,
- _workContextAccessor.WorkContext.CurrentStore.Id);
+ _contextAccessor.WorkContext.WorkingLanguage.Id,
+ _contextAccessor.StoreContext.CurrentStore.Id);
var cachedModel = await _cacheBase.GetAsync(cacheKey, async () =>
{
var model = new HomePageBlogItemsModel();
- var blogPosts = await _blogService.GetAllBlogPosts(_workContextAccessor.WorkContext.CurrentStore.Id,
+ var blogPosts = await _blogService.GetAllBlogPosts(_contextAccessor.StoreContext.CurrentStore.Id,
null, null, 0, _blogSettings.HomePageBlogCount);
foreach (var post in blogPosts)
{
var item = new HomePageBlogItemsModel.BlogItemModel();
- var description = post.GetTranslation(x => x.BodyOverview, _workContextAccessor.WorkContext.WorkingLanguage.Id);
- item.SeName = post.GetSeName(_workContextAccessor.WorkContext.WorkingLanguage.Id);
- item.Title = post.GetTranslation(x => x.Title, _workContextAccessor.WorkContext.WorkingLanguage.Id);
+ var description = post.GetTranslation(x => x.BodyOverview, _contextAccessor.WorkContext.WorkingLanguage.Id);
+ item.SeName = post.GetSeName(_contextAccessor.WorkContext.WorkingLanguage.Id);
+ item.Title = post.GetTranslation(x => x.Title, _contextAccessor.WorkContext.WorkingLanguage.Id);
item.Short = description?.Length > _blogSettings.MaxTextSizeHomePage
? description[.._blogSettings.MaxTextSizeHomePage]
: description;
@@ -72,7 +72,7 @@ public class GetHomePageBlogHandler : IRequestHandler<GetHomePageBlog, HomePageB
_dateTimeService.ConvertToUserTime(post.StartDateUtc ?? post.CreatedOnUtc, DateTimeKind.Utc);
item.UserFields = post.UserFields;
item.Category = (await _blogService.GetBlogCategoryByPostId(post.Id)).FirstOrDefault()
- ?.GetTranslation(x => x.Name, _workContextAccessor.WorkContext.WorkingLanguage.Id);
+ ?.GetTranslation(x => x.Name, _contextAccessor.WorkContext.WorkingLanguage.Id);
//prepare picture model
if (!string.IsNullOrEmpty(post.PictureId))
@@ -95,16 +95,16 @@ public class GetHomePageBlogHandler : IRequestHandler<GetHomePageBlog, HomePageB
//"title" attribute
pictureModel.Title =
picture != null && !string.IsNullOrEmpty(picture.GetTranslation(x => x.TitleAttribute,
- _workContextAccessor.WorkContext.WorkingLanguage.Id))
- ? picture.GetTranslation(x => x.TitleAttribute, _workContextAccessor.WorkContext.WorkingLanguage.Id)
+ _contextAccessor.WorkContext.WorkingLanguage.Id))
+ ? picture.GetTranslation(x => x.TitleAttribute, _contextAccessor.WorkContext.WorkingLanguage.Id)
: string.Format(_translationService.GetResource("Media.Blog.ImageLinkTitleFormat"),
post.Title);
//"alt" attribute
pictureModel.AlternateText =
picture != null &&
!string.IsNullOrEmpty(picture.GetTranslation(x => x.AltAttribute,
- _workContextAccessor.WorkContext.WorkingLanguage.Id))
- ? picture.GetTranslation(x => x.AltAttribute, _workContextAccessor.WorkContext.WorkingLanguage.Id)
+ _contextAccessor.WorkContext.WorkingLanguage.Id))
+ ? picture.GetTranslation(x => x.AltAttribute, _contextAccessor.WorkContext.WorkingLanguage.Id)
: string.Format(_translationService.GetResource("Media.Blog.ImageAlternateTextFormat"),
post.Title);
diff --git a/src/Web/Grand.Web/Features/Handlers/Catalog/GetCompareProductsHandler.cs b/src/Web/Grand.Web/Features/Handlers/Catalog/GetCompareProductsHandler.cs
index 2ff709e24..e75ae3aa6 100644
--- a/src/Web/Grand.Web/Features/Handlers/Catalog/GetCompareProductsHandler.cs
+++ b/src/Web/Grand.Web/Features/Handlers/Catalog/GetCompareProductsHandler.cs
@@ -18,18 +18,18 @@ public class GetCompareProductsHandler : IRequestHandler<GetCompareProducts, Com
private readonly IHttpContextAccessor _httpContextAccessor;
private readonly IMediator _mediator;
private readonly IProductService _productService;
- private readonly IWorkContextAccessor _workContextAccessor;
+ private readonly IContextAccessor _contextAccessor;
public GetCompareProductsHandler(
IProductService productService,
- IWorkContextAccessor workContextAccessor,
+ IContextAccessor contextAccessor,
IAclService aclService,
IMediator mediator,
IHttpContextAccessor httpContextAccessor,
CatalogSettings catalogSettings)
{
_productService = productService;
- _workContextAccessor = workContextAccessor;
+ _contextAccessor = contextAccessor;
_aclService = aclService;
_mediator = mediator;
_httpContextAccessor = httpContextAccessor;
@@ -54,8 +54,8 @@ public class GetCompareProductsHandler : IRequestHandler<GetCompareProducts, Com
//ACL and store acl
products = products.Where(p =>
- _aclService.Authorize(p, _workContextAccessor.WorkContext.CurrentCustomer) &&
- _aclService.Authorize(p, _workContextAccessor.WorkContext.CurrentStore.Id)).ToList();
+ _aclService.Authorize(p, _contextAccessor.WorkContext.CurrentCustomer) &&
+ _aclService.Authorize(p, _contextAccessor.StoreContext.CurrentStore.Id)).ToList();
//availability dates
products = products.Where(p => p.IsAvailable()).ToList();
diff --git a/src/Web/Grand.Web/Features/Handlers/Catalog/GetSearchAutoCompleteHandler.cs b/src/Web/Grand.Web/Features/Handlers/Catalog/GetSearchAutoCompleteHandler.cs
index e2a77ea16..a177dc1e6 100644
--- a/src/Web/Grand.Web/Features/Handlers/Catalog/GetSearchAutoCompleteHandler.cs
+++ b/src/Web/Grand.Web/Features/Handlers/Catalog/GetSearchAutoCompleteHandler.cs
@@ -39,7 +39,7 @@ public class GetSearchAutoCompleteHandler : IRequestHandler<GetSearchAutoComplet
private readonly IPricingService _pricingService;
private readonly ISearchTermService _searchTermService;
private readonly ITaxService _taxService;
- private readonly IWorkContextAccessor _workContextAccessor;
+ private readonly IContextAccessor _contextAccessor;
public GetSearchAutoCompleteHandler(
IPictureService pictureService,
@@ -52,7 +52,7 @@ public class GetSearchAutoCompleteHandler : IRequestHandler<GetSearchAutoComplet
ITaxService taxService,
IPriceFormatter priceFormatter,
IMediator mediator,
- IWorkContextAccessor workContextAccessor,
+ IContextAccessor contextAccessor,
IPermissionService permissionService,
CatalogSettings catalogSettings,
MediaSettings mediaSettings,
@@ -66,7 +66,7 @@ public class GetSearchAutoCompleteHandler : IRequestHandler<GetSearchAutoComplet
_blogService = blogService;
_pricingService = priceCalculationService;
_taxService = taxService;
- _workContextAccessor = workContextAccessor;
+ _contextAccessor = contextAccessor;
_priceFormatter = priceFormatter;
_mediator = mediator;
_permissionService = permissionService;
@@ -111,10 +111,10 @@ public class GetSearchAutoCompleteHandler : IRequestHandler<GetSearchAutoComplet
var categories = new List<string>();
var brands = new List<string>();
- var storeurl = _workContextAccessor.WorkContext.CurrentHost.Url.TrimEnd('/');
+ var storeurl = _contextAccessor.StoreContext.CurrentHost.Url.TrimEnd('/');
var displayPrices =
- await _permissionService.Authorize(StandardPermission.DisplayPrices, _workContextAccessor.WorkContext.CurrentCustomer);
+ await _permissionService.Authorize(StandardPermission.DisplayPrices, _contextAccessor.WorkContext.CurrentCustomer);
foreach (var item in products)
{
@@ -163,7 +163,7 @@ public class GetSearchAutoCompleteHandler : IRequestHandler<GetSearchAutoComplet
if (brand is not { Published: true }) continue;
var allow = true;
if (!_accessControlConfig.IgnoreAcl)
- if (!_aclService.Authorize(brand, _workContextAccessor.WorkContext.CurrentCustomer))
+ if (!_aclService.Authorize(brand, _contextAccessor.WorkContext.CurrentCustomer))
allow = false;
if (!_accessControlConfig.IgnoreStoreLimitations)
if (!_aclService.Authorize(brand, storeId))
@@ -188,7 +188,7 @@ public class GetSearchAutoCompleteHandler : IRequestHandler<GetSearchAutoComplet
if (category is not { Published: true }) continue;
var allow = true;
if (!_accessControlConfig.IgnoreAcl)
- if (!_aclService.Authorize(category, _workContextAccessor.WorkContext.CurrentCustomer))
+ if (!_aclService.Authorize(category, _contextAccessor.WorkContext.CurrentCustomer))
allow = false;
if (!_accessControlConfig.IgnoreStoreLimitations)
if (!_aclService.Authorize(category, storeId))
diff --git a/src/Web/Grand.Web/Features/Handlers/Common/GetStatesProvinceHandler.cs b/src/Web/Grand.Web/Features/Handlers/Common/GetStatesProvinceHandler.cs
index a143781c9..368ceefa5 100644
--- a/src/Web/Grand.Web/Features/Handlers/Common/GetStatesProvinceHandler.cs
+++ b/src/Web/Grand.Web/Features/Handlers/Common/GetStatesProvinceHandler.cs
@@ -12,23 +12,23 @@ public class GetStatesProvinceHandler : IRequestHandler<GetStatesProvince, IList
{
private readonly ICountryService _countryService;
private readonly ITranslationService _translationService;
- private readonly IWorkContextAccessor _workContextAccessor;
+ private readonly IContextAccessor _contextAccessor;
- public GetStatesProvinceHandler(ICountryService countryService, IWorkContextAccessor workContextAccessor,
+ public GetStatesProvinceHandler(ICountryService countryService, IContextAccessor contextAccessor,
ITranslationService translationService)
{
_countryService = countryService;
- _workContextAccessor = workContextAccessor;
+ _contextAccessor = contextAccessor;
_translationService = translationService;
}
public async Task<IList<StateProvinceModel>> Handle(GetStatesProvince request, CancellationToken cancellationToken)
{
var states =
- await _countryService.GetStateProvincesByCountryId(request.CountryId, _workContextAccessor.WorkContext.WorkingLanguage.Id);
+ await _countryService.GetStateProvincesByCountryId(request.CountryId, _contextAccessor.WorkContext.WorkingLanguage.Id);
var model = (from s in states
select new StateProvinceModel
- { id = s.Id, name = s.GetTranslation(x => x.Name, _workContextAccessor.WorkContext.WorkingLanguage.Id) }).ToList();
+ { id = s.Id, name = s.GetTranslation(x => x.Name, _contextAccessor.WorkContext.WorkingLanguage.Id) }).ToList();
if (request.AddSelectStateItem)
model.Insert(0,
new StateProvinceModel { id = "", name = _translationService.GetResource("Address.SelectState") });
diff --git a/src/Web/Grand.Web/Features/Handlers/News/GetHomePageNewsItemsHandler.cs b/src/Web/Grand.Web/Features/Handlers/News/GetHomePageNewsItemsHandler.cs
index 6335c4d74..0ed11ad2f 100644
--- a/src/Web/Grand.Web/Features/Handlers/News/GetHomePageNewsItemsHandler.cs
+++ b/src/Web/Grand.Web/Features/Handlers/News/GetHomePageNewsItemsHandler.cs
@@ -19,20 +19,22 @@ public class GetHomePageNewsItemsHandler : IRequestHandler<GetHomePageNewsItems,
{
private readonly ICacheBase _cacheBase;
private readonly IDateTimeService _dateTimeService;
- private readonly MediaSettings _mediaSettings;
- private readonly INewsService _newsService;
-
- private readonly NewsSettings _newsSettings;
private readonly IPictureService _pictureService;
private readonly ITranslationService _translationService;
- private readonly IWorkContextAccessor _workContextAccessor;
+ private readonly IContextAccessor _contextAccessor;
+ private readonly INewsService _newsService;
+ private readonly MediaSettings _mediaSettings;
+ private readonly NewsSettings _newsSettings;
+
+ private string WorkingLanguageId => _contextAccessor.WorkContext.WorkingLanguage.Id;
+ private string CurrentStoreId => _contextAccessor.StoreContext.CurrentStore.Id;
- public GetHomePageNewsItemsHandler(ICacheBase cacheBase, IWorkContextAccessor workContextAccessor,
+ public GetHomePageNewsItemsHandler(ICacheBase cacheBase, IContextAccessor contextAccessor,
INewsService newsService, IDateTimeService dateTimeService, IPictureService pictureService,
ITranslationService translationService, NewsSettings newsSettings, MediaSettings mediaSettings)
{
_cacheBase = cacheBase;
- _workContextAccessor = workContextAccessor;
+ _contextAccessor = contextAccessor;
_newsService = newsService;
_dateTimeService = dateTimeService;
_pictureService = pictureService;
@@ -43,12 +45,11 @@ public class GetHomePageNewsItemsHandler : IRequestHandler<GetHomePageNewsItems,
public async Task<HomePageNewsItemsModel> Handle(GetHomePageNewsItems request, CancellationToken cancellationToken)
{
- var cacheKey = string.Format(CacheKeyConst.HOMEPAGE_NEWSMODEL_KEY, _workContextAccessor.WorkContext.WorkingLanguage.Id,
- _workContextAccessor.WorkContext.CurrentStore.Id);
+ var cacheKey = string.Format(CacheKeyConst.HOMEPAGE_NEWSMODEL_KEY, WorkingLanguageId, CurrentStoreId);
var model = await _cacheBase.GetAsync(cacheKey, async () =>
{
var newsItems =
- await _newsService.GetAllNews(_workContextAccessor.WorkContext.CurrentStore.Id, 0, _newsSettings.MainPageNewsCount);
+ await _newsService.GetAllNews(CurrentStoreId, 0, _newsSettings.MainPageNewsCount);
var hpnitemodel = new HomePageNewsItemsModel();
foreach (var item in newsItems)
{
@@ -66,10 +67,10 @@ public class GetHomePageNewsItemsHandler : IRequestHandler<GetHomePageNewsItems,
{
var model = new HomePageNewsItemsModel.NewsItemModel {
Id = newsItem.Id,
- SeName = newsItem.GetSeName(_workContextAccessor.WorkContext.WorkingLanguage.Id),
- Title = newsItem.GetTranslation(x => x.Title, _workContextAccessor.WorkContext.WorkingLanguage.Id),
- Short = newsItem.GetTranslation(x => x.Short, _workContextAccessor.WorkContext.WorkingLanguage.Id),
- Full = newsItem.GetTranslation(x => x.Full, _workContextAccessor.WorkContext.WorkingLanguage.Id),
+ SeName = newsItem.GetSeName(WorkingLanguageId),
+ Title = newsItem.GetTranslation(x => x.Title, WorkingLanguageId),
+ Short = newsItem.GetTranslation(x => x.Short, WorkingLanguageId),
+ Full = newsItem.GetTranslation(x => x.Full, WorkingLanguageId),
CreatedOn = _dateTimeService.ConvertToUserTime(newsItem.StartDateUtc ?? newsItem.CreatedOnUtc,
DateTimeKind.Utc)
};
diff --git a/src/Web/Grand.Web/Features/Handlers/News/GetNewsItemHandler.cs b/src/Web/Grand.Web/Features/Handlers/News/GetNewsItemHandler.cs
index d78b4071b..76292a6df 100644
--- a/src/Web/Grand.Web/Features/Handlers/News/GetNewsItemHandler.cs
+++ b/src/Web/Grand.Web/Features/Handlers/News/GetNewsItemHandler.cs
@@ -25,13 +25,13 @@ public class GetNewsItemHandler : IRequestHandler<GetNewsItem, NewsItemModel>
private readonly MediaSettings _mediaSettings;
private readonly IPictureService _pictureService;
private readonly ITranslationService _translationService;
- private readonly IWorkContextAccessor _workContextAccessor;
+ private readonly IContextAccessor _contextAccessor;
- public GetNewsItemHandler(IWorkContextAccessor workContextAccessor, IDateTimeService dateTimeService,
+ public GetNewsItemHandler(IContextAccessor contextAccessor, IDateTimeService dateTimeService,
IPictureService pictureService, ITranslationService translationService, ICustomerService customerService,
MediaSettings mediaSettings, CaptchaSettings captchaSettings, CustomerSettings customerSettings)
{
- _workContextAccessor = workContextAccessor;
+ _contextAccessor = contextAccessor;
_dateTimeService = dateTimeService;
_pictureService = pictureService;
_translationService = translationService;
@@ -46,13 +46,13 @@ public class GetNewsItemHandler : IRequestHandler<GetNewsItem, NewsItemModel>
{
var model = new NewsItemModel {
Id = request.NewsItem.Id,
- MetaTitle = request.NewsItem.GetTranslation(x => x.MetaTitle, _workContextAccessor.WorkContext.WorkingLanguage.Id),
- MetaDescription = request.NewsItem.GetTranslation(x => x.MetaDescription, _workContextAccessor.WorkContext.WorkingLanguage.Id),
- MetaKeywords = request.NewsItem.GetTranslation(x => x.MetaKeywords, _workContextAccessor.WorkContext.WorkingLanguage.Id),
- SeName = request.NewsItem.GetSeName(_workContextAccessor.WorkContext.WorkingLanguage.Id),
- Title = request.NewsItem.GetTranslation(x => x.Title, _workContextAccessor.WorkContext.WorkingLanguage.Id),
- Short = request.NewsItem.GetTranslation(x => x.Short, _workContextAccessor.WorkContext.WorkingLanguage.Id),
- Full = request.NewsItem.GetTranslation(x => x.Full, _workContextAccessor.WorkContext.WorkingLanguage.Id),
+ MetaTitle = request.NewsItem.GetTranslation(x => x.MetaTitle, _contextAccessor.WorkContext.WorkingLanguage.Id),
+ MetaDescription = request.NewsItem.GetTranslation(x => x.MetaDescription, _contextAccessor.WorkContext.WorkingLanguage.Id),
+ MetaKeywords = request.NewsItem.GetTranslation(x => x.MetaKeywords, _contextAccessor.WorkContext.WorkingLanguage.Id),
+ SeName = request.NewsItem.GetSeName(_contextAccessor.WorkContext.WorkingLanguage.Id),
+ Title = request.NewsItem.GetTranslation(x => x.Title, _contextAccessor.WorkContext.WorkingLanguage.Id),
+ Short = request.NewsItem.GetTranslation(x => x.Short, _contextAccessor.WorkContext.WorkingLanguage.Id),
+ Full = request.NewsItem.GetTranslation(x => x.Full, _contextAccessor.WorkContext.WorkingLanguage.Id),
AllowComments = request.NewsItem.AllowComments,
CreatedOn = _dateTimeService.ConvertToUserTime(
request.NewsItem.StartDateUtc ?? request.NewsItem.CreatedOnUtc, DateTimeKind.Utc),
diff --git a/src/Web/Grand.Web/Features/Handlers/News/GetNewsItemListHandler.cs b/src/Web/Grand.Web/Features/Handlers/News/GetNewsItemListHandler.cs
index 3c931fa32..62af08b44 100644
--- a/src/Web/Grand.Web/Features/Handlers/News/GetNewsItemListHandler.cs
+++ b/src/Web/Grand.Web/Features/Handlers/News/GetNewsItemListHandler.cs
@@ -16,19 +16,20 @@ namespace Grand.Web.Features.Handlers.News;
public class GetNewsItemListHandler : IRequestHandler<GetNewsItemList, NewsItemListModel>
{
private readonly IDateTimeService _dateTimeService;
- private readonly MediaSettings _mediaSettings;
private readonly INewsService _newsService;
-
- private readonly NewsSettings _newsSettings;
private readonly IPictureService _pictureService;
private readonly ITranslationService _translationService;
- private readonly IWorkContextAccessor _workContextAccessor;
+ private readonly IContextAccessor _contextAccessor;
+ private readonly MediaSettings _mediaSettings;
+ private readonly NewsSettings _newsSettings;
+
+ private string WorkingLanguageId => _contextAccessor.WorkContext.WorkingLanguage.Id;
- public GetNewsItemListHandler(IWorkContextAccessor workContextAccessor,
+ public GetNewsItemListHandler(IContextAccessor contextAccessor,
INewsService newsService, IDateTimeService dateTimeService, IPictureService pictureService,
ITranslationService translationService, NewsSettings newsSettings, MediaSettings mediaSettings)
{
- _workContextAccessor = workContextAccessor;
+ _contextAccessor = contextAccessor;
_newsService = newsService;
_dateTimeService = dateTimeService;
_pictureService = pictureService;
@@ -40,13 +41,13 @@ public class GetNewsItemListHandler : IRequestHandler<GetNewsItemList, NewsItemL
public async Task<NewsItemListModel> Handle(GetNewsItemList request, CancellationToken cancellationToken)
{
var model = new NewsItemListModel {
- WorkingLanguageId = _workContextAccessor.WorkContext.WorkingLanguage.Id
+ WorkingLanguageId = WorkingLanguageId
};
if (request.Command.PageSize <= 0) request.Command.PageSize = _newsSettings.NewsArchivePageSize;
if (request.Command.PageNumber <= 0) request.Command.PageNumber = 1;
- var newsItems = await _newsService.GetAllNews(_workContextAccessor.WorkContext.CurrentStore.Id,
+ var newsItems = await _newsService.GetAllNews(_contextAccessor.StoreContext.CurrentStore.Id,
request.Command.PageNumber - 1, request.Command.PageSize);
model.PagingFilteringContext.LoadPagedList(newsItems);
foreach (var item in newsItems)
@@ -62,12 +63,11 @@ public class GetNewsItemListHandler : IRequestHandler<GetNewsItemList, NewsItemL
{
var model = new NewsItemListModel.NewsItemModel {
Id = newsItem.Id,
- SeName = newsItem.GetSeName(_workContextAccessor.WorkContext.WorkingLanguage.Id),
- Title = newsItem.GetTranslation(x => x.Title, _workContextAccessor.WorkContext.WorkingLanguage.Id),
- Short = newsItem.GetTranslation(x => x.Short, _workContextAccessor.WorkContext.WorkingLanguage.Id),
- Full = newsItem.GetTranslation(x => x.Full, _workContextAccessor.WorkContext.WorkingLanguage.Id),
- CreatedOn = _dateTimeService.ConvertToUserTime(newsItem.StartDateUtc ?? newsItem.CreatedOnUtc,
- DateTimeKind.Utc)
+ SeName = newsItem.GetSeName(WorkingLanguageId),
+ Title = newsItem.GetTranslation(x => x.Title, WorkingLanguageId),
+ Short = newsItem.GetTranslation(x => x.Short, WorkingLanguageId),
+ Full = newsItem.GetTranslation(x => x.Full, WorkingLanguageId),
+ CreatedOn = _dateTimeService.ConvertToUserTime(newsItem.StartDateUtc ?? newsItem.CreatedOnUtc, DateTimeKind.Utc)
};
//prepare picture model
if (string.IsNullOrEmpty(newsItem.PictureId)) return model;
diff --git a/src/Web/Grand.Web/Features/Handlers/Orders/GetMerchandiseReturnDetailsHandler.cs b/src/Web/Grand.Web/Features/Handlers/Orders/GetMerchandiseReturnDetailsHandler.cs
index 6281dfdf8..1fbe541cc 100644
--- a/src/Web/Grand.Web/Features/Handlers/Orders/GetMerchandiseReturnDetailsHandler.cs
+++ b/src/Web/Grand.Web/Features/Handlers/Orders/GetMerchandiseReturnDetailsHandler.cs
@@ -22,13 +22,13 @@ public class
private readonly OrderSettings _orderSettings;
private readonly IPriceFormatter _priceFormatter;
private readonly IProductService _productService;
- private readonly IWorkContextAccessor _workContextAccessor;
+ private readonly IContextAccessor _contextAccessor;
public GetMerchandiseReturnDetailsHandler(
IProductService productService,
IMerchandiseReturnService merchandiseReturnService,
IPriceFormatter priceFormatter,
- IWorkContextAccessor workContextAccessor,
+ IContextAccessor contextAccessor,
IMediator mediator,
IDateTimeService dateTimeService,
OrderSettings orderSettings)
@@ -36,7 +36,7 @@ public class
_productService = productService;
_merchandiseReturnService = merchandiseReturnService;
_priceFormatter = priceFormatter;
- _workContextAccessor = workContextAccessor;
+ _contextAccessor = contextAccessor;
_mediator = mediator;
_dateTimeService = dateTimeService;
_orderSettings = orderSettings;
@@ -84,8 +84,8 @@ public class
Quantity = item.Quantity,
ReasonForReturn = item.ReasonForReturn,
RequestedAction = item.RequestedAction,
- ProductName = product.GetTranslation(x => x.Name, _workContextAccessor.WorkContext.WorkingLanguage.Id),
- ProductSeName = product.GetSeName(_workContextAccessor.WorkContext.WorkingLanguage.Id),
+ ProductName = product.GetTranslation(x => x.Name, _contextAccessor.WorkContext.WorkingLanguage.Id),
+ ProductSeName = product.GetSeName(_contextAccessor.WorkContext.WorkingLanguage.Id),
ProductPrice = unitPrice
});
}
diff --git a/src/Web/Grand.Web/Features/Handlers/Orders/GetMerchandiseReturnHandler.cs b/src/Web/Grand.Web/Features/Handlers/Orders/GetMerchandiseReturnHandler.cs
index a5cd2c9fe..91c715952 100644
--- a/src/Web/Grand.Web/Features/Handlers/Orders/GetMerchandiseReturnHandler.cs
+++ b/src/Web/Grand.Web/Features/Handlers/Orders/GetMerchandiseReturnHandler.cs
@@ -29,10 +29,10 @@ public class GetMerchandiseReturnHandler : IRequestHandler<GetMerchandiseReturn,
private readonly IProductService _productService;
private readonly IShipmentService _shipmentService;
private readonly IVendorService _vendorService;
- private readonly IWorkContextAccessor _workContextAccessor;
+ private readonly IContextAccessor _contextAccessor;
public GetMerchandiseReturnHandler(
- IWorkContextAccessor workContextAccessor,
+ IContextAccessor contextAccessor,
IMerchandiseReturnService merchandiseReturnService,
IShipmentService shipmentService,
IProductService productService,
@@ -44,7 +44,7 @@ public class GetMerchandiseReturnHandler : IRequestHandler<GetMerchandiseReturn,
OrderSettings orderSettings,
ICurrencyService currencyService)
{
- _workContextAccessor = workContextAccessor;
+ _contextAccessor = contextAccessor;
_merchandiseReturnService = merchandiseReturnService;
_shipmentService = shipmentService;
_productService = productService;
@@ -87,7 +87,7 @@ public class GetMerchandiseReturnHandler : IRequestHandler<GetMerchandiseReturn,
foreach (var rrr in await _merchandiseReturnService.GetAllMerchandiseReturnReasons())
reasons.Add(new MerchandiseReturnModel.MerchandiseReturnReasonModel {
Id = rrr.Id,
- Name = rrr.GetTranslation(x => x.Name, _workContextAccessor.WorkContext.WorkingLanguage.Id)
+ Name = rrr.GetTranslation(x => x.Name, _contextAccessor.WorkContext.WorkingLanguage.Id)
});
return reasons;
}
@@ -98,7 +98,7 @@ public class GetMerchandiseReturnHandler : IRequestHandler<GetMerchandiseReturn,
foreach (var rra in await _merchandiseReturnService.GetAllMerchandiseReturnActions())
actions.Add(new MerchandiseReturnModel.MerchandiseReturnActionModel {
Id = rra.Id,
- Name = rra.GetTranslation(x => x.Name, _workContextAccessor.WorkContext.WorkingLanguage.Id)
+ Name = rra.GetTranslation(x => x.Name, _contextAccessor.WorkContext.WorkingLanguage.Id)
});
return actions;
}
@@ -123,8 +123,8 @@ public class GetMerchandiseReturnHandler : IRequestHandler<GetMerchandiseReturn,
var orderItemModel = new MerchandiseReturnModel.OrderItemModel {
Id = orderItem.Id,
ProductId = orderItem.ProductId,
- ProductName = product.GetTranslation(x => x.Name, _workContextAccessor.WorkContext.WorkingLanguage.Id),
- ProductSeName = product.GetSeName(_workContextAccessor.WorkContext.WorkingLanguage.Id),
+ ProductName = product.GetTranslation(x => x.Name, _contextAccessor.WorkContext.WorkingLanguage.Id),
+ ProductSeName = product.GetSeName(_contextAccessor.WorkContext.WorkingLanguage.Id),
AttributeInfo = orderItem.AttributeDescription,
VendorId = orderItem.VendorId,
VendorName = string.IsNullOrEmpty(orderItem.VendorId)
@@ -147,7 +147,7 @@ public class GetMerchandiseReturnHandler : IRequestHandler<GetMerchandiseReturn,
{
//existing addresses
var addresses = new List<Address>();
- foreach (var item in _workContextAccessor.WorkContext.CurrentCustomer.Addresses)
+ foreach (var item in _contextAccessor.WorkContext.CurrentCustomer.Addresses)
{
if (string.IsNullOrEmpty(item.CountryId))
{
@@ -181,7 +181,7 @@ public class GetMerchandiseReturnHandler : IRequestHandler<GetMerchandiseReturn,
ExcludeProperties = false,
LoadCountries = () => countries,
PrePopulateWithCustomerFields = true,
- Customer = _workContextAccessor.WorkContext.CurrentCustomer
+ Customer = _contextAccessor.WorkContext.CurrentCustomer
});
}
}
\ No newline at end of file
diff --git a/src/Web/Grand.Web/Features/Handlers/Pages/GetPageBlockHandler.cs b/src/Web/Grand.Web/Features/Handlers/Pages/GetPageBlockHandler.cs
index cc22de436..44ea87f6c 100644
--- a/src/Web/Grand.Web/Features/Handlers/Pages/GetPageBlockHandler.cs
+++ b/src/Web/Grand.Web/Features/Handlers/Pages/GetPageBlockHandler.cs
@@ -16,16 +16,16 @@ public class GetPageBlockHandler : IRequestHandler<GetPageBlock, PageModel>
private readonly IAclService _aclService;
private readonly IDateTimeService _dateTimeService;
private readonly IPageService _pageService;
- private readonly IWorkContextAccessor _workContextAccessor;
+ private readonly IContextAccessor _contextAccessor;
public GetPageBlockHandler(
IPageService pageService,
- IWorkContextAccessor workContextAccessor,
+ IContextAccessor contextAccessor,
IAclService aclService,
IDateTimeService dateTimeService)
{
_pageService = pageService;
- _workContextAccessor = workContextAccessor;
+ _contextAccessor = contextAccessor;
_aclService = aclService;
_dateTimeService = dateTimeService;
}
@@ -34,7 +34,7 @@ public class GetPageBlockHandler : IRequestHandler<GetPageBlock, PageModel>
{
//load by store
var page = string.IsNullOrEmpty(request.PageId)
- ? await _pageService.GetPageBySystemName(request.SystemName, _workContextAccessor.WorkContext.CurrentStore.Id)
+ ? await _pageService.GetPageBySystemName(request.SystemName, _contextAccessor.StoreContext.CurrentStore.Id)
: await _pageService.GetPageById(request.PageId);
if (page is not { Published: true })
@@ -45,9 +45,9 @@ public class GetPageBlockHandler : IRequestHandler<GetPageBlock, PageModel>
return null;
//ACL (access control list)
- return !_aclService.Authorize(page, _workContextAccessor.WorkContext.CurrentCustomer)
+ return !_aclService.Authorize(page, _contextAccessor.WorkContext.CurrentCustomer)
? null
- : ToModel(page, _workContextAccessor.WorkContext.WorkingLanguage, request.Password);
+ : ToModel(page, _contextAccessor.WorkContext.WorkingLanguage, request.Password);
}
private PageModel ToModel(Page entity, Language language,
diff --git a/src/Web/Grand.Web/Features/Handlers/Products/GetProductDetailsPageHandler.cs b/src/Web/Grand.Web/Features/Handlers/Products/GetProductDetailsPageHandler.cs
index d1885931e..64579c7e9 100644
--- a/src/Web/Grand.Web/Features/Handlers/Products/GetProductDetailsPageHandler.cs
+++ b/src/Web/Grand.Web/Features/Handlers/Products/GetProductDetailsPageHandler.cs
@@ -71,11 +71,11 @@ public class GetProductDetailsPageHandler : IRequestHandler<GetProductDetailsPag
private readonly IVendorService _vendorService;
private readonly VendorSettings _vendorSettings;
private readonly IWarehouseService _warehouseService;
- private readonly IWorkContextAccessor _workContextAccessor;
+ private readonly IContextAccessor _contextAccessor;
public GetProductDetailsPageHandler(
IPermissionService permissionService,
- IWorkContextAccessor workContextAccessor,
+ IContextAccessor contextAccessor,
ITranslationService translationService,
IProductService productService,
IPricingService priceCalculationService,
@@ -107,7 +107,7 @@ public class GetProductDetailsPageHandler : IRequestHandler<GetProductDetailsPag
ShoppingCartSettings shoppingCartSettings)
{
_permissionService = permissionService;
- _workContextAccessor = workContextAccessor;
+ _contextAccessor = contextAccessor;
_translationService = translationService;
_productService = productService;
_pricingService = priceCalculationService;
@@ -191,7 +191,7 @@ public class GetProductDetailsPageHandler : IRequestHandler<GetProductDetailsPag
product.BackorderModeId == BackorderMode.NoBackorders &&
product.AllowOutOfStockSubscriptions &&
_stockQuantityService.GetTotalStockQuantity(product,
- warehouseId: _workContextAccessor.WorkContext.CurrentStore.DefaultWarehouseId) <= 0)
+ warehouseId: _contextAccessor.StoreContext.CurrentStore.DefaultWarehouseId) <= 0)
//out of stock
model.DisplayOutOfStockSubscription = true;
@@ -254,7 +254,7 @@ public class GetProductDetailsPageHandler : IRequestHandler<GetProductDetailsPag
#region Product specifications
model.ProductSpecifications = await _mediator.Send(new GetProductSpecification {
- Language = _workContextAccessor.WorkContext.WorkingLanguage,
+ Language = _contextAccessor.WorkContext.WorkingLanguage,
Product = product
});
@@ -264,8 +264,8 @@ public class GetProductDetailsPageHandler : IRequestHandler<GetProductDetailsPag
model.ProductReviewOverview = await _mediator.Send(new GetProductReviewOverview {
Product = product,
- Language = _workContextAccessor.WorkContext.WorkingLanguage,
- Store = _workContextAccessor.WorkContext.CurrentStore
+ Language = _contextAccessor.WorkContext.WorkingLanguage,
+ Store = _contextAccessor.StoreContext.CurrentStore
});
#endregion
@@ -281,16 +281,16 @@ public class GetProductDetailsPageHandler : IRequestHandler<GetProductDetailsPag
var collectionsCacheKey = string.Format(CacheKeyConst.PRODUCT_COLLECTIONS_MODEL_KEY,
product.Id,
- _workContextAccessor.WorkContext.WorkingLanguage.Id,
- string.Join(",", _workContextAccessor.WorkContext.CurrentCustomer.GetCustomerGroupIds()),
- _workContextAccessor.WorkContext.CurrentStore.Id);
+ _contextAccessor.WorkContext.WorkingLanguage.Id,
+ string.Join(",", _contextAccessor.WorkContext.CurrentCustomer.GetCustomerGroupIds()),
+ _contextAccessor.StoreContext.CurrentStore.Id);
model.ProductCollections = await _cacheBase.GetAsync(collectionsCacheKey, async () =>
{
var listCollection = new List<CollectionModel>();
foreach (var item in product.ProductCollections.OrderBy(x => x.DisplayOrder))
{
var collect =
- (await _collectionService.GetCollectionById(item.CollectionId)).ToModel(_workContextAccessor.WorkContext.WorkingLanguage);
+ (await _collectionService.GetCollectionById(item.CollectionId)).ToModel(_contextAccessor.WorkContext.WorkingLanguage);
listCollection.Add(collect);
}
@@ -306,7 +306,7 @@ public class GetProductDetailsPageHandler : IRequestHandler<GetProductDetailsPag
if (!isAssociatedProduct)
{
var associatedProducts =
- await _productService.GetAssociatedProducts(product.Id, _workContextAccessor.WorkContext.CurrentStore.Id);
+ await _productService.GetAssociatedProducts(product.Id, _contextAccessor.StoreContext.CurrentStore.Id);
foreach (var associatedProduct in associatedProducts)
model.AssociatedProducts.Add(
await PrepareProductDetailsModel(store, associatedProduct, null, true));
@@ -352,19 +352,19 @@ public class GetProductDetailsPageHandler : IRequestHandler<GetProductDetailsPag
var warehouseId = updateCartItem != null
? updateCartItem.WarehouseId
- : _workContextAccessor.WorkContext.CurrentStore.DefaultWarehouseId;
+ : _contextAccessor.StoreContext.CurrentStore.DefaultWarehouseId;
var model = new ProductDetailsModel {
Id = product.Id,
ProductType = product.ProductTypeId,
- Name = product.GetTranslation(x => x.Name, _workContextAccessor.WorkContext.WorkingLanguage.Id),
- ShortDescription = product.GetTranslation(x => x.ShortDescription, _workContextAccessor.WorkContext.WorkingLanguage.Id),
- FullDescription = product.GetTranslation(x => x.FullDescription, _workContextAccessor.WorkContext.WorkingLanguage.Id),
+ Name = product.GetTranslation(x => x.Name, _contextAccessor.WorkContext.WorkingLanguage.Id),
+ ShortDescription = product.GetTranslation(x => x.ShortDescription, _contextAccessor.WorkContext.WorkingLanguage.Id),
+ FullDescription = product.GetTranslation(x => x.FullDescription, _contextAccessor.WorkContext.WorkingLanguage.Id),
Flag = product.Flag,
- MetaKeywords = product.GetTranslation(x => x.MetaKeywords, _workContextAccessor.WorkContext.WorkingLanguage.Id),
- MetaDescription = product.GetTranslation(x => x.MetaDescription, _workContextAccessor.WorkContext.WorkingLanguage.Id),
- MetaTitle = product.GetTranslation(x => x.MetaTitle, _workContextAccessor.WorkContext.WorkingLanguage.Id),
- SeName = product.GetSeName(_workContextAccessor.WorkContext.WorkingLanguage.Id),
+ MetaKeywords = product.GetTranslation(x => x.MetaKeywords, _contextAccessor.WorkContext.WorkingLanguage.Id),
+ MetaDescription = product.GetTranslation(x => x.MetaDescription, _contextAccessor.WorkContext.WorkingLanguage.Id),
+ MetaTitle = product.GetTranslation(x => x.MetaTitle, _contextAccessor.WorkContext.WorkingLanguage.Id),
+ SeName = product.GetSeName(_contextAccessor.WorkContext.WorkingLanguage.Id),
ShowSku = _catalogSettings.ShowSkuOnProductDetailsPage,
Sku = product.Sku,
ShowMpn = _catalogSettings.ShowMpn,
@@ -425,7 +425,7 @@ public class GetProductDetailsPageHandler : IRequestHandler<GetProductDetailsPag
if (deliveryDate != null)
{
model.DeliveryDate =
- deliveryDate.GetTranslation(dd => dd.Name, _workContextAccessor.WorkContext.WorkingLanguage.Id);
+ deliveryDate.GetTranslation(dd => dd.Name, _contextAccessor.WorkContext.WorkingLanguage.Id);
model.DeliveryColorSquaresRgb = deliveryDate.ColorSquaresRgb;
}
}
@@ -434,7 +434,7 @@ public class GetProductDetailsPageHandler : IRequestHandler<GetProductDetailsPag
//additional shipping charge
if (model.AdditionalShippingCharge > 0)
model.AdditionalShippingChargeStr = _priceFormatter.FormatPrice(
- (await _taxService.GetShippingPrice(model.AdditionalShippingCharge, _workContextAccessor.WorkContext.CurrentCustomer))
+ (await _taxService.GetShippingPrice(model.AdditionalShippingCharge, _contextAccessor.WorkContext.CurrentCustomer))
.shippingPrice);
//ask question us on the product
@@ -443,7 +443,7 @@ public class GetProductDetailsPageHandler : IRequestHandler<GetProductDetailsPag
//store name
model.CurrentStoreName =
- _workContextAccessor.WorkContext.CurrentStore.GetTranslation(x => x.Name, _workContextAccessor.WorkContext.WorkingLanguage.Id);
+ _contextAccessor.StoreContext.CurrentStore.GetTranslation(x => x.Name, _contextAccessor.WorkContext.WorkingLanguage.Id);
return model;
@@ -459,7 +459,7 @@ public class GetProductDetailsPageHandler : IRequestHandler<GetProductDetailsPag
private async Task<ProductAskQuestionSimpleModel> PrepareProductAskQuestionSimpleModel(Product product)
{
- var customer = _workContextAccessor.WorkContext.CurrentCustomer;
+ var customer = _contextAccessor.WorkContext.CurrentCustomer;
var model = new ProductAskQuestionSimpleModel {
Id = product.Id,
@@ -479,8 +479,8 @@ public class GetProductDetailsPageHandler : IRequestHandler<GetProductDetailsPag
if (brand is { Published: true })
return new BrandBriefInfoModel {
Id = brand.Id,
- Name = brand.GetTranslation(x => x.Name, _workContextAccessor.WorkContext.WorkingLanguage.Id),
- SeName = brand.GetSeName(_workContextAccessor.WorkContext.WorkingLanguage.Id)
+ Name = brand.GetTranslation(x => x.Name, _contextAccessor.WorkContext.WorkingLanguage.Id),
+ SeName = brand.GetSeName(_contextAccessor.WorkContext.WorkingLanguage.Id)
};
return null;
@@ -493,8 +493,8 @@ public class GetProductDetailsPageHandler : IRequestHandler<GetProductDetailsPag
if (vendor is { Deleted: false, Active: true })
return new VendorBriefInfoModel {
Id = vendor.Id,
- Name = vendor.GetTranslation(x => x.Name, _workContextAccessor.WorkContext.WorkingLanguage.Id),
- SeName = vendor.GetSeName(_workContextAccessor.WorkContext.WorkingLanguage.Id)
+ Name = vendor.GetTranslation(x => x.Name, _contextAccessor.WorkContext.WorkingLanguage.Id),
+ SeName = vendor.GetSeName(_contextAccessor.WorkContext.WorkingLanguage.Id)
};
return null;
@@ -504,16 +504,16 @@ public class GetProductDetailsPageHandler : IRequestHandler<GetProductDetailsPag
{
var breadcrumbCacheKey = string.Format(CacheKeyConst.PRODUCT_BREADCRUMB_MODEL_KEY,
product.Id,
- _workContextAccessor.WorkContext.WorkingLanguage.Id,
- string.Join(",", _workContextAccessor.WorkContext.CurrentCustomer.GetCustomerGroupIds()),
- _workContextAccessor.WorkContext.CurrentStore.Id);
+ _contextAccessor.WorkContext.WorkingLanguage.Id,
+ string.Join(",", _contextAccessor.WorkContext.CurrentCustomer.GetCustomerGroupIds()),
+ _contextAccessor.StoreContext.CurrentStore.Id);
return await _cacheBase.GetAsync(breadcrumbCacheKey, async () =>
{
var breadcrumbModel = new ProductDetailsModel.ProductBreadcrumbModel {
Enabled = _catalogSettings.CategoryBreadcrumbEnabled,
ProductId = product.Id,
- ProductName = product.GetTranslation(x => x.Name, _workContextAccessor.WorkContext.WorkingLanguage.Id),
- ProductSeName = product.GetSeName(_workContextAccessor.WorkContext.WorkingLanguage.Id)
+ ProductName = product.GetTranslation(x => x.Name, _contextAccessor.WorkContext.WorkingLanguage.Id),
+ ProductSeName = product.GetSeName(_contextAccessor.WorkContext.WorkingLanguage.Id)
};
var productCategories = product.ProductCategories;
if (!productCategories.Any()) return breadcrumbModel;
@@ -525,8 +525,8 @@ public class GetProductDetailsPageHandler : IRequestHandler<GetProductDetailsPag
foreach (var catBr in await _categoryService.GetCategoryBreadCrumb(category))
breadcrumbModel.CategoryBreadcrumb.Add(new CategorySimpleModel {
Id = catBr.Id,
- Name = catBr.GetTranslation(x => x.Name, _workContextAccessor.WorkContext.WorkingLanguage.Id),
- SeName = catBr.GetSeName(_workContextAccessor.WorkContext.WorkingLanguage.Id),
+ Name = catBr.GetTranslation(x => x.Name, _contextAccessor.WorkContext.WorkingLanguage.Id),
+ SeName = catBr.GetSeName(_contextAccessor.WorkContext.WorkingLanguage.Id),
IncludeInMenu = catBr.IncludeInMenu
});
@@ -538,7 +538,7 @@ public class GetProductDetailsPageHandler : IRequestHandler<GetProductDetailsPag
private async Task<IList<ProductTagModel>> PrepareProductTagModel(Product product)
{
var productTagsCacheKey = string.Format(CacheKeyConst.PRODUCTTAG_BY_PRODUCT_MODEL_KEY, product.Id,
- _workContextAccessor.WorkContext.WorkingLanguage.Id, _workContextAccessor.WorkContext.CurrentStore.Id);
+ _contextAccessor.WorkContext.WorkingLanguage.Id, _contextAccessor.StoreContext.CurrentStore.Id);
return await _cacheBase.GetAsync(productTagsCacheKey, async () =>
{
var tags = new List<ProductTagModel>();
@@ -548,7 +548,7 @@ public class GetProductDetailsPageHandler : IRequestHandler<GetProductDetailsPag
if (tag != null)
tags.Add(new ProductTagModel {
Id = tag.Id,
- Name = tag.GetTranslation(y => y.Name, _workContextAccessor.WorkContext.WorkingLanguage.Id),
+ Name = tag.GetTranslation(y => y.Name, _contextAccessor.WorkContext.WorkingLanguage.Id),
SeName = tag.SeName,
ProductCount = tag.Count
});
@@ -579,15 +579,15 @@ public class GetProductDetailsPageHandler : IRequestHandler<GetProductDetailsPag
Title =
picture != null &&
!string.IsNullOrEmpty(
- picture.GetTranslation(x => x.TitleAttribute, _workContextAccessor.WorkContext.WorkingLanguage.Id))
- ? picture.GetTranslation(x => x.TitleAttribute, _workContextAccessor.WorkContext.WorkingLanguage.Id)
+ picture.GetTranslation(x => x.TitleAttribute, _contextAccessor.WorkContext.WorkingLanguage.Id))
+ ? picture.GetTranslation(x => x.TitleAttribute, _contextAccessor.WorkContext.WorkingLanguage.Id)
: string.Format(_translationService.GetResource("Media.Product.ImageLinkTitleFormat.Details"),
name),
//"alt" attribute
AlternateText =
picture != null &&
- !string.IsNullOrEmpty(picture.GetTranslation(x => x.AltAttribute, _workContextAccessor.WorkContext.WorkingLanguage.Id))
- ? picture.GetTranslation(x => x.AltAttribute, _workContextAccessor.WorkContext.WorkingLanguage.Id)
+ !string.IsNullOrEmpty(picture.GetTranslation(x => x.AltAttribute, _contextAccessor.WorkContext.WorkingLanguage.Id))
+ ? picture.GetTranslation(x => x.AltAttribute, _contextAccessor.WorkContext.WorkingLanguage.Id)
: string.Format(
_translationService.GetResource("Media.Product.ImageAlternateTextFormat.Details"), name)
};
@@ -611,16 +611,16 @@ public class GetProductDetailsPageHandler : IRequestHandler<GetProductDetailsPag
//"title" attribute
Title =
!string.IsNullOrEmpty(picture.GetTranslation(x => x.TitleAttribute,
- _workContextAccessor.WorkContext.WorkingLanguage.Id))
- ? picture.GetTranslation(x => x.TitleAttribute, _workContextAccessor.WorkContext.WorkingLanguage.Id)
+ _contextAccessor.WorkContext.WorkingLanguage.Id))
+ ? picture.GetTranslation(x => x.TitleAttribute, _contextAccessor.WorkContext.WorkingLanguage.Id)
: string.Format(
_translationService.GetResource("Media.Product.ImageLinkTitleFormat.Details"),
name),
//"alt" attribute
AlternateText =
!string.IsNullOrEmpty(picture.GetTranslation(x => x.AltAttribute,
- _workContextAccessor.WorkContext.WorkingLanguage.Id))
- ? picture.GetTranslation(x => x.AltAttribute, _workContextAccessor.WorkContext.WorkingLanguage.Id)
+ _contextAccessor.WorkContext.WorkingLanguage.Id))
+ ? picture.GetTranslation(x => x.AltAttribute, _contextAccessor.WorkContext.WorkingLanguage.Id)
: string.Format(
_translationService.GetResource("Media.Product.ImageAlternateTextFormat.Details"),
name)
@@ -653,17 +653,17 @@ public class GetProductDetailsPageHandler : IRequestHandler<GetProductDetailsPag
var oldproductprice = await _taxService.GetProductPrice(product, product.OldPrice);
var oldPriceBase = oldproductprice.productprice;
var finalPriceWithoutDiscount = (await _taxService.GetProductPrice(product,
- (await _pricingService.GetFinalPrice(product, _workContextAccessor.WorkContext.CurrentCustomer,
- _workContextAccessor.WorkContext.CurrentStore,
- _workContextAccessor.WorkContext.WorkingCurrency, includeDiscounts: false)).finalPrice)).productprice;
+ (await _pricingService.GetFinalPrice(product, _contextAccessor.WorkContext.CurrentCustomer,
+ _contextAccessor.StoreContext.CurrentStore,
+ _contextAccessor.WorkContext.WorkingCurrency, includeDiscounts: false)).finalPrice)).productprice;
- var appliedPrice = await _pricingService.GetFinalPrice(product, _workContextAccessor.WorkContext.CurrentCustomer,
- _workContextAccessor.WorkContext.CurrentStore, _workContextAccessor.WorkContext.WorkingCurrency, includeDiscounts: true);
+ var appliedPrice = await _pricingService.GetFinalPrice(product, _contextAccessor.WorkContext.CurrentCustomer,
+ _contextAccessor.StoreContext.CurrentStore, _contextAccessor.WorkContext.WorkingCurrency, includeDiscounts: true);
var finalPriceWithDiscount =
(await _taxService.GetProductPrice(product, appliedPrice.finalPrice)).productprice;
var oldPrice =
await _currencyService.ConvertFromPrimaryStoreCurrency(oldPriceBase,
- _workContextAccessor.WorkContext.WorkingCurrency);
+ _contextAccessor.WorkContext.WorkingCurrency);
if (finalPriceWithoutDiscount != oldPrice && oldPrice > 0)
model.OldPrice = _priceFormatter.FormatPrice(oldPrice);
@@ -678,7 +678,7 @@ public class GetProductDetailsPageHandler : IRequestHandler<GetProductDetailsPag
{
var catalogPrice =
await _currencyService.ConvertFromPrimaryStoreCurrency(product.CatalogPrice,
- _workContextAccessor.WorkContext.WorkingCurrency);
+ _contextAccessor.WorkContext.WorkingCurrency);
model.CatalogPrice = _priceFormatter.FormatPrice(catalogPrice);
}
@@ -689,12 +689,12 @@ public class GetProductDetailsPageHandler : IRequestHandler<GetProductDetailsPag
if (product.BasepriceEnabled)
model.BasePricePAngV = await _mediator.Send(new GetFormatBasePrice {
- Currency = _workContextAccessor.WorkContext.WorkingCurrency, Product = product,
+ Currency = _contextAccessor.WorkContext.WorkingCurrency, Product = product,
ProductPrice = finalPriceWithDiscount
});
//currency code
- model.CurrencyCode = _workContextAccessor.WorkContext.WorkingCurrency.CurrencyCode;
+ model.CurrencyCode = _contextAccessor.WorkContext.WorkingCurrency.CurrencyCode;
//reservation
if (product.ProductTypeId == ProductType.Reservation)
@@ -711,13 +711,13 @@ public class GetProductDetailsPageHandler : IRequestHandler<GetProductDetailsPag
model.IsAuction = true;
var highestBid =
await _currencyService.ConvertFromPrimaryStoreCurrency(product.HighestBid,
- _workContextAccessor.WorkContext.WorkingCurrency);
+ _contextAccessor.WorkContext.WorkingCurrency);
model.HighestBid = _priceFormatter.FormatPrice(highestBid);
model.HighestBidValue = highestBid;
model.DisableBuyButton = product.DisableBuyButton;
var startPrice =
await _currencyService.ConvertFromPrimaryStoreCurrency(product.StartPrice,
- _workContextAccessor.WorkContext.WorkingCurrency);
+ _contextAccessor.WorkContext.WorkingCurrency);
model.StartPrice = _priceFormatter.FormatPrice(startPrice);
model.StartPriceValue = startPrice;
}
@@ -791,10 +791,10 @@ public class GetProductDetailsPageHandler : IRequestHandler<GetProductDetailsPag
if (!model.EnteredPrice) return model;
var minimumCustomerEnteredPrice =
await _currencyService.ConvertFromPrimaryStoreCurrency(product.MinEnteredPrice,
- _workContextAccessor.WorkContext.WorkingCurrency);
+ _contextAccessor.WorkContext.WorkingCurrency);
var maximumCustomerEnteredPrice =
await _currencyService.ConvertFromPrimaryStoreCurrency(product.MaxEnteredPrice,
- _workContextAccessor.WorkContext.WorkingCurrency);
+ _contextAccessor.WorkContext.WorkingCurrency);
model.CustomerEnteredPrice = updatecartitem is { EnteredPrice: not null }
? updatecartitem.EnteredPrice.Value
@@ -819,8 +819,8 @@ public class GetProductDetailsPageHandler : IRequestHandler<GetProductDetailsPag
if (updatecartitem == null)
{
- model.SenderName = _workContextAccessor.WorkContext.CurrentCustomer.GetFullName();
- model.SenderEmail = _workContextAccessor.WorkContext.CurrentCustomer.Email;
+ model.SenderName = _contextAccessor.WorkContext.CurrentCustomer.GetFullName();
+ model.SenderEmail = _contextAccessor.WorkContext.CurrentCustomer.Email;
}
else
{
@@ -858,8 +858,8 @@ public class GetProductDetailsPageHandler : IRequestHandler<GetProductDetailsPag
Id = attribute.Id,
ProductId = product.Id,
ProductAttributeId = attribute.ProductAttributeId,
- Name = productAttribute.GetTranslation(x => x.Name, _workContextAccessor.WorkContext.WorkingLanguage.Id),
- Description = productAttribute.GetTranslation(x => x.Description, _workContextAccessor.WorkContext.WorkingLanguage.Id),
+ Name = productAttribute.GetTranslation(x => x.Name, _contextAccessor.WorkContext.WorkingLanguage.Id),
+ Description = productAttribute.GetTranslation(x => x.Description, _contextAccessor.WorkContext.WorkingLanguage.Id),
TextPrompt = attribute.TextPrompt,
IsRequired = attribute.IsRequired,
AttributeControlType = attribute.AttributeControlTypeId,
@@ -898,7 +898,7 @@ public class GetProductDetailsPageHandler : IRequestHandler<GetProductDetailsPag
var valueModel = new ProductDetailsModel.ProductAttributeValueModel {
Id = attributeValue.Id,
- Name = attributeValue.GetTranslation(x => x.Name, _workContextAccessor.WorkContext.WorkingLanguage.Id),
+ Name = attributeValue.GetTranslation(x => x.Name, _contextAccessor.WorkContext.WorkingLanguage.Id),
ColorSquaresRgb = attributeValue.ColorSquaresRgb, //used with "Color squares" attribute type
IsPreSelected = preselected,
StockAvailability = stockAvailability
@@ -918,12 +918,12 @@ public class GetProductDetailsPageHandler : IRequestHandler<GetProductDetailsPag
case > 0:
valueModel.PriceAdjustment =
"+" + _priceFormatter.FormatPrice(productprice.productprice,
- _workContextAccessor.WorkContext.WorkingCurrency);
+ _contextAccessor.WorkContext.WorkingCurrency);
break;
case < 0:
valueModel.PriceAdjustment =
"-" + _priceFormatter.FormatPrice(-productprice.productprice,
- _workContextAccessor.WorkContext.WorkingCurrency);
+ _contextAccessor.WorkContext.WorkingCurrency);
break;
}
@@ -1045,18 +1045,18 @@ public class GetProductDetailsPageHandler : IRequestHandler<GetProductDetailsPag
{
var model = new List<ProductDetailsModel.TierPriceModel>();
foreach (var tierPrice in product.TierPrices.OrderBy(x => x.Quantity)
- .FilterByStore(_workContextAccessor.WorkContext.CurrentStore.Id)
- .FilterByCurrency(_workContextAccessor.WorkContext.WorkingCurrency.CurrencyCode)
- .FilterForCustomer(_workContextAccessor.WorkContext.CurrentCustomer)
+ .FilterByStore(_contextAccessor.StoreContext.CurrentStore.Id)
+ .FilterByCurrency(_contextAccessor.WorkContext.WorkingCurrency.CurrencyCode)
+ .FilterForCustomer(_contextAccessor.WorkContext.CurrentCustomer)
.FilterByDate()
.RemoveDuplicatedQuantities())
{
var tier = new ProductDetailsModel.TierPriceModel();
var priceBase = await _taxService.GetProductPrice(product, (await _pricingService.GetFinalPrice(product,
- _workContextAccessor.WorkContext.CurrentCustomer, _workContextAccessor.WorkContext.CurrentStore, _workContextAccessor.WorkContext.WorkingCurrency,
+ _contextAccessor.WorkContext.CurrentCustomer, _contextAccessor.StoreContext.CurrentStore, _contextAccessor.WorkContext.WorkingCurrency,
0, _catalogSettings.DisplayTierPricesWithDiscounts, tierPrice.Quantity)).finalPrice);
tier.Quantity = tierPrice.Quantity;
- tier.Price = _priceFormatter.FormatPrice(priceBase.productprice, _workContextAccessor.WorkContext.WorkingCurrency);
+ tier.Price = _priceFormatter.FormatPrice(priceBase.productprice, _contextAccessor.WorkContext.WorkingCurrency);
model.Add(tier);
}
@@ -1077,7 +1077,7 @@ public class GetProductDetailsPageHandler : IRequestHandler<GetProductDetailsPag
{
var reservations =
await _productReservationService.GetProductReservationsByProductId(product.Id, true, null);
- var inCart = _workContextAccessor.WorkContext.CurrentCustomer.ShoppingCartItems
+ var inCart = _contextAccessor.WorkContext.CurrentCustomer.ShoppingCartItems
.Where(x => !string.IsNullOrEmpty(x.ReservationId)).ToList();
foreach (var cartItem in inCart)
{
@@ -1120,9 +1120,9 @@ public class GetProductDetailsPageHandler : IRequestHandler<GetProductDetailsPag
var bundleProduct = new ProductDetailsModel.ProductBundleModel {
ProductId = p1.Id,
- Name = p1.GetTranslation(x => x.Name, _workContextAccessor.WorkContext.WorkingLanguage.Id),
- ShortDescription = p1.GetTranslation(x => x.ShortDescription, _workContextAccessor.WorkContext.WorkingLanguage.Id),
- SeName = p1.GetSeName(_workContextAccessor.WorkContext.WorkingLanguage.Id),
+ Name = p1.GetTranslation(x => x.Name, _contextAccessor.WorkContext.WorkingLanguage.Id),
+ ShortDescription = p1.GetTranslation(x => x.ShortDescription, _contextAccessor.WorkContext.WorkingLanguage.Id),
+ SeName = p1.GetSeName(_contextAccessor.WorkContext.WorkingLanguage.Id),
Sku = p1.Sku,
Mpn = p1.Mpn,
Gtin = p1.Gtin,
@@ -1132,8 +1132,8 @@ public class GetProductDetailsPageHandler : IRequestHandler<GetProductDetailsPag
if (displayPrices)
{
var productprice = await _taxService.GetProductPrice(p1,
- (await _pricingService.GetFinalPrice(p1, _workContextAccessor.WorkContext.CurrentCustomer, _workContextAccessor.WorkContext.CurrentStore,
- _workContextAccessor.WorkContext.WorkingCurrency, includeDiscounts: true)).finalPrice);
+ (await _pricingService.GetFinalPrice(p1, _contextAccessor.WorkContext.CurrentCustomer, _contextAccessor.StoreContext.CurrentStore,
+ _contextAccessor.WorkContext.WorkingCurrency, includeDiscounts: true)).finalPrice);
bundleProduct.Price = _priceFormatter.FormatPrice(productprice.productprice);
bundleProduct.PriceValue = productprice.productprice;
}
diff --git a/src/Web/Grand.Web/Features/Handlers/Products/GetProductOverviewHandler.cs b/src/Web/Grand.Web/Features/Handlers/Products/GetProductOverviewHandler.cs
index 364330f54..824c1e4a2 100644
--- a/src/Web/Grand.Web/Features/Handlers/Products/GetProductOverviewHandler.cs
+++ b/src/Web/Grand.Web/Features/Handlers/Products/GetProductOverviewHandler.cs
@@ -35,11 +35,11 @@ public class GetProductOverviewHandler : IRequestHandler<GetProductOverview, IEn
private readonly IPricingService _pricingService;
private readonly IProductService _productService;
private readonly ITaxService _taxService;
- private readonly IWorkContextAccessor _workContextAccessor;
+ private readonly IContextAccessor _contextAccessor;
public GetProductOverviewHandler(
IPermissionService permissionService,
- IWorkContextAccessor workContextAccessor,
+ IContextAccessor contextAccessor,
IProductService productService,
IBrandService brandService,
IPricingService priceCalculationService,
@@ -54,7 +54,7 @@ public class GetProductOverviewHandler : IRequestHandler<GetProductOverview, IEn
CatalogSettings catalogSettings)
{
_permissionService = permissionService;
- _workContextAccessor = workContextAccessor;
+ _contextAccessor = contextAccessor;
_productService = productService;
_brandService = brandService;
_pricingService = priceCalculationService;
@@ -76,13 +76,13 @@ public class GetProductOverviewHandler : IRequestHandler<GetProductOverview, IEn
throw new ArgumentNullException(nameof(request.Products));
var displayPrices =
- await _permissionService.Authorize(StandardPermission.DisplayPrices, _workContextAccessor.WorkContext.CurrentCustomer);
+ await _permissionService.Authorize(StandardPermission.DisplayPrices, _contextAccessor.WorkContext.CurrentCustomer);
var enableShoppingCart =
- await _permissionService.Authorize(StandardPermission.EnableShoppingCart, _workContextAccessor.WorkContext.CurrentCustomer);
+ await _permissionService.Authorize(StandardPermission.EnableShoppingCart, _contextAccessor.WorkContext.CurrentCustomer);
var enableWishlist =
- await _permissionService.Authorize(StandardPermission.EnableWishlist, _workContextAccessor.WorkContext.CurrentCustomer);
+ await _permissionService.Authorize(StandardPermission.EnableWishlist, _contextAccessor.WorkContext.CurrentCustomer);
var pictureSize = request.ProductThumbPictureSize ?? _mediaSettings.ProductThumbPictureSize;
- var priceIncludesTax = _workContextAccessor.WorkContext.TaxDisplayType == TaxDisplayType.IncludingTax;
+ var priceIncludesTax = _contextAccessor.WorkContext.TaxDisplayType == TaxDisplayType.IncludingTax;
var tasks = new List<Task<ProductOverviewModel>>();
@@ -115,26 +115,26 @@ public class GetProductOverviewHandler : IRequestHandler<GetProductOverview, IEn
//specs
if (request.PrepareSpecificationAttributes && product.ProductSpecificationAttributes.Any())
model.SpecificationAttributeModels = await _mediator.Send(new GetProductSpecification
- { Language = _workContextAccessor.WorkContext.WorkingLanguage, Product = product });
+ { Language = _contextAccessor.WorkContext.WorkingLanguage, Product = product });
//attributes
model.ProductAttributeModels = await PrepareAttributesModel(product);
//reviews
model.ReviewOverviewModel = await _mediator.Send(new GetProductReviewOverview
- { Product = product, Language = _workContextAccessor.WorkContext.WorkingLanguage, Store = _workContextAccessor.WorkContext.CurrentStore });
+ { Product = product, Language = _contextAccessor.WorkContext.WorkingLanguage, Store = _contextAccessor.StoreContext.CurrentStore });
return model;
}
private async Task<ProductOverviewModel> PrepareProductOverviewModel(Product product)
{
- var sename = product.GetSeName(_workContextAccessor.WorkContext.WorkingLanguage.Id);
+ var sename = product.GetSeName(_contextAccessor.WorkContext.WorkingLanguage.Id);
var model = new ProductOverviewModel {
Id = product.Id,
- Name = product.GetTranslation(x => x.Name, _workContextAccessor.WorkContext.WorkingLanguage.Id),
- ShortDescription = product.GetTranslation(x => x.ShortDescription, _workContextAccessor.WorkContext.WorkingLanguage.Id),
- FullDescription = product.GetTranslation(x => x.FullDescription, _workContextAccessor.WorkContext.WorkingLanguage.Id),
+ Name = product.GetTranslation(x => x.Name, _contextAccessor.WorkContext.WorkingLanguage.Id),
+ ShortDescription = product.GetTranslation(x => x.ShortDescription, _contextAccessor.WorkContext.WorkingLanguage.Id),
+ FullDescription = product.GetTranslation(x => x.FullDescription, _contextAccessor.WorkContext.WorkingLanguage.Id),
SeName = sename,
Url = _linkGenerator.GetPathByRouteValues("Product", new { SeName = sename }),
ProductType = product.ProductTypeId,
@@ -145,11 +145,11 @@ public class GetProductOverviewHandler : IRequestHandler<GetProductOverview, IEn
BrandName = string.IsNullOrEmpty(product.BrandId)
? ""
: (await _brandService.GetBrandById(product.BrandId))?.GetTranslation(x => x.Name,
- _workContextAccessor.WorkContext.WorkingLanguage.Id),
+ _contextAccessor.WorkContext.WorkingLanguage.Id),
IsFreeShipping = product.IsFreeShipping,
LowStock = product.LowStock,
ShowSku = _catalogSettings.ShowSkuOnCatalogPages,
- TaxDisplayType = _workContextAccessor.WorkContext.TaxDisplayType,
+ TaxDisplayType = _contextAccessor.WorkContext.TaxDisplayType,
Interval = product.Interval,
IntervalUnitId = product.IntervalUnitId,
EndTime = product.AvailableEndDateTimeUtc,
@@ -185,7 +185,7 @@ public class GetProductOverviewHandler : IRequestHandler<GetProductOverview, IEn
#region Grouped product
var associatedProducts =
- await _productService.GetAssociatedProducts(product.Id, _workContextAccessor.WorkContext.CurrentStore.Id);
+ await _productService.GetAssociatedProducts(product.Id, _contextAccessor.StoreContext.CurrentStore.Id);
//add to cart button (ignore "DisableBuyButton" property for grouped products)
priceModel.DisableBuyButton = !enableShoppingCart || !displayPrices;
@@ -202,8 +202,8 @@ public class GetProductOverviewHandler : IRequestHandler<GetProductOverview, IEn
{
var catalogPrice =
await _currencyService.ConvertFromPrimaryStoreCurrency(product.CatalogPrice,
- _workContextAccessor.WorkContext.WorkingCurrency);
- priceModel.CatalogPrice = _priceFormatter.FormatPrice(catalogPrice, _workContextAccessor.WorkContext.WorkingCurrency);
+ _contextAccessor.WorkContext.WorkingCurrency);
+ priceModel.CatalogPrice = _priceFormatter.FormatPrice(catalogPrice, _contextAccessor.WorkContext.WorkingCurrency);
}
if (associatedProducts.Any())
@@ -220,7 +220,7 @@ public class GetProductOverviewHandler : IRequestHandler<GetProductOverview, IEn
{
//calculate for the maximum quantity (in case if we have tier prices)
var tmpPrice = (await _pricingService.GetFinalPrice(associatedProduct,
- _workContextAccessor.WorkContext.CurrentCustomer, _workContextAccessor.WorkContext.CurrentStore, _workContextAccessor.WorkContext.WorkingCurrency,
+ _contextAccessor.WorkContext.CurrentCustomer, _contextAccessor.StoreContext.CurrentStore, _contextAccessor.WorkContext.WorkingCurrency,
0, true,
int.MaxValue)).finalPrice;
if (minPossiblePrice.HasValue && !(tmpPrice < minPossiblePrice.Value)) continue;
@@ -240,18 +240,18 @@ public class GetProductOverviewHandler : IRequestHandler<GetProductOverview, IEn
//calculate prices
var finalPrice = (await _taxService.GetProductPrice(minPriceProduct,
minPossiblePrice.Value, priceIncludesTax,
- _workContextAccessor.WorkContext.CurrentCustomer))
+ _contextAccessor.WorkContext.CurrentCustomer))
.productprice;
priceModel.OldPrice = null;
priceModel.Price =
- _priceFormatter.FormatPrice(finalPrice, _workContextAccessor.WorkContext.WorkingCurrency);
+ _priceFormatter.FormatPrice(finalPrice, _contextAccessor.WorkContext.WorkingCurrency);
priceModel.PriceValue = finalPrice;
//PAngV base price (used in Germany)
if (product.BasepriceEnabled)
priceModel.BasePricePAngV = await _mediator.Send(new GetFormatBasePrice {
- Currency = _workContextAccessor.WorkContext.WorkingCurrency, Product = product,
+ Currency = _contextAccessor.WorkContext.WorkingCurrency, Product = product,
ProductPrice = finalPrice
});
}
@@ -298,8 +298,8 @@ public class GetProductOverviewHandler : IRequestHandler<GetProductOverview, IEn
{
var catalogPrice =
await _currencyService.ConvertFromPrimaryStoreCurrency(product.CatalogPrice,
- _workContextAccessor.WorkContext.WorkingCurrency);
- priceModel.CatalogPrice = _priceFormatter.FormatPrice(catalogPrice, _workContextAccessor.WorkContext.WorkingCurrency);
+ _contextAccessor.WorkContext.WorkingCurrency);
+ priceModel.CatalogPrice = _priceFormatter.FormatPrice(catalogPrice, _contextAccessor.WorkContext.WorkingCurrency);
}
//start price for product auction
@@ -307,8 +307,8 @@ public class GetProductOverviewHandler : IRequestHandler<GetProductOverview, IEn
{
var startPrice =
await _currencyService.ConvertFromPrimaryStoreCurrency(product.StartPrice,
- _workContextAccessor.WorkContext.WorkingCurrency);
- priceModel.StartPrice = _priceFormatter.FormatPrice(startPrice, _workContextAccessor.WorkContext.WorkingCurrency);
+ _contextAccessor.WorkContext.WorkingCurrency);
+ priceModel.StartPrice = _priceFormatter.FormatPrice(startPrice, _contextAccessor.WorkContext.WorkingCurrency);
priceModel.StartPriceValue = startPrice;
}
@@ -317,8 +317,8 @@ public class GetProductOverviewHandler : IRequestHandler<GetProductOverview, IEn
{
var highestBid =
await _currencyService.ConvertFromPrimaryStoreCurrency(product.HighestBid,
- _workContextAccessor.WorkContext.WorkingCurrency);
- priceModel.HighestBid = _priceFormatter.FormatPrice(highestBid, _workContextAccessor.WorkContext.WorkingCurrency);
+ _contextAccessor.WorkContext.WorkingCurrency);
+ priceModel.HighestBid = _priceFormatter.FormatPrice(highestBid, _contextAccessor.WorkContext.WorkingCurrency);
priceModel.HighestBidValue = highestBid;
}
@@ -339,7 +339,7 @@ public class GetProductOverviewHandler : IRequestHandler<GetProductOverview, IEn
//calculate for the maximum quantity (in case if we have tier prices)
var infoPrice = await _pricingService.GetFinalPrice(product,
- _workContextAccessor.WorkContext.CurrentCustomer, _workContextAccessor.WorkContext.CurrentStore, _workContextAccessor.WorkContext.WorkingCurrency,
+ _contextAccessor.WorkContext.CurrentCustomer, _contextAccessor.StoreContext.CurrentStore, _contextAccessor.WorkContext.WorkingCurrency,
0, true, int.MaxValue);
priceModel.AppliedDiscounts = infoPrice.appliedDiscounts;
@@ -348,21 +348,21 @@ public class GetProductOverviewHandler : IRequestHandler<GetProductOverview, IEn
var minPossiblePrice = infoPrice.finalPrice;
var oldPriceBase = (await _taxService.GetProductPrice(product, product.OldPrice,
- priceIncludesTax, _workContextAccessor.WorkContext.CurrentCustomer)).productprice;
+ priceIncludesTax, _contextAccessor.WorkContext.CurrentCustomer)).productprice;
var finalPrice = (await _taxService.GetProductPrice(product, minPossiblePrice,
- priceIncludesTax, _workContextAccessor.WorkContext.CurrentCustomer)).productprice;
+ priceIncludesTax, _contextAccessor.WorkContext.CurrentCustomer)).productprice;
var oldPrice =
await _currencyService.ConvertFromPrimaryStoreCurrency(oldPriceBase,
- _workContextAccessor.WorkContext.WorkingCurrency);
+ _contextAccessor.WorkContext.WorkingCurrency);
//do we have tier prices configured?
var tierPrices = new List<TierPrice>();
if (product.TierPrices.Any())
tierPrices.AddRange(product.TierPrices.OrderBy(tp => tp.Quantity)
- .FilterByStore(_workContextAccessor.WorkContext.CurrentStore.Id)
- .FilterByCurrency(_workContextAccessor.WorkContext.WorkingCurrency.CurrencyCode)
- .FilterForCustomer(_workContextAccessor.WorkContext.CurrentCustomer)
+ .FilterByStore(_contextAccessor.StoreContext.CurrentStore.Id)
+ .FilterByCurrency(_contextAccessor.WorkContext.WorkingCurrency.CurrencyCode)
+ .FilterForCustomer(_contextAccessor.WorkContext.CurrentCustomer)
.FilterByDate()
.RemoveDuplicatedQuantities());
@@ -374,7 +374,7 @@ public class GetProductOverviewHandler : IRequestHandler<GetProductOverview, IEn
{
priceModel.OldPrice = null;
priceModel.Price =
- _priceFormatter.FormatPrice(finalPrice, _workContextAccessor.WorkContext.WorkingCurrency);
+ _priceFormatter.FormatPrice(finalPrice, _contextAccessor.WorkContext.WorkingCurrency);
priceModel.PriceValue = finalPrice;
}
else
@@ -382,17 +382,17 @@ public class GetProductOverviewHandler : IRequestHandler<GetProductOverview, IEn
if (!finalPrice.Equals(oldPriceBase) && oldPriceBase != 0)
{
priceModel.OldPrice =
- _priceFormatter.FormatPrice(oldPrice, _workContextAccessor.WorkContext.WorkingCurrency);
+ _priceFormatter.FormatPrice(oldPrice, _contextAccessor.WorkContext.WorkingCurrency);
priceModel.OldPriceValue = oldPrice;
priceModel.Price =
- _priceFormatter.FormatPrice(finalPrice, _workContextAccessor.WorkContext.WorkingCurrency);
+ _priceFormatter.FormatPrice(finalPrice, _contextAccessor.WorkContext.WorkingCurrency);
priceModel.PriceValue = finalPrice;
}
else
{
priceModel.OldPrice = null;
priceModel.Price =
- _priceFormatter.FormatPrice(finalPrice, _workContextAccessor.WorkContext.WorkingCurrency);
+ _priceFormatter.FormatPrice(finalPrice, _contextAccessor.WorkContext.WorkingCurrency);
priceModel.PriceValue = finalPrice;
}
}
@@ -400,7 +400,7 @@ public class GetProductOverviewHandler : IRequestHandler<GetProductOverview, IEn
//PAngV base price (used in Germany)
if (product.BasepriceEnabled)
priceModel.BasePricePAngV = await _mediator.Send(new GetFormatBasePrice {
- Currency = _workContextAccessor.WorkContext.WorkingCurrency, Product = product,
+ Currency = _contextAccessor.WorkContext.WorkingCurrency, Product = product,
ProductPrice = finalPrice
});
}
@@ -445,15 +445,15 @@ public class GetProductOverviewHandler : IRequestHandler<GetProductOverview, IEn
//"title" attribute
Title =
picture != null && !string.IsNullOrEmpty(picture.GetTranslation(x => x.TitleAttribute,
- _workContextAccessor.WorkContext.WorkingLanguage.Id))
- ? picture.GetTranslation(x => x.TitleAttribute, _workContextAccessor.WorkContext.WorkingLanguage.Id)
+ _contextAccessor.WorkContext.WorkingLanguage.Id))
+ ? picture.GetTranslation(x => x.TitleAttribute, _contextAccessor.WorkContext.WorkingLanguage.Id)
: name,
//"alt" attribute
AlternateText =
picture != null &&
!string.IsNullOrEmpty(picture.GetTranslation(x => x.AltAttribute,
- _workContextAccessor.WorkContext.WorkingLanguage.Id))
- ? picture.GetTranslation(x => x.AltAttribute, _workContextAccessor.WorkContext.WorkingLanguage.Id)
+ _contextAccessor.WorkContext.WorkingLanguage.Id))
+ ? picture.GetTranslation(x => x.AltAttribute, _contextAccessor.WorkContext.WorkingLanguage.Id)
: name
};
@@ -492,7 +492,7 @@ public class GetProductOverviewHandler : IRequestHandler<GetProductOverview, IEn
if (pa == null) continue;
var productAttributeModel = new ProductOverviewModel.ProductAttributeModel {
- Name = pa.GetTranslation(x => x.Name, _workContextAccessor.WorkContext.WorkingLanguage.Id),
+ Name = pa.GetTranslation(x => x.Name, _contextAccessor.WorkContext.WorkingLanguage.Id),
SeName = pa.SeName,
TextPrompt = attribute.TextPrompt,
IsRequired = attribute.IsRequired,
diff --git a/src/Web/Grand.Web/Features/Handlers/Vendors/GetVendorReviewsHandler.cs b/src/Web/Grand.Web/Features/Handlers/Vendors/GetVendorReviewsHandler.cs
index 1c3eccb89..f2932f438 100644
--- a/src/Web/Grand.Web/Features/Handlers/Vendors/GetVendorReviewsHandler.cs
+++ b/src/Web/Grand.Web/Features/Handlers/Vendors/GetVendorReviewsHandler.cs
@@ -20,10 +20,10 @@ public class GetVendorReviewsHandler : IRequestHandler<GetVendorReviews, VendorR
private readonly IGroupService _groupService;
private readonly IVendorService _vendorService;
private readonly VendorSettings _vendorSettings;
- private readonly IWorkContextAccessor _workContextAccessor;
+ private readonly IContextAccessor _contextAccessor;
public GetVendorReviewsHandler(
- IWorkContextAccessor workContextAccessor,
+ IContextAccessor contextAccessor,
IVendorService vendorService,
ICustomerService customerService,
IDateTimeService dateTimeService,
@@ -32,7 +32,7 @@ public class GetVendorReviewsHandler : IRequestHandler<GetVendorReviews, VendorR
VendorSettings vendorSettings,
CaptchaSettings captchaSettings)
{
- _workContextAccessor = workContextAccessor;
+ _contextAccessor = contextAccessor;
_vendorService = vendorService;
_customerService = customerService;
_dateTimeService = dateTimeService;
@@ -49,8 +49,8 @@ public class GetVendorReviewsHandler : IRequestHandler<GetVendorReviews, VendorR
var model = new VendorReviewsModel {
VendorId = request.Vendor.Id,
- VendorName = request.Vendor.GetTranslation(x => x.Name, _workContextAccessor.WorkContext.WorkingLanguage.Id),
- VendorSeName = request.Vendor.GetSeName(_workContextAccessor.WorkContext.WorkingLanguage.Id)
+ VendorName = request.Vendor.GetTranslation(x => x.Name, _contextAccessor.WorkContext.WorkingLanguage.Id),
+ VendorSeName = request.Vendor.GetSeName(_contextAccessor.WorkContext.WorkingLanguage.Id)
};
var vendorReviews = await _vendorService.GetAllVendorReviews("", true, null, null, "", request.Vendor.Id, 0,
@@ -77,7 +77,7 @@ public class GetVendorReviewsHandler : IRequestHandler<GetVendorReviews, VendorR
}
model.AddVendorReview.CanCurrentCustomerLeaveReview = _vendorSettings.AllowAnonymousUsersToReviewVendor ||
- !await _groupService.IsGuest(_workContextAccessor.WorkContext.CurrentCustomer);
+ !await _groupService.IsGuest(_contextAccessor.WorkContext.CurrentCustomer);
model.AddVendorReview.DisplayCaptcha = _captchaSettings.Enabled && _captchaSettings.ShowOnVendorReviewPage;
return model;
diff --git a/src/Web/Grand.Web/Validators/Blogs/AddBlogCommentValidator.cs b/src/Web/Grand.Web/Validators/Blogs/AddBlogCommentValidator.cs
index e5ef90a24..9c34a5634 100644
--- a/src/Web/Grand.Web/Validators/Blogs/AddBlogCommentValidator.cs
+++ b/src/Web/Grand.Web/Validators/Blogs/AddBlogCommentValidator.cs
@@ -19,10 +19,10 @@ public class AddBlogCommentValidator : BaseGrandValidator<AddBlogCommentModel>
public AddBlogCommentValidator(
IEnumerable<IValidatorConsumer<AddBlogCommentModel>> validators,
IEnumerable<IValidatorConsumer<ICaptchaValidModel>> validatorsCaptcha,
- CaptchaSettings captchaSettings, IHttpContextAccessor contextAccessor,
+ CaptchaSettings captchaSettings, IHttpContextAccessor httpcontextAccessor,
GoogleReCaptchaValidator googleReCaptchaValidator,
BlogSettings blogSettings,
- IGroupService groupService, IWorkContextAccessor workContextAccessor, IBlogService blogService, IAclService aclService,
+ IGroupService groupService, IContextAccessor contextAccessor, IBlogService blogService, IAclService aclService,
ITranslationService translationService)
: base(validators)
{
@@ -31,7 +31,7 @@ public class AddBlogCommentValidator : BaseGrandValidator<AddBlogCommentModel>
RuleFor(x => x).CustomAsync(async (x, context, _) =>
{
- if (await groupService.IsGuest(workContextAccessor.WorkContext.CurrentCustomer) &&
+ if (await groupService.IsGuest(contextAccessor.WorkContext.CurrentCustomer) &&
!blogSettings.AllowNotRegisteredUsersToLeaveComments)
context.AddFailure(
translationService.GetResource("Blog.Comments.OnlyRegisteredUsersLeaveComments"));
@@ -44,7 +44,7 @@ public class AddBlogCommentValidator : BaseGrandValidator<AddBlogCommentModel>
if (blogPost is not { AllowComments: true })
context.AddFailure(translationService.GetResource("Blog.Comments.NotAllowed"));
- if (!aclService.Authorize(blogPost, workContextAccessor.WorkContext.CurrentStore.Id))
+ if (!aclService.Authorize(blogPost, contextAccessor.StoreContext.CurrentStore.Id))
context.AddFailure(translationService.GetResource("Blog.Comments.NotAllowed"));
if (blogPost == null ||
@@ -57,7 +57,7 @@ public class AddBlogCommentValidator : BaseGrandValidator<AddBlogCommentModel>
{
RuleFor(x => x.Captcha).NotNull().WithMessage(translationService.GetResource("Account.Captcha.Required"));
RuleFor(x => x.Captcha)
- .SetValidator(new CaptchaValidator(validatorsCaptcha, contextAccessor, googleReCaptchaValidator));
+ .SetValidator(new CaptchaValidator(validatorsCaptcha, httpcontextAccessor, googleReCaptchaValidator));
}
}
}
\ No newline at end of file
diff --git a/src/Web/Grand.Web/Validators/Catalog/ProductEmailAFriendValidator.cs b/src/Web/Grand.Web/Validators/Catalog/ProductEmailAFriendValidator.cs
index eb335dd9f..991d231fc 100644
--- a/src/Web/Grand.Web/Validators/Catalog/ProductEmailAFriendValidator.cs
+++ b/src/Web/Grand.Web/Validators/Catalog/ProductEmailAFriendValidator.cs
@@ -19,8 +19,8 @@ public class ProductEmailAFriendValidator : BaseGrandValidator<ProductEmailAFrie
IEnumerable<IValidatorConsumer<ProductEmailAFriendModel>> validators,
IEnumerable<IValidatorConsumer<ICaptchaValidModel>> validatorsCaptcha,
CaptchaSettings captchaSettings, CatalogSettings catalogSettings,
- IWorkContextAccessor workContextAccessor, IGroupService groupService, IProductService productService,
- IHttpContextAccessor contextAccessor, GoogleReCaptchaValidator googleReCaptchaValidator,
+ IContextAccessor contextAccessor, IGroupService groupService, IProductService productService,
+ IHttpContextAccessor httpcontextAccessor, GoogleReCaptchaValidator googleReCaptchaValidator,
ITranslationService translationService)
: base(validators)
{
@@ -37,7 +37,7 @@ public class ProductEmailAFriendValidator : BaseGrandValidator<ProductEmailAFrie
{
RuleFor(x => x.Captcha).NotNull().WithMessage(translationService.GetResource("Account.Captcha.Required"));
RuleFor(x => x.Captcha)
- .SetValidator(new CaptchaValidator(validatorsCaptcha, contextAccessor, googleReCaptchaValidator));
+ .SetValidator(new CaptchaValidator(validatorsCaptcha, httpcontextAccessor, googleReCaptchaValidator));
}
RuleFor(x => x).CustomAsync(async (x, context, _) =>
@@ -46,7 +46,7 @@ public class ProductEmailAFriendValidator : BaseGrandValidator<ProductEmailAFrie
if (product is not { Published: true } || !catalogSettings.EmailAFriendEnabled)
context.AddFailure("Product is disabled");
- if (await groupService.IsGuest(workContextAccessor.WorkContext.CurrentCustomer) &&
+ if (await groupService.IsGuest(contextAccessor.WorkContext.CurrentCustomer) &&
!catalogSettings.AllowAnonymousUsersToEmailAFriend)
context.AddFailure(translationService.GetResource("Products.EmailAFriend.OnlyRegisteredUsers"));
});
diff --git a/src/Web/Grand.Web/Validators/Catalog/ProductReviewsValidator.cs b/src/Web/Grand.Web/Validators/Catalog/ProductReviewsValidator.cs
index 38a26361b..f1559d171 100644
--- a/src/Web/Grand.Web/Validators/Catalog/ProductReviewsValidator.cs
+++ b/src/Web/Grand.Web/Validators/Catalog/ProductReviewsValidator.cs
@@ -40,8 +40,8 @@ public class ProductReviewsValidator : BaseGrandValidator<ProductReviewsModel>
IOrderService orderService,
IProductReviewService productReviewService,
CaptchaSettings captchaSettings, CatalogSettings catalogSettings,
- IWorkContextAccessor workContextAccessor,
- IHttpContextAccessor contextAccessor, GoogleReCaptchaValidator googleReCaptchaValidator,
+ IContextAccessor contextAccessor,
+ IHttpContextAccessor httpcontextAccessor, GoogleReCaptchaValidator googleReCaptchaValidator,
ITranslationService translationService)
: base(validators)
{
@@ -56,7 +56,7 @@ public class ProductReviewsValidator : BaseGrandValidator<ProductReviewsModel>
{
RuleFor(x => x.Captcha).NotNull().WithMessage(translationService.GetResource("Account.Captcha.Required"));
RuleFor(x => x.Captcha)
- .SetValidator(new CaptchaValidator(validatorsCaptcha, contextAccessor, googleReCaptchaValidator));
+ .SetValidator(new CaptchaValidator(validatorsCaptcha, httpcontextAccessor, googleReCaptchaValidator));
}
RuleFor(x => x).CustomAsync(async (x, context, _) =>
@@ -65,18 +65,18 @@ public class ProductReviewsValidator : BaseGrandValidator<ProductReviewsModel>
if (product is not { Published: true } || !product.AllowCustomerReviews)
context.AddFailure("Product is disabled");
- if (await groupService.IsGuest(workContextAccessor.WorkContext.CurrentCustomer) &&
+ if (await groupService.IsGuest(contextAccessor.WorkContext.CurrentCustomer) &&
!catalogSettings.AllowAnonymousUsersToReviewProduct)
context.AddFailure(translationService.GetResource("Reviews.OnlyRegisteredUsersCanWriteReviews"));
if (catalogSettings.ProductReviewPossibleOnlyAfterPurchasing &&
- !(await orderService.SearchOrders(customerId: workContextAccessor.WorkContext.CurrentCustomer.Id, productId: x.ProductId,
+ !(await orderService.SearchOrders(customerId: contextAccessor.WorkContext.CurrentCustomer.Id, productId: x.ProductId,
os: (int)OrderStatusSystem.Complete)).Any())
context.AddFailure(translationService.GetResource("Reviews.ProductReviewPossibleOnlyAfterPurchasing"));
if (catalogSettings.ProductReviewPossibleOnlyOnce)
{
- var reviews = await productReviewService.GetAllProductReviews(workContextAccessor.WorkContext.CurrentCustomer.Id,
+ var reviews = await productReviewService.GetAllProductReviews(contextAccessor.WorkContext.CurrentCustomer.Id,
productId: x.ProductId,
pageSize: 1);
if (reviews.Any())
diff --git a/src/Web/Grand.Web/Validators/Contact/ContactUsValidator.cs b/src/Web/Grand.Web/Validators/Contact/ContactUsValidator.cs
index eae16747d..112360eea 100644
--- a/src/Web/Grand.Web/Validators/Contact/ContactUsValidator.cs
+++ b/src/Web/Grand.Web/Validators/Contact/ContactUsValidator.cs
@@ -19,23 +19,23 @@ public class ContactUsValidator : BaseGrandValidator<ContactUsModel>
private readonly IContactAttributeParser _contactAttributeParser;
private readonly IContactAttributeService _contactAttributeService;
private readonly ITranslationService _translationService;
- private readonly IWorkContextAccessor _workContextAccessor;
+ private readonly IContextAccessor _contextAccessor;
public ContactUsValidator(
IEnumerable<IValidatorConsumer<ContactUsModel>> validators,
IEnumerable<IValidatorConsumer<ICaptchaValidModel>> validatorsCaptcha,
IContactAttributeParser contactAttributeParser,
IContactAttributeService contactAttributeService,
- IWorkContextAccessor workContextAccessor,
+ IContextAccessor contextAccessor,
ITranslationService translationService, CommonSettings commonSettings,
CaptchaSettings captchaSettings,
- IHttpContextAccessor contextAccessor, GoogleReCaptchaValidator googleReCaptchaValidator)
+ IHttpContextAccessor httpcontextAccessor, GoogleReCaptchaValidator googleReCaptchaValidator)
: base(validators)
{
_contactAttributeParser = contactAttributeParser;
_contactAttributeService = contactAttributeService;
_translationService = translationService;
- _workContextAccessor = workContextAccessor;
+ _contextAccessor = contextAccessor;
RuleFor(x => x.Email).NotEmpty().WithMessage(translationService.GetResource("ContactUs.Email.Required"));
RuleFor(x => x.Email).EmailAddress().WithMessage(translationService.GetResource("Common.WrongEmail"));
@@ -53,14 +53,14 @@ public class ContactUsValidator : BaseGrandValidator<ContactUsModel>
RuleFor(x => x.Captcha).NotNull()
.WithMessage(translationService.GetResource("Account.Captcha.Required"));
RuleFor(x => x.Captcha)
- .SetValidator(new CaptchaValidator(validatorsCaptcha, contextAccessor, googleReCaptchaValidator));
+ .SetValidator(new CaptchaValidator(validatorsCaptcha, httpcontextAccessor, googleReCaptchaValidator));
}
RuleFor(x => x).CustomAsync(async (x, context, _) =>
{
var contactAttributeWarnings = await GetContactAttributesWarnings(
x.Attributes.Select(z => new CustomAttribute { Key = z.Key, Value = z.Value }).ToList(),
- workContextAccessor.WorkContext.CurrentStore.Id);
+ contextAccessor.StoreContext.CurrentStore.Id);
if (contactAttributeWarnings.Any())
foreach (var item in contactAttributeWarnings)
context.AddFailure(item);
@@ -99,10 +99,10 @@ public class ContactUsValidator : BaseGrandValidator<ContactUsModel>
//if not found
if (!found)
warnings.Add(
- !string.IsNullOrEmpty(a2.GetTranslation(a => a.TextPrompt, _workContextAccessor.WorkContext.WorkingLanguage.Id))
- ? a2.GetTranslation(a => a.TextPrompt, _workContextAccessor.WorkContext.WorkingLanguage.Id)
+ !string.IsNullOrEmpty(a2.GetTranslation(a => a.TextPrompt, _contextAccessor.WorkContext.WorkingLanguage.Id))
+ ? a2.GetTranslation(a => a.TextPrompt, _contextAccessor.WorkContext.WorkingLanguage.Id)
: string.Format(_translationService.GetResource("ContactUs.SelectAttribute"),
- a2.GetTranslation(a => a.Name, _workContextAccessor.WorkContext.WorkingLanguage.Id)));
+ a2.GetTranslation(a => a.Name, _contextAccessor.WorkContext.WorkingLanguage.Id)));
}
//now validation rules
@@ -124,7 +124,7 @@ public class ContactUsValidator : BaseGrandValidator<ContactUsModel>
if (ca.ValidationMinLength.Value > enteredTextLength)
warnings.Add(string.Format(
_translationService.GetResource("ContactUs.TextboxMinimumLength"),
- ca.GetTranslation(a => a.Name, _workContextAccessor.WorkContext.WorkingLanguage.Id),
+ ca.GetTranslation(a => a.Name, _contextAccessor.WorkContext.WorkingLanguage.Id),
ca.ValidationMinLength.Value));
}
}
@@ -143,7 +143,7 @@ public class ContactUsValidator : BaseGrandValidator<ContactUsModel>
if (ca.ValidationMaxLength.Value < enteredTextLength)
warnings.Add(string.Format(_translationService.GetResource("ContactUs.TextboxMaximumLength"),
- ca.GetTranslation(a => a.Name, _workContextAccessor.WorkContext.WorkingLanguage.Id),
+ ca.GetTranslation(a => a.Name, _contextAccessor.WorkContext.WorkingLanguage.Id),
ca.ValidationMaxLength.Value));
}
}
diff --git a/src/Web/Grand.Web/Validators/Customer/ChangePasswordValidator.cs b/src/Web/Grand.Web/Validators/Customer/ChangePasswordValidator.cs
index 01f05d11a..224b26a40 100644
--- a/src/Web/Grand.Web/Validators/Customer/ChangePasswordValidator.cs
+++ b/src/Web/Grand.Web/Validators/Customer/ChangePasswordValidator.cs
@@ -14,7 +14,7 @@ public class ChangePasswordValidator : BaseGrandValidator<ChangePasswordModel>
{
public ChangePasswordValidator(
IEnumerable<IValidatorConsumer<ChangePasswordModel>> validators,
- ICustomerService customerService, IWorkContextAccessor workContextAccessor, IGroupService groupService,
+ ICustomerService customerService, IContextAccessor contextAccessor, IGroupService groupService,
IEncryptionService encryptionService, ICustomerHistoryPasswordService customerHistoryPasswordService,
ICustomerManagerService customerManagerService,
ITranslationService translationService, CustomerSettings customerSettings)
@@ -38,7 +38,7 @@ public class ChangePasswordValidator : BaseGrandValidator<ChangePasswordModel>
RuleFor(x => x).CustomAsync(async (x, context, _) =>
{
- var customer = await customerService.GetCustomerById(workContextAccessor.WorkContext.CurrentCustomer.Id);
+ var customer = await customerService.GetCustomerById(contextAccessor.WorkContext.CurrentCustomer.Id);
switch (customer)
{
diff --git a/src/Web/Grand.Web/Validators/Customer/CustomerInfoValidator.cs b/src/Web/Grand.Web/Validators/Customer/CustomerInfoValidator.cs
index 391131bb3..685363d53 100644
--- a/src/Web/Grand.Web/Validators/Customer/CustomerInfoValidator.cs
+++ b/src/Web/Grand.Web/Validators/Customer/CustomerInfoValidator.cs
@@ -16,7 +16,7 @@ public class CustomerInfoValidator : BaseGrandValidator<CustomerInfoModel>
{
public CustomerInfoValidator(
IEnumerable<IValidatorConsumer<CustomerInfoModel>> validators,
- IWorkContextAccessor workContextAccessor,
+ IContextAccessor contextAccessor,
ICustomerService customerService,
IMediator mediator, ICustomerAttributeParser customerAttributeParser,
ITranslationService translationService,
@@ -119,7 +119,7 @@ public class CustomerInfoValidator : BaseGrandValidator<CustomerInfoModel>
var customerAttributeWarnings = await customerAttributeParser.GetAttributeWarnings(customerAttributes);
foreach (var error in customerAttributeWarnings) context.AddFailure(error);
- if (workContextAccessor.WorkContext.CurrentCustomer.Email != x.Email.ToLower() && customerSettings.AllowUsersToChangeEmail)
+ if (contextAccessor.WorkContext.CurrentCustomer.Email != x.Email.ToLower() && customerSettings.AllowUsersToChangeEmail)
{
if (!CommonHelper.IsValidEmail(x.Email))
context.AddFailure(
@@ -135,7 +135,7 @@ public class CustomerInfoValidator : BaseGrandValidator<CustomerInfoModel>
}
if (customerSettings.UsernamesEnabled && customerSettings.AllowUsersToChangeUsernames &&
- workContextAccessor.WorkContext.CurrentCustomer.Username != x.Username.ToLower())
+ contextAccessor.WorkContext.CurrentCustomer.Username != x.Username.ToLower())
{
if (x.Username.ToLower().Length > 100)
context.AddFailure(translationService.GetResource("Account.EmailUsernameErrors.UsernameTooLong"));
diff --git a/src/Web/Grand.Web/Validators/Customer/DeleteAccountValidator.cs b/src/Web/Grand.Web/Validators/Customer/DeleteAccountValidator.cs
index 543e0e5bf..9c5b65b60 100644
--- a/src/Web/Grand.Web/Validators/Customer/DeleteAccountValidator.cs
+++ b/src/Web/Grand.Web/Validators/Customer/DeleteAccountValidator.cs
@@ -12,7 +12,7 @@ public class DeleteAccountValidator : BaseGrandValidator<DeleteAccountModel>
{
public DeleteAccountValidator(
IEnumerable<IValidatorConsumer<DeleteAccountModel>> validators,
- IEncryptionService encryptionService, CustomerSettings customerSettings, IWorkContextAccessor workContextAccessor,
+ IEncryptionService encryptionService, CustomerSettings customerSettings, IContextAccessor contextAccessor,
ITranslationService translationService)
: base(validators)
{
@@ -20,16 +20,16 @@ public class DeleteAccountValidator : BaseGrandValidator<DeleteAccountModel>
.WithMessage(translationService.GetResource("Account.DeleteAccount.Fields.Password.Required"));
RuleFor(x => x).Custom((x, context) =>
{
- var pwd = workContextAccessor.WorkContext.CurrentCustomer.PasswordFormatId switch {
+ var pwd = contextAccessor.WorkContext.CurrentCustomer.PasswordFormatId switch {
PasswordFormat.Clear => x.Password,
PasswordFormat.Encrypted => encryptionService.EncryptText(x.Password,
- workContextAccessor.WorkContext.CurrentCustomer.PasswordSalt),
+ contextAccessor.WorkContext.CurrentCustomer.PasswordSalt),
PasswordFormat.Hashed => encryptionService.CreatePasswordHash(x.Password,
- workContextAccessor.WorkContext.CurrentCustomer.PasswordSalt,
+ contextAccessor.WorkContext.CurrentCustomer.PasswordSalt,
customerSettings.HashedPasswordFormat),
_ => throw new Exception("PasswordFormat not supported")
};
- var isValid = pwd == workContextAccessor.WorkContext.CurrentCustomer.Password;
+ var isValid = pwd == contextAccessor.WorkContext.CurrentCustomer.Password;
if (!isValid) context.AddFailure(translationService.GetResource("Account.Login.WrongCredentials"));
});
}
diff --git a/src/Web/Grand.Web/Validators/Customer/RegisterValidator.cs b/src/Web/Grand.Web/Validators/Customer/RegisterValidator.cs
index 2756ca3c6..cb013b0ee 100644
--- a/src/Web/Grand.Web/Validators/Customer/RegisterValidator.cs
+++ b/src/Web/Grand.Web/Validators/Customer/RegisterValidator.cs
@@ -24,10 +24,10 @@ public class RegisterValidator : BaseGrandValidator<RegisterModel>
ITranslationService translationService,
ICountryService countryService,
CustomerSettings customerSettings, CaptchaSettings captchaSettings,
- IHttpContextAccessor contextAccessor, GoogleReCaptchaValidator googleReCaptchaValidator,
+ IHttpContextAccessor httpcontextAccessor, GoogleReCaptchaValidator googleReCaptchaValidator,
IMediator mediator, ICustomerAttributeParser customerAttributeParser,
ICustomerService customerService,
- IGroupService groupService, IWorkContextAccessor workContextAccessor
+ IGroupService groupService, IContextAccessor contextAccessor
)
: base(validators)
{
@@ -125,7 +125,7 @@ public class RegisterValidator : BaseGrandValidator<RegisterModel>
{
RuleFor(x => x.Captcha).NotNull().WithMessage(translationService.GetResource("Account.Captcha.Required"));
RuleFor(x => x.Captcha)
- .SetValidator(new CaptchaValidator(validatorsCaptcha, contextAccessor, googleReCaptchaValidator));
+ .SetValidator(new CaptchaValidator(validatorsCaptcha, httpcontextAccessor, googleReCaptchaValidator));
}
RuleFor(x => x).CustomAsync(async (x, context, _) =>
@@ -135,7 +135,7 @@ public class RegisterValidator : BaseGrandValidator<RegisterModel>
var customerAttributeWarnings = await customerAttributeParser.GetAttributeWarnings(customerAttributes);
foreach (var error in customerAttributeWarnings) context.AddFailure(error);
- if (await groupService.IsRegistered(workContextAccessor.WorkContext.CurrentCustomer))
+ if (await groupService.IsRegistered(contextAccessor.WorkContext.CurrentCustomer))
{
context.AddFailure("Current customer is already registered");
return;
diff --git a/src/Web/Grand.Web/Validators/Customer/SubAccountEditValidator.cs b/src/Web/Grand.Web/Validators/Customer/SubAccountEditValidator.cs
index b08e88b89..674b1b526 100644
--- a/src/Web/Grand.Web/Validators/Customer/SubAccountEditValidator.cs
+++ b/src/Web/Grand.Web/Validators/Customer/SubAccountEditValidator.cs
@@ -16,7 +16,7 @@ public class SubAccountEditValidator : BaseGrandValidator<SubAccountEditModel>
IEnumerable<IValidatorConsumer<SubAccountEditModel>> validators,
ICustomerService customerService, IGroupService groupService,
ITranslationService translationService,
- IWorkContextAccessor workContextAccessor,
+ IContextAccessor contextAccessor,
CustomerSettings customerSettings)
: base(validators)
{
@@ -54,7 +54,7 @@ public class SubAccountEditValidator : BaseGrandValidator<SubAccountEditModel>
break;
}
- if (customer != null && customer.OwnerId != workContextAccessor.WorkContext.CurrentCustomer.Id)
+ if (customer != null && customer.OwnerId != contextAccessor.WorkContext.CurrentCustomer.Id)
context.AddFailure("You are not owner of this account");
if (customer != null && customer.Email != x.Email.ToLower() && customerSettings.AllowUsersToChangeEmail)
diff --git a/src/Web/Grand.Web/Validators/Knowledgebase/KnowledgebaseArticleValidator.cs b/src/Web/Grand.Web/Validators/Knowledgebase/KnowledgebaseArticleValidator.cs
index 37fcee8aa..2a31d674d 100644
--- a/src/Web/Grand.Web/Validators/Knowledgebase/KnowledgebaseArticleValidator.cs
+++ b/src/Web/Grand.Web/Validators/Knowledgebase/KnowledgebaseArticleValidator.cs
@@ -18,10 +18,10 @@ public class KnowledgebaseArticleValidator : BaseGrandValidator<KnowledgebaseArt
public KnowledgebaseArticleValidator(
IEnumerable<IValidatorConsumer<KnowledgebaseArticleModel>> validators,
IEnumerable<IValidatorConsumer<ICaptchaValidModel>> validatorsCaptcha,
- IWorkContextAccessor workContextAccessor, IGroupService groupService,
+ IContextAccessor contextAccessor, IGroupService groupService,
IKnowledgebaseService knowledgebaseService, KnowledgebaseSettings knowledgebaseSettings,
CaptchaSettings captchaSettings,
- IHttpContextAccessor contextAccessor, GoogleReCaptchaValidator googleReCaptchaValidator,
+ IHttpContextAccessor httpcontextAccessor, GoogleReCaptchaValidator googleReCaptchaValidator,
ITranslationService translationService)
: base(validators)
{
@@ -31,7 +31,7 @@ public class KnowledgebaseArticleValidator : BaseGrandValidator<KnowledgebaseArt
RuleFor(x => x).CustomAsync(async (x, context, _) =>
{
- if (await groupService.IsGuest(workContextAccessor.WorkContext.CurrentCustomer) &&
+ if (await groupService.IsGuest(contextAccessor.WorkContext.CurrentCustomer) &&
!knowledgebaseSettings.AllowNotRegisteredUsersToLeaveComments)
context.AddFailure(
translationService.GetResource("Knowledgebase.Article.Comments.OnlyRegisteredUsersLeaveComments"));
@@ -45,7 +45,7 @@ public class KnowledgebaseArticleValidator : BaseGrandValidator<KnowledgebaseArt
RuleFor(x => x.Captcha).NotNull()
.WithMessage(translationService.GetResource("Account.Captcha.Required"));
RuleFor(x => x.Captcha)
- .SetValidator(new CaptchaValidator(validatorsCaptcha, contextAccessor, googleReCaptchaValidator));
+ .SetValidator(new CaptchaValidator(validatorsCaptcha, httpcontextAccessor, googleReCaptchaValidator));
}
}
}
\ No newline at end of file
diff --git a/src/Web/Grand.Web/Validators/News/AddNewsCommentValidator.cs b/src/Web/Grand.Web/Validators/News/AddNewsCommentValidator.cs
index 5cdc612e5..99c71b1b9 100644
--- a/src/Web/Grand.Web/Validators/News/AddNewsCommentValidator.cs
+++ b/src/Web/Grand.Web/Validators/News/AddNewsCommentValidator.cs
@@ -18,9 +18,9 @@ public class AddNewsCommentValidator : BaseGrandValidator<AddNewsCommentModel>
public AddNewsCommentValidator(
IEnumerable<IValidatorConsumer<AddNewsCommentModel>> validators,
IEnumerable<IValidatorConsumer<ICaptchaValidModel>> validatorsCaptcha,
- IWorkContextAccessor workContextAccessor, IGroupService groupService, INewsService newsService,
+ IContextAccessor contextAccessor, IGroupService groupService, INewsService newsService,
CaptchaSettings captchaSettings, NewsSettings newsSettings,
- IHttpContextAccessor contextAccessor, GoogleReCaptchaValidator googleReCaptchaValidator,
+ IHttpContextAccessor httpcontextAccessor, GoogleReCaptchaValidator googleReCaptchaValidator,
ITranslationService translationService)
: base(validators)
{
@@ -32,7 +32,7 @@ public class AddNewsCommentValidator : BaseGrandValidator<AddNewsCommentModel>
.WithMessage(translationService.GetResource("News.Comments.CommentText.Required"));
RuleFor(x => x).CustomAsync(async (x, context, _) =>
{
- if (await groupService.IsGuest(workContextAccessor.WorkContext.CurrentCustomer) &&
+ if (await groupService.IsGuest(contextAccessor.WorkContext.CurrentCustomer) &&
!newsSettings.AllowNotRegisteredUsersToLeaveComments)
context.AddFailure(translationService.GetResource("News.Comments.OnlyRegisteredUsersLeaveComments"));
var newsItem = await newsService.GetNewsById(x.Id);
@@ -44,7 +44,7 @@ public class AddNewsCommentValidator : BaseGrandValidator<AddNewsCommentModel>
RuleFor(x => x.Captcha).NotNull()
.WithMessage(translationService.GetResource("Account.Captcha.Required"));
RuleFor(x => x.Captcha)
- .SetValidator(new CaptchaValidator(validatorsCaptcha, contextAccessor, googleReCaptchaValidator));
+ .SetValidator(new CaptchaValidator(validatorsCaptcha, httpcontextAccessor, googleReCaptchaValidator));
}
}
}
\ No newline at end of file
diff --git a/src/Web/Grand.Web/Validators/ShoppingCart/DiscountCouponValidator.cs b/src/Web/Grand.Web/Validators/ShoppingCart/DiscountCouponValidator.cs
index 8e0348cde..c5ea53c71 100644
--- a/src/Web/Grand.Web/Validators/ShoppingCart/DiscountCouponValidator.cs
+++ b/src/Web/Grand.Web/Validators/ShoppingCart/DiscountCouponValidator.cs
@@ -13,7 +13,7 @@ public class DiscountCouponValidator : BaseGrandValidator<DiscountCouponModel>
public DiscountCouponValidator(
IEnumerable<IValidatorConsumer<DiscountCouponModel>> validators,
IDiscountValidationService discountValidationService,
- IDiscountService discountService, IWorkContextAccessor workContextAccessor,
+ IDiscountService discountService, IContextAccessor contextAccessor,
ITranslationService translationService)
: base(validators)
{
@@ -30,7 +30,7 @@ public class DiscountCouponValidator : BaseGrandValidator<DiscountCouponModel>
if (discount is { RequiresCouponCode: true, IsEnabled: true })
{
var coupons =
- workContextAccessor.WorkContext.CurrentCustomer.ParseAppliedCouponCodes(SystemCustomerFieldNames.DiscountCoupons);
+ contextAccessor.WorkContext.CurrentCustomer.ParseAppliedCouponCodes(SystemCustomerFieldNames.DiscountCoupons);
var existsAndUsed = false;
foreach (var item in coupons)
if (await discountValidationService.ExistsCodeInDiscount(item, discount.Id, null))
@@ -46,7 +46,7 @@ public class DiscountCouponValidator : BaseGrandValidator<DiscountCouponModel>
if (!existsAndUsed)
{
var validationResult = await discountValidationService.ValidateDiscount(discount,
- workContextAccessor.WorkContext.CurrentCustomer, workContextAccessor.WorkContext.CurrentStore, workContextAccessor.WorkContext.WorkingCurrency,
+ contextAccessor.WorkContext.CurrentCustomer, contextAccessor.StoreContext.CurrentStore, contextAccessor.WorkContext.WorkingCurrency,
x.DiscountCouponCode);
if (!validationResult.IsValid)
context.AddFailure(!string.IsNullOrEmpty(validationResult.UserErrorResource)
diff --git a/src/Web/Grand.Web/Validators/ShoppingCart/GiftVoucherCouponValidator.cs b/src/Web/Grand.Web/Validators/ShoppingCart/GiftVoucherCouponValidator.cs
index 8510b606a..96fabda63 100644
--- a/src/Web/Grand.Web/Validators/ShoppingCart/GiftVoucherCouponValidator.cs
+++ b/src/Web/Grand.Web/Validators/ShoppingCart/GiftVoucherCouponValidator.cs
@@ -13,7 +13,7 @@ public class GiftVoucherCouponValidator : BaseGrandValidator<GiftVoucherCouponMo
{
public GiftVoucherCouponValidator(
IEnumerable<IValidatorConsumer<GiftVoucherCouponModel>> validators,
- IMediator mediator, IWorkContextAccessor workContextAccessor,
+ IMediator mediator, IContextAccessor contextAccessor,
ITranslationService translationService)
: base(validators)
{
@@ -31,8 +31,8 @@ public class GiftVoucherCouponValidator : BaseGrandValidator<GiftVoucherCouponMo
new GetGiftVoucherQuery { Code = x.GiftVoucherCouponCode, IsGiftVoucherActivated = true }, _))
.FirstOrDefault();
var isGiftVoucherValid = giftVoucher != null
- && giftVoucher.IsGiftVoucherValid(workContextAccessor.WorkContext.WorkingCurrency,
- workContextAccessor.WorkContext.CurrentStore);
+ && giftVoucher.IsGiftVoucherValid(contextAccessor.WorkContext.WorkingCurrency,
+ contextAccessor.StoreContext.CurrentStore);
if (!isGiftVoucherValid)
context.AddFailure(translationService.GetResource("ShoppingCart.Code.WrongGiftVoucher"));
diff --git a/src/Web/Grand.Web/Validators/ShoppingCart/UpdateQuantityValidator.cs b/src/Web/Grand.Web/Validators/ShoppingCart/UpdateQuantityValidator.cs
index b55c300c5..5d0c48e40 100644
--- a/src/Web/Grand.Web/Validators/ShoppingCart/UpdateQuantityValidator.cs
+++ b/src/Web/Grand.Web/Validators/ShoppingCart/UpdateQuantityValidator.cs
@@ -14,7 +14,7 @@ public class UpdateQuantityValidator : BaseGrandValidator<UpdateQuantityModel>
public UpdateQuantityValidator(
IEnumerable<IValidatorConsumer<UpdateQuantityModel>> validators,
IPermissionService permissionService, ShoppingCartSettings shoppingCartSettings,
- IShoppingCartService shoppingCartService, IWorkContextAccessor workContextAccessor)
+ IShoppingCartService shoppingCartService, IContextAccessor contextAccessor)
: base(validators)
{
RuleFor(x => x.Quantity).GreaterThan(0).WithMessage("Wrong quantity");
@@ -36,7 +36,7 @@ public class UpdateQuantityValidator : BaseGrandValidator<UpdateQuantityModel>
}
}
- var cart = (await shoppingCartService.GetShoppingCart(workContextAccessor.WorkContext.CurrentStore.Id, PrepareCartTypes()))
+ var cart = (await shoppingCartService.GetShoppingCart(contextAccessor.StoreContext.CurrentStore.Id, PrepareCartTypes()))
.FirstOrDefault(z => z.Id == x.ShoppingCartId);
if (cart == null) context.AddFailure("Shopping cart item not found");
});
diff --git a/src/Web/Grand.Web/Validators/ShoppingCart/WishlistEmailAFriendValidator.cs b/src/Web/Grand.Web/Validators/ShoppingCart/WishlistEmailAFriendValidator.cs
index 5bf7eeba8..0c580634c 100644
--- a/src/Web/Grand.Web/Validators/ShoppingCart/WishlistEmailAFriendValidator.cs
+++ b/src/Web/Grand.Web/Validators/ShoppingCart/WishlistEmailAFriendValidator.cs
@@ -17,9 +17,9 @@ public class WishlistEmailAFriendValidator : BaseGrandValidator<WishlistEmailAFr
public WishlistEmailAFriendValidator(
IEnumerable<IValidatorConsumer<WishlistEmailAFriendModel>> validators,
IEnumerable<IValidatorConsumer<ICaptchaValidModel>> validatorsCaptcha,
- IWorkContextAccessor workContextAccessor, IGroupService groupService,
+ IContextAccessor contextAccessor, IGroupService groupService,
CaptchaSettings captchaSettings, ShoppingCartSettings shoppingCartSettings,
- IHttpContextAccessor contextAccessor, GoogleReCaptchaValidator googleReCaptchaValidator,
+ IHttpContextAccessor httpcontextAccessor, GoogleReCaptchaValidator googleReCaptchaValidator,
ITranslationService translationService)
: base(validators)
{
@@ -37,13 +37,13 @@ public class WishlistEmailAFriendValidator : BaseGrandValidator<WishlistEmailAFr
RuleFor(x => x.Captcha).NotNull()
.WithMessage(translationService.GetResource("Account.Captcha.Required"));
RuleFor(x => x.Captcha)
- .SetValidator(new CaptchaValidator(validatorsCaptcha, contextAccessor, googleReCaptchaValidator));
+ .SetValidator(new CaptchaValidator(validatorsCaptcha, httpcontextAccessor, googleReCaptchaValidator));
}
RuleFor(x => x).CustomAsync(async (x, context, _) =>
{
//check whether the current customer is guest and ia allowed to email wishlist
- if (await groupService.IsGuest(workContextAccessor.WorkContext.CurrentCustomer) &&
+ if (await groupService.IsGuest(contextAccessor.WorkContext.CurrentCustomer) &&
!shoppingCartSettings.AllowAnonymousUsersToEmailWishlist)
context.AddFailure(translationService.GetResource("Wishlist.EmailAFriend.OnlyRegisteredUsers"));
});
diff --git a/src/Web/Grand.Web/Validators/Vendors/VendorReviewsValidator.cs b/src/Web/Grand.Web/Validators/Vendors/VendorReviewsValidator.cs
index 6fdb64439..0ae4982a8 100644
--- a/src/Web/Grand.Web/Validators/Vendors/VendorReviewsValidator.cs
+++ b/src/Web/Grand.Web/Validators/Vendors/VendorReviewsValidator.cs
@@ -22,9 +22,9 @@ public class VendorReviewsValidator : BaseGrandValidator<VendorReviewsModel>
IEnumerable<IValidatorConsumer<VendorReviewsModel>> validators,
IEnumerable<IValidatorConsumer<ICaptchaValidModel>> validatorsCaptcha,
IMediator mediator,
- IGroupService groupService, IWorkContextAccessor workContextAccessor, IVendorService vendorService,
+ IGroupService groupService, IContextAccessor contextAccessor, IVendorService vendorService,
CaptchaSettings captchaSettings, VendorSettings vendorSettings,
- IHttpContextAccessor contextAccessor, GoogleReCaptchaValidator googleReCaptchaValidator,
+ IHttpContextAccessor httpcontextAccessor, GoogleReCaptchaValidator googleReCaptchaValidator,
ITranslationService translationService)
: base(validators)
{
@@ -44,13 +44,13 @@ public class VendorReviewsValidator : BaseGrandValidator<VendorReviewsModel>
context.AddFailure(
translationService.GetResource("VendorReviews.VendorNotActiveOrAllowCustomerReviewsDisabled"));
- if (await groupService.IsGuest(workContextAccessor.WorkContext.CurrentCustomer) &&
+ if (await groupService.IsGuest(contextAccessor.WorkContext.CurrentCustomer) &&
!vendorSettings.AllowAnonymousUsersToReviewVendor)
context.AddFailure(translationService.GetResource("VendorReviews.OnlyRegisteredUsersCanWriteReviews"));
//allow reviews only by customer that bought something from this vendor
if (vendorSettings.VendorReviewPossibleOnlyAfterPurchasing &&
!(await mediator.Send(new GetOrderQuery {
- CustomerId = workContextAccessor.WorkContext.CurrentCustomer.Id,
+ CustomerId = contextAccessor.WorkContext.CurrentCustomer.Id,
VendorId = x.VendorId,
Os = (int)OrderStatusSystem.Complete,
PageSize = 1
@@ -61,7 +61,7 @@ public class VendorReviewsValidator : BaseGrandValidator<VendorReviewsModel>
if (vendorSettings.VendorReviewPossibleOnlyOnce)
if ((await vendorService.GetAllVendorReviews(
- workContextAccessor.WorkContext.CurrentCustomer.Id,
+ contextAccessor.WorkContext.CurrentCustomer.Id,
null,
vendorId: vendor.Id,
pageSize: 1)).Any())
@@ -71,7 +71,7 @@ public class VendorReviewsValidator : BaseGrandValidator<VendorReviewsModel>
{
RuleFor(x => x.Captcha).NotNull().WithMessage(translationService.GetResource("Account.Captcha.Required"));
RuleFor(x => x.Captcha)
- .SetValidator(new CaptchaValidator(validatorsCaptcha, contextAccessor, googleReCaptchaValidator));
+ .SetValidator(new CaptchaValidator(validatorsCaptcha, httpcontextAccessor, googleReCaptchaValidator));
}
}
}
\ No newline at end of file
diff --git a/src/Web/Grand.Web/Views/Account/Reviews.cshtml b/src/Web/Grand.Web/Views/Account/Reviews.cshtml
index 01834a01f..88321278d 100644
--- a/src/Web/Grand.Web/Views/Account/Reviews.cshtml
+++ b/src/Web/Grand.Web/Views/Account/Reviews.cshtml
@@ -1,10 +1,10 @@
@model CustomerProductReviewsModel
@inject IPageHeadBuilder pagebuilder
-@inject IWorkContextAccessor workContextAccessor
+@inject IContextAccessor contextAccessor
@{
Layout = "_TwoColumns";
- var supportRtl = workContextAccessor.WorkContext.WorkingLanguage.Rtl;
+ var supportRtl = contextAccessor.WorkContext.WorkingLanguage.Rtl;
//title
pagebuilder.AddTitleParts(Loc["Title.Account"]);
diff --git a/src/Web/Grand.Web/Views/Checkout/Completed.cshtml b/src/Web/Grand.Web/Views/Checkout/Completed.cshtml
index 42b75a38c..8a3114ca7 100644
--- a/src/Web/Grand.Web/Views/Checkout/Completed.cshtml
+++ b/src/Web/Grand.Web/Views/Checkout/Completed.cshtml
@@ -1,4 +1,4 @@
-@inject IWorkContextAccessor workContextAccessor
+@inject IContextAccessor contextAccessor
@model CheckoutCompletedModel
@{
diff --git a/src/Web/Grand.Web/Views/Order/CustomerOrders.cshtml b/src/Web/Grand.Web/Views/Order/CustomerOrders.cshtml
index d08cba07c..6de2efde4 100644
--- a/src/Web/Grand.Web/Views/Order/CustomerOrders.cshtml
+++ b/src/Web/Grand.Web/Views/Order/CustomerOrders.cshtml
@@ -1,10 +1,10 @@
@model CustomerOrderListModel
@inject IPageHeadBuilder pagebuilder
-@inject IWorkContextAccessor workContextAccessor
+@inject IContextAccessor contextAccessor
@{
Layout = "_TwoColumns";
- var supportRtl = workContextAccessor.WorkContext.WorkingLanguage.Rtl;
+ var supportRtl = contextAccessor.WorkContext.WorkingLanguage.Rtl;
//title
pagebuilder.AddTitleParts(Loc["Title.Account"]);
diff --git a/src/Web/Grand.Web/Views/Order/Details.cshtml b/src/Web/Grand.Web/Views/Order/Details.cshtml
index 867a7e44f..1836f2b56 100644
--- a/src/Web/Grand.Web/Views/Order/Details.cshtml
+++ b/src/Web/Grand.Web/Views/Order/Details.cshtml
@@ -1,9 +1,9 @@
@using System.Globalization
@model OrderDetailsModel
@inject IPageHeadBuilder pagebuilder
-@inject IWorkContextAccessor workContextAccessor
+@inject IContextAccessor contextAccessor
@{
- var supportRtl = workContextAccessor.WorkContext.WorkingLanguage.Rtl;
+ var supportRtl = contextAccessor.WorkContext.WorkingLanguage.Rtl;
Layout = "_SingleColumn";
diff --git a/src/Web/Grand.Web/Views/PdfTemplates/ShipmentPdfTemplate.cshtml b/src/Web/Grand.Web/Views/PdfTemplates/ShipmentPdfTemplate.cshtml
index 30ff7550d..7e1f5bc81 100644
--- a/src/Web/Grand.Web/Views/PdfTemplates/ShipmentPdfTemplate.cshtml
+++ b/src/Web/Grand.Web/Views/PdfTemplates/ShipmentPdfTemplate.cshtml
@@ -6,12 +6,12 @@
@inject IOrderService _orderService
@inject IProductService _productService
@inject ICountryService _countryService
-@inject IWorkContextAccessor _workContextAccessor
+@inject IContextAccessor _contextAccessor
@inject ITranslationService _translationService
@{
- var companyName = _workContextAccessor.WorkContext.CurrentStore.CompanyName;
- var limitbyVendor = _workContextAccessor.WorkContext.CurrentVendor != null;
+ var companyName = _contextAccessor.StoreContext.CurrentStore.CompanyName;
+ var limitbyVendor = _contextAccessor.WorkContext.CurrentVendor != null;
}
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
@@ -118,7 +118,7 @@
@foreach (var item in shipment.ShipmentItems)
{
var orderItem = order.OrderItems.FirstOrDefault(x => x.Id == item.OrderItemId);
- if (orderItem != null && (orderItem.VendorId == _workContextAccessor.WorkContext.CurrentVendor?.Id || !limitbyVendor))
+ if (orderItem != null && (orderItem.VendorId == _contextAccessor.WorkContext.CurrentVendor?.Id || !limitbyVendor))
{
<tr>
<td colspan="2">
diff --git a/src/Web/Grand.Web/Views/Product/Partials/Prices.cshtml b/src/Web/Grand.Web/Views/Product/Partials/Prices.cshtml
index 61dba2f01..21bc7e11d 100644
--- a/src/Web/Grand.Web/Views/Product/Partials/Prices.cshtml
+++ b/src/Web/Grand.Web/Views/Product/Partials/Prices.cshtml
@@ -1,6 +1,6 @@
@using System.Globalization
@model ProductDetailsModel.ProductPriceModel
-@inject IWorkContextAccessor workContextAccessor
+@inject IContextAccessor contextAccessor
<div class="prices d-flex justify-content-center align-items-start row px-3 flex-column" itemprop="offers" itemscope itemtype="http://schema.org/Offer">
@if (Model.EnteredPrice)
@@ -13,7 +13,7 @@
<b-button v-b-modal.modal-1>@Loc["Products.CallForPrice"]</b-button>
<b-modal id="modal-1" hide-footer title="@Loc["Products.CallForPrice"]">
<p class="my-4">
- <span>@Loc["Products.CallForPrice"]:</span><a href="tel:@workContextAccessor.WorkContext.CurrentStore.CompanyPhoneNumber"> @workContextAccessor.WorkContext.CurrentStore.CompanyPhoneNumber</a>
+ <span>@Loc["Products.CallForPrice"]:</span><a href="tel:@contextAccessor.StoreContext.CurrentStore.CompanyPhoneNumber"> @contextAccessor.StoreContext.CurrentStore.CompanyPhoneNumber</a>
</p>
</b-modal>
</div>
diff --git a/src/Web/Grand.Web/Views/Shared/Components/Menu/Default.cshtml b/src/Web/Grand.Web/Views/Shared/Components/Menu/Default.cshtml
index bb564e49c..313c9cc45 100644
--- a/src/Web/Grand.Web/Views/Shared/Components/Menu/Default.cshtml
+++ b/src/Web/Grand.Web/Views/Shared/Components/Menu/Default.cshtml
@@ -96,7 +96,15 @@
</ul>
</li>
}
-@if (Model.DisplaySearchMenu | Model.DisplayNewProductsMenu | Model.DisplayCustomerMenu | Model.DisplayBlogMenu | Model.DisplayContactUsMenu)
+
+@functions {
+ private bool ShouldDisplayMenu()
+ {
+ return Model.DisplaySearchMenu || Model.DisplayNewProductsMenu || Model.DisplayCustomerMenu || Model.DisplayBlogMenu || Model.DisplayContactUsMenu;
+ }
+}
+
+@if (ShouldDisplayMenu())
{
@if (Model.NewProductsEnabled && Model.DisplayNewProductsMenu)
{
diff --git a/src/Web/Grand.Web/Views/Shared/Components/SearchBox/Default.cshtml b/src/Web/Grand.Web/Views/Shared/Components/SearchBox/Default.cshtml
index c5f9ca67a..999e33b85 100644
--- a/src/Web/Grand.Web/Views/Shared/Components/SearchBox/Default.cshtml
+++ b/src/Web/Grand.Web/Views/Shared/Components/SearchBox/Default.cshtml
@@ -1,9 +1,9 @@
@using Grand.Domain.Blogs
@model SearchBoxModel
@inject BlogSettings blogSettings
-@inject IWorkContextAccessor workContextAccessor
+@inject IContextAccessor contextAccessor
@{
- var lang = workContextAccessor.WorkContext.WorkingLanguage.LanguageCulture;
+ var lang = contextAccessor.WorkContext.WorkingLanguage.LanguageCulture;
}
<template id="searchBoxContainer">
<a class="modal-close" @@click="$bvModal.hide('search-box')">
diff --git a/src/Web/Grand.Web/Views/Shared/Components/VoiceNavigation/Default.cshtml b/src/Web/Grand.Web/Views/Shared/Components/VoiceNavigation/Default.cshtml
index db3f5485a..4e4c94f39 100644
--- a/src/Web/Grand.Web/Views/Shared/Components/VoiceNavigation/Default.cshtml
+++ b/src/Web/Grand.Web/Views/Shared/Components/VoiceNavigation/Default.cshtml
@@ -1,6 +1,6 @@
-@inject IWorkContextAccessor workContextAccessor
+@inject IContextAccessor contextAccessor
@{
- var lang = workContextAccessor.WorkContext.WorkingLanguage.LanguageCulture;
+ var lang = contextAccessor.WorkContext.WorkingLanguage.LanguageCulture;
}
<template v-if="voicenavigator.allowed">
<button id="voicePageButton"
diff --git a/src/Web/Grand.Web/Views/Shared/Partials/Cookie.cshtml b/src/Web/Grand.Web/Views/Shared/Partials/Cookie.cshtml
index 40fd77dd8..c2b5e0ba0 100644
--- a/src/Web/Grand.Web/Views/Shared/Partials/Cookie.cshtml
+++ b/src/Web/Grand.Web/Views/Shared/Partials/Cookie.cshtml
@@ -1,9 +1,9 @@
@inject StoreInformationSettings storeInformationSettings
-@inject IWorkContextAccessor workContextAccessor
+@inject IContextAccessor contextAccessor
-@if (storeInformationSettings.DisplayCookieInformation && !workContextAccessor.WorkContext.CurrentCustomer.IsSystemAccount)
+@if (storeInformationSettings.DisplayCookieInformation && !contextAccessor.WorkContext.CurrentCustomer.IsSystemAccount)
{
- if (workContextAccessor.WorkContext.CurrentCustomer.GetUserFieldFromEntity<bool>(SystemCustomerFieldNames.CookieAccepted, workContextAccessor.WorkContext.CurrentStore.Id))
+ if (contextAccessor.WorkContext.CurrentCustomer.GetUserFieldFromEntity<bool>(SystemCustomerFieldNames.CookieAccepted, contextAccessor.StoreContext.CurrentStore.Id))
return;
if (TempData["Grand.IgnoreCookieInformation"] != null && Convert.ToBoolean(TempData["Grand.IgnoreCookieInformation"]))
diff --git a/src/Web/Grand.Web/Views/Shared/Partials/Head.cshtml b/src/Web/Grand.Web/Views/Shared/Partials/Head.cshtml
index 2f5a399b0..d0a65c77b 100644
--- a/src/Web/Grand.Web/Views/Shared/Partials/Head.cshtml
+++ b/src/Web/Grand.Web/Views/Shared/Partials/Head.cshtml
@@ -1,7 +1,7 @@
-@inject IWorkContextAccessor workContextAccessor
+@inject IContextAccessor contextAccessor
@{
- var supportRtl = workContextAccessor.WorkContext.WorkingLanguage.Rtl;
+ var supportRtl = contextAccessor.WorkContext.WorkingLanguage.Rtl;
<script asp-location="Head" src="/bundles/app.runtime.bundle.js"></script>
<script asp-location="Head" src="/bundles/chunk-vendors.runtime.bundle.js"></script>
diff --git a/src/Web/Grand.Web/Views/Shared/Partials/Header.cshtml b/src/Web/Grand.Web/Views/Shared/Partials/Header.cshtml
index 40d994716..487819e8e 100644
--- a/src/Web/Grand.Web/Views/Shared/Partials/Header.cshtml
+++ b/src/Web/Grand.Web/Views/Shared/Partials/Header.cshtml
@@ -1,8 +1,8 @@
-@inject IWorkContextAccessor workContextAccessor
+@inject IContextAccessor contextAccessor
@inject StoreInformationSettings StoreInformationSettings
@inject CommonSettings CommonSettings
@{
- var supportRtl = workContextAccessor.WorkContext.WorkingLanguage.Rtl;
+ var supportRtl = contextAccessor.WorkContext.WorkingLanguage.Rtl;
}
<div class="header-nav">
<nav class="navbar navbar-light navbar-expand">
@@ -67,8 +67,7 @@
@if (CommonSettings.AllowToSelectStore)
{
<partial name="Partials/Selector_Store"/>
- }
- <partial name="Partials/Selector_Store"/>
+ }
@if (StoreInformationSettings.AllowCustomerToSelectTheme)
{
<partial name="Partials/Selector_Theme"/>
diff --git a/src/Web/Grand.Web/Views/Shared/Partials/HeaderLinks.cshtml b/src/Web/Grand.Web/Views/Shared/Partials/HeaderLinks.cshtml
index fb12a92eb..7d717a23b 100644
--- a/src/Web/Grand.Web/Views/Shared/Partials/HeaderLinks.cshtml
+++ b/src/Web/Grand.Web/Views/Shared/Partials/HeaderLinks.cshtml
@@ -2,15 +2,15 @@
@using Grand.Business.Core.Interfaces.Common.Security
@using Grand.Domain.Permissions
@inject IGroupService groupService
-@inject IWorkContextAccessor workContextAccessor
+@inject IContextAccessor contextAccessor
@inject IPageHeadBuilder pagebuilder
@inject IPermissionService permissionService
@{
var registerUrl = Url.RouteUrl("Register", new { returnUrl = Context.Request.Query["returnUrl"] });
- var isAuthenticated = await groupService.IsRegistered(workContextAccessor.WorkContext.CurrentCustomer);
- var isCustomerImpersonated = workContextAccessor.WorkContext.OriginalCustomerIfImpersonated != null;
+ var isAuthenticated = await groupService.IsRegistered(contextAccessor.WorkContext.CurrentCustomer);
+ var isCustomerImpersonated = contextAccessor.WorkContext.OriginalCustomerIfImpersonated != null;
var isAdminAccess = await permissionService.Authorize(StandardPermission.ManageAccessAdminPanel);
- var isVendor = workContextAccessor.WorkContext.CurrentVendor != null;
+ var isVendor = contextAccessor.WorkContext.CurrentVendor != null;
}
@await Component.InvokeAsync("Widget", new { widgetZone = "header_links_before" })
@@ -19,7 +19,7 @@
{
<a class="btn btn-outline-secondary w-100 mb-2" href="@Url.RouteUrl("Logout")" title="@Loc["Account.ImpersonatedAs.Finish.Hint"]">
<b-icon icon="door-closed"></b-icon>
- <span class="text text-uppercase ml-3">@string.Format(Loc["Account.ImpersonatedAs"], workContextAccessor.WorkContext.CurrentCustomer.Email ?? "GUEST")</span>
+ <span class="text text-uppercase ml-3">@string.Format(Loc["Account.ImpersonatedAs"], contextAccessor.WorkContext.CurrentCustomer.Email ?? "GUEST")</span>
</a>
}
@if (isAuthenticated)
diff --git a/src/Web/Grand.Web/Views/Shared/Partials/Logo.cshtml b/src/Web/Grand.Web/Views/Shared/Partials/Logo.cshtml
index bd8de8193..9f165df15 100644
--- a/src/Web/Grand.Web/Views/Shared/Partials/Logo.cshtml
+++ b/src/Web/Grand.Web/Views/Shared/Partials/Logo.cshtml
@@ -1,11 +1,11 @@
@using Grand.Business.Core.Interfaces.Storage
@inject StoreInformationSettings storeInformation
-@inject IWorkContextAccessor workContextAccessor
+@inject IContextAccessor contextAccessor
@inject IPictureService pictureService
@{
var urlLogo = await pictureService.GetPictureUrl(storeInformation.LogoPictureId);
}
<a class="navbar-brand store-logo mx-lg-0 mx-auto" target="_self" href="@Url.RouteUrl("HomePage")">
- <img width="236" height="53" src="@urlLogo" alt="@workContextAccessor.WorkContext.CurrentStore.Name" />
+ <img width="236" height="53" src="@urlLogo" alt="@contextAccessor.StoreContext.CurrentStore.Name" />
<span class="sr-only">@Loc["Logo"]</span>
</a>
\ No newline at end of file
diff --git a/src/Web/Grand.Web/Views/Shared/Partials/Selector_Currency.cshtml b/src/Web/Grand.Web/Views/Shared/Partials/Selector_Currency.cshtml
index 5f6dd6701..9303ba8b3 100644
--- a/src/Web/Grand.Web/Views/Shared/Partials/Selector_Currency.cshtml
+++ b/src/Web/Grand.Web/Views/Shared/Partials/Selector_Currency.cshtml
@@ -2,10 +2,10 @@
@using Grand.Business.Core.Extensions
@using Grand.Business.Core.Interfaces.Common.Directory
@inject ICurrencyService currencyService
-@inject IWorkContextAccessor workContextAccessor
+@inject IContextAccessor contextAccessor
@{
- var availableCurrencies = (await currencyService.GetAllCurrencies(storeId: workContextAccessor.WorkContext.CurrentStore.Id))
+ var availableCurrencies = (await currencyService.GetAllCurrencies(storeId: contextAccessor.StoreContext.CurrentStore.Id))
.Select(x =>
{
//currency char
@@ -15,7 +15,7 @@
var currencyModel = new CurrencyModel
{
Id = x.Id,
- Name = x.GetTranslation(y => y.Name, workContextAccessor.WorkContext.WorkingLanguage.Id),
+ Name = x.GetTranslation(y => y.Name, contextAccessor.WorkContext.WorkingLanguage.Id),
CurrencyCode = x.CurrencyCode,
CurrencySymbol = currencySymbol
};
@@ -30,7 +30,7 @@
x.Name,
Text = x.CurrencyCode,
Value = Url.RouteUrl("ChangeCurrency", new { currencyCode = x.CurrencyCode, returnUrl }),
- Selected = x.Id.Equals(workContextAccessor.WorkContext.WorkingCurrency.Id)
+ Selected = x.Id.Equals(contextAccessor.WorkContext.WorkingCurrency.Id)
});
<b-dropdown class="mr-2" text="@currencies.FirstOrDefault(x => x.Selected).Text">
@foreach (var item in currencies)
diff --git a/src/Web/Grand.Web/Views/Shared/Partials/Selector_Language.cshtml b/src/Web/Grand.Web/Views/Shared/Partials/Selector_Language.cshtml
index 562fd5265..961cce81c 100644
--- a/src/Web/Grand.Web/Views/Shared/Partials/Selector_Language.cshtml
+++ b/src/Web/Grand.Web/Views/Shared/Partials/Selector_Language.cshtml
@@ -1,8 +1,8 @@
@using Grand.Business.Core.Interfaces.Common.Localization
@inject ILanguageService languageService
-@inject IWorkContextAccessor workContextAccessor
+@inject IContextAccessor contextAccessor
@{
- var availableLanguages = (await languageService.GetAllLanguages(storeId: workContextAccessor.WorkContext.CurrentStore.Id))
+ var availableLanguages = (await languageService.GetAllLanguages(storeId: contextAccessor.StoreContext.CurrentStore.Id))
.Select(x => new LanguageModel
{
Id = x.Id,
@@ -16,10 +16,10 @@
if (availableLanguages.Count > 1)
{
<div>
- <b-dropdown class="mr-2" text="@availableLanguages.FirstOrDefault(x => x.Id == workContextAccessor.WorkContext.WorkingLanguage.Id)?.Name">
+ <b-dropdown class="mr-2" text="@availableLanguages.FirstOrDefault(x => x.Id == contextAccessor.WorkContext.WorkingLanguage.Id)?.Name">
@foreach (var lang in availableLanguages)
{
- var className = lang.Id == workContextAccessor.WorkContext.WorkingLanguage.Id ? "active" : "";
+ var className = lang.Id == contextAccessor.WorkContext.WorkingLanguage.Id ? "active" : "";
<b-dropdown-item class="@className" href="@Url.RouteUrl("ChangeLanguage", new { langcode = lang.UniqueSeoCode, returnurl })">
@lang.Name
</b-dropdown-item>
diff --git a/src/Web/Grand.Web/Views/Shared/Partials/Selector_Store.cshtml b/src/Web/Grand.Web/Views/Shared/Partials/Selector_Store.cshtml
index 865501531..bad629d1c 100644
--- a/src/Web/Grand.Web/Views/Shared/Partials/Selector_Store.cshtml
+++ b/src/Web/Grand.Web/Views/Shared/Partials/Selector_Store.cshtml
@@ -1,7 +1,7 @@
@using Grand.Business.Core.Extensions
@using Grand.Business.Core.Interfaces.Common.Stores
@inject IStoreService StoreService
-@inject IWorkContextAccessor workContextAccessor
+@inject IContextAccessor contextAccessor
@{
var availableStores = (await StoreService.GetAllStores())
.Select(x =>
@@ -10,7 +10,7 @@
var storeModel = new StoreModel
{
Id = x.Id,
- Name = x.GetTranslation(y => y.Name, workContextAccessor.WorkContext.WorkingLanguage.Id),
+ Name = x.GetTranslation(y => y.Name, contextAccessor.WorkContext.WorkingLanguage.Id),
Shortcut = x.Shortcut
};
return storeModel;
@@ -20,10 +20,10 @@
{
var returnUrl = Context?.Request?.GetEncodedPathAndQuery();
- <b-dropdown class="mr-2" text="@availableStores.FirstOrDefault(x => x.Id == workContextAccessor.WorkContext.CurrentStore.Id)?.Name">
+ <b-dropdown class="mr-2" text="@availableStores.FirstOrDefault(x => x.Id == contextAccessor.StoreContext.CurrentStore.Id)?.Name">
@foreach (var store in availableStores)
{
- var className = store.Id == workContextAccessor.WorkContext.CurrentStore.Id ? "active" : "";
+ var className = store.Id == contextAccessor.StoreContext.CurrentStore.Id ? "active" : "";
<b-dropdown-item class="@className" href="@Url.RouteUrl("ChangeStore", new { shortcut = store.Shortcut, returnUrl })">
@store.Name
</b-dropdown-item>
diff --git a/src/Web/Grand.Web/Views/Shared/Partials/Selector_TaxType.cshtml b/src/Web/Grand.Web/Views/Shared/Partials/Selector_TaxType.cshtml
index 3b9ba1182..13daef3ca 100644
--- a/src/Web/Grand.Web/Views/Shared/Partials/Selector_TaxType.cshtml
+++ b/src/Web/Grand.Web/Views/Shared/Partials/Selector_TaxType.cshtml
@@ -1,12 +1,12 @@
@inject TaxSettings taxSettings
-@inject IWorkContextAccessor workContextAccessor
+@inject IContextAccessor contextAccessor
@if (taxSettings.AllowCustomersToSelectTaxDisplayType)
{
var text = "";
var className = "";
var returnUrl = Context?.Request?.GetEncodedPathAndQuery();
- if (workContextAccessor.WorkContext.TaxDisplayType == TaxDisplayType.IncludingTax)
+ if (contextAccessor.WorkContext.TaxDisplayType == TaxDisplayType.IncludingTax)
{
text = Loc["Tax.Inclusive"];
className = "active";
diff --git a/src/Web/Grand.Web/Views/Shared/Partials/ShoppingCartLinks.cshtml b/src/Web/Grand.Web/Views/Shared/Partials/ShoppingCartLinks.cshtml
index decccb59a..9737609f5 100644
--- a/src/Web/Grand.Web/Views/Shared/Partials/ShoppingCartLinks.cshtml
+++ b/src/Web/Grand.Web/Views/Shared/Partials/ShoppingCartLinks.cshtml
@@ -1,7 +1,7 @@
@using Grand.Business.Core.Interfaces.Checkout.Orders
@using Grand.Business.Core.Interfaces.Common.Security
@using Grand.Domain.Permissions
-@inject IWorkContextAccessor workContextAccessor
+@inject IContextAccessor contextAccessor
@inject IPermissionService permissionService
@inject IShoppingCartService shoppingCartService
@inject ShoppingCartSettings shoppingCartSettings
@@ -20,14 +20,14 @@
var miniShoppingCartEnabled = shoppingCartSettings.MiniShoppingCartEnabled;
var shoppingCartItems =
- workContextAccessor.WorkContext.CurrentCustomer.ShoppingCartItems.Any()
- ? (await shoppingCartService.GetShoppingCart(workContextAccessor.WorkContext.CurrentStore.Id, shoppingCartTypes.ToArray()))
+ contextAccessor.WorkContext.CurrentCustomer.ShoppingCartItems.Any()
+ ? (await shoppingCartService.GetShoppingCart(contextAccessor.StoreContext.CurrentStore.Id, shoppingCartTypes.ToArray()))
.Sum(x => x.Quantity)
: 0;
- var wishlistItems = workContextAccessor.WorkContext.CurrentCustomer.ShoppingCartItems.Any()
- ? (await shoppingCartService.GetShoppingCart(workContextAccessor.WorkContext.CurrentStore.Id, ShoppingCartType.Wishlist))
+ var wishlistItems = contextAccessor.WorkContext.CurrentCustomer.ShoppingCartItems.Any()
+ ? (await shoppingCartService.GetShoppingCart(contextAccessor.StoreContext.CurrentStore.Id, ShoppingCartType.Wishlist))
.Sum(x => x.Quantity)
: 0;
}
diff --git a/src/Web/Grand.Web/Views/Shared/Partials/SidebarCompareProducts.cshtml b/src/Web/Grand.Web/Views/Shared/Partials/SidebarCompareProducts.cshtml
index 5fefd396a..6c6f79324 100644
--- a/src/Web/Grand.Web/Views/Shared/Partials/SidebarCompareProducts.cshtml
+++ b/src/Web/Grand.Web/Views/Shared/Partials/SidebarCompareProducts.cshtml
@@ -1,6 +1,6 @@
-@inject IWorkContextAccessor workContextAccessor
+@inject IContextAccessor contextAccessor
@{
- var supportRtl = workContextAccessor.WorkContext.WorkingLanguage.Rtl;
+ var supportRtl = contextAccessor.WorkContext.WorkingLanguage.Rtl;
}
<li class="nav-item">
<ul class="px-0">
diff --git a/src/Web/Grand.Web/Views/Shared/Partials/SidebarShoppingCart.cshtml b/src/Web/Grand.Web/Views/Shared/Partials/SidebarShoppingCart.cshtml
index 983f232e9..cee0708f2 100644
--- a/src/Web/Grand.Web/Views/Shared/Partials/SidebarShoppingCart.cshtml
+++ b/src/Web/Grand.Web/Views/Shared/Partials/SidebarShoppingCart.cshtml
@@ -1,7 +1,7 @@
@model int
-@inject IWorkContextAccessor workContextAccessor
+@inject IContextAccessor contextAccessor
@{
- var supportRtl = workContextAccessor.WorkContext.WorkingLanguage.Rtl;
+ var supportRtl = contextAccessor.WorkContext.WorkingLanguage.Rtl;
}
<li class="nav-item">
<ul class="sidebar-cart px-0">
diff --git a/src/Web/Grand.Web/Views/Shared/Partials/SidebarWishlist.cshtml b/src/Web/Grand.Web/Views/Shared/Partials/SidebarWishlist.cshtml
index 7be64da9c..7931ce8da 100644
--- a/src/Web/Grand.Web/Views/Shared/Partials/SidebarWishlist.cshtml
+++ b/src/Web/Grand.Web/Views/Shared/Partials/SidebarWishlist.cshtml
@@ -1,7 +1,7 @@
@model int
-@inject IWorkContextAccessor workContextAccessor
+@inject IContextAccessor contextAccessor
@{
- var supportRtl = workContextAccessor.WorkContext.WorkingLanguage.Rtl;
+ var supportRtl = contextAccessor.WorkContext.WorkingLanguage.Rtl;
}
<li class="nav-item">
<ul class="sidebar-cart wishlist px-0">
diff --git a/src/Web/Grand.Web/wwwroot/theme/script/public.common.js b/src/Web/Grand.Web/wwwroot/theme/script/public.common.js
index cc5e8f3a9..49776e565 100644
--- a/src/Web/Grand.Web/wwwroot/theme/script/public.common.js
+++ b/src/Web/Grand.Web/wwwroot/theme/script/public.common.js
@@ -373,7 +373,7 @@ var Reservation = {
},
daysToMark: function daysToMark(date) {
- for (i = 0; i < Reservation.availableDates.length; i++) {
+ for (let i = 0; i < Reservation.availableDates.length; i++) {
var splitResults = Reservation.availableDates[i].Date.split("-");
var year = splitResults[0];
var month = splitResults[1];
@@ -387,7 +387,7 @@ var Reservation = {
},
daysToMarkTo: function daysToMark(date) {
- for (i = 0; i < Reservation.availableDatesTo.length; i++) {
+ for (let i = 0; i < Reservation.availableDatesTo.length; i++) {
var splitResults = Reservation.availableDatesTo[i].Date.split("-");
var year = splitResults[0];
var month = splitResults[1];
@@ -402,7 +402,7 @@ var Reservation = {
},
daysToMarkFrom: function daysToMark(date) {
- for (i = 0; i < Reservation.availableDatesFrom.length; i++) {
+ for (let i = 0; i < Reservation.availableDatesFrom.length; i++) {
var splitResults = Reservation.availableDatesFrom[i].Date.split("-");
var year = splitResults[0];
var month = splitResults[1];