Skip to content

Commit 63aadfb

Browse files
Refactor StoreService and WorkContextSetter
1 parent 60fc4bd commit 63aadfb

File tree

5 files changed

+6
-28
lines changed

5 files changed

+6
-28
lines changed

src/Business/Grand.Business.Common/Services/Stores/StoreService.cs

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -56,18 +56,6 @@ public virtual async Task<IList<Store>> GetAllStores()
5656
});
5757
}
5858

59-
/// <summary>
60-
/// Gets all stores
61-
/// </summary>
62-
/// <returns>Stores</returns>
63-
public virtual IList<Store> GetAll()
64-
{
65-
return _allStores ??= _cacheBase.Get(CacheKey.STORES_ALL_KEY, () =>
66-
{
67-
return _storeRepository.Table.OrderBy(x => x.DisplayOrder).ToList();
68-
});
69-
}
70-
7159
/// <summary>
7260
/// Gets a store
7361
/// </summary>

src/Business/Grand.Business.Core/Interfaces/Common/Stores/IStoreService.cs

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,6 @@ public interface IStoreService
1313
/// <returns>Stores</returns>
1414
Task<IList<Store>> GetAllStores();
1515

16-
/// <summary>
17-
/// Gets all stores
18-
/// </summary>
19-
/// <returns>Stores</returns>
20-
IList<Store> GetAll();
21-
2216
/// <summary>
2317
/// Gets a store
2418
/// </summary>

src/Web/Grand.Web.Common/WorkContextSetter.cs

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
using Grand.Domain.Vendors;
1414
using Grand.Infrastructure;
1515
using Grand.Infrastructure.Configuration;
16+
using Grand.SharedKernel.Extensions;
1617
using Microsoft.AspNetCore.Authorization;
1718
using Microsoft.AspNetCore.Http;
1819
using Microsoft.AspNetCore.Localization;
@@ -38,7 +39,6 @@ public WorkContextSetter(
3839
IStoreService storeService,
3940
IAclService aclService,
4041
IVendorService vendorService,
41-
LanguageSettings languageSettings,
4242
TaxSettings taxSettings,
4343
AppConfig config)
4444
{
@@ -51,7 +51,6 @@ public WorkContextSetter(
5151
_storeService = storeService;
5252
_aclService = aclService;
5353
_vendorService = vendorService;
54-
_languageSettings = languageSettings;
5554
_taxSettings = taxSettings;
5655
_config = config;
5756
}
@@ -70,7 +69,6 @@ public WorkContextSetter(
7069
private readonly IAclService _aclService;
7170
private readonly IVendorService _vendorService;
7271

73-
private readonly LanguageSettings _languageSettings;
7472
private readonly TaxSettings _taxSettings;
7573
private readonly AppConfig _config;
7674

@@ -347,8 +345,7 @@ protected async Task<Language> WorkingLanguage(Customer customer, Store store)
347345
var customerLanguageId =
348346
customer.GetUserFieldFromEntity<string>(SystemCustomerFieldNames.LanguageId, store.Id);
349347

350-
if (_languageSettings.AutomaticallyDetectLanguage &&
351-
language == null && string.IsNullOrEmpty(customerLanguageId))
348+
if (language == null && string.IsNullOrEmpty(customerLanguageId))
352349
language = await GetLanguageFromRequest(allStoreLanguages, store);
353350

354351
//check customer language
@@ -420,10 +417,9 @@ protected async Task<TaxDisplayType> TaxDisplayType(Customer customer, Store sto
420417
return await Task.FromResult(taxDisplayType);
421418
}
422419

423-
private const string StoreCookieName = ".Grand.Store";
424420
private string GetStoreCookie()
425421
{
426-
return _httpContextAccessor.HttpContext?.Request.Cookies[StoreCookieName];
422+
return _httpContextAccessor.HttpContext?.Request.Cookies[CommonHelper.StoreCookieName];
427423
}
428424

429425
protected async Task<Store> CurrentStore(string id = null)
@@ -433,7 +429,7 @@ protected async Task<Store> CurrentStore(string id = null)
433429

434430
var host = _httpContextAccessor.HttpContext?.Request.Host.Host;
435431

436-
var allStores = _storeService.GetAll();
432+
var allStores = await _storeService.GetAllStores();
437433
var stores = allStores.Where(s => s.ContainsHostValue(host)).ToList();
438434
if (!stores.Any())
439435
return allStores.FirstOrDefault();

src/Web/Grand.Web/Controllers/CommonController.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -248,7 +248,7 @@ public virtual async Task<IActionResult> SetStore(
248248
if (currentstoreShortcut != shortcut)
249249
if (commonSettings.AllowToSelectStore)
250250
{
251-
var selectedstore = storeService.GetAll().FirstOrDefault(x =>
251+
var selectedstore = (await storeService.GetAllStores()).FirstOrDefault(x =>
252252
string.Equals(x.Shortcut, shortcut, StringComparison.InvariantCultureIgnoreCase));
253253
if (selectedstore != null)
254254
{

src/Web/Grand.Web/Views/Shared/Partials/Selector_Store.cshtml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
@inject IStoreService StoreService
44
@inject IWorkContextAccessor workContextAccessor
55
@{
6-
var availableStores = StoreService.GetAll()
6+
var availableStores = (await StoreService.GetAllStores())
77
.Select(x =>
88
{
99
//model

0 commit comments

Comments
 (0)