Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 11 additions & 11 deletions src/Web/Grand.Web.Admin/Components/StoreScope.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
using Grand.Business.Core.Interfaces.Common.Directory;
using Grand.Business.Core.Interfaces.Common.Localization;
using Grand.Business.Core.Interfaces.Common.Stores;
using Grand.Infrastructure;
using Grand.Web.AdminShared.Models.Settings;
using Grand.Web.Common.Components;
using Grand.Web.Common.Helpers;
Expand All @@ -15,9 +14,8 @@ public class StoreScopeViewComponent : BaseAdminViewComponent
#region Fields

private readonly IStoreService _storeService;
private readonly IContextAccessor _contextAccessor;
private readonly IGroupService _groupService;
private readonly IAdminStoreService _adminStoreService;
private readonly ITranslationService _translationService;

#endregion

Expand All @@ -26,13 +24,11 @@ public class StoreScopeViewComponent : BaseAdminViewComponent
public StoreScopeViewComponent(
IStoreService storeService,
IAdminStoreService adminStoreService,
IGroupService groupService,
IContextAccessor contextAccessor)
ITranslationService translationService)
{
_adminStoreService = adminStoreService;
_storeService = storeService;
_contextAccessor = contextAccessor;
_groupService = groupService;
_translationService = translationService;
}

#endregion
Expand All @@ -45,10 +41,14 @@ public async Task<IViewComponentResult> InvokeAsync()
if (allStores.Count < 2)
return Content("");

if (await _groupService.IsStoreManager(_contextAccessor.WorkContext.CurrentCustomer))
allStores = allStores.Where(x => x.Id == _contextAccessor.WorkContext.CurrentCustomer.StaffStoreId).ToList();

var model = new StoreScopeModel();

//global scope (all stores)
model.Stores.Add(new StoreModel {
Id = "",
Name = _translationService.GetResource("Admin.Settings.StoreScope.AllStores")
});

foreach (var s in allStores)
model.Stores.Add(new StoreModel {
Id = s.Id,
Expand Down
11 changes: 4 additions & 7 deletions src/Web/Grand.Web.Admin/Controllers/BaseAdminController.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using Grand.Business.Core.Interfaces.Common.Directory;
using Grand.Business.Core.Interfaces.Common.Stores;
using Grand.Business.Core.Interfaces.Common.Stores;
using Grand.Domain.Common;
using Grand.Domain.Customers;
using Grand.Infrastructure;
Expand All @@ -24,23 +23,21 @@ protected async Task<string> GetActiveStore()
{
var storeService = HttpContext.RequestServices.GetRequiredService<IStoreService>();
var workContext = HttpContext.RequestServices.GetRequiredService<IContextAccessor>().WorkContext;
var groupService = HttpContext.RequestServices.GetRequiredService<IGroupService>();

var stores = await storeService.GetAllStores();
if (stores.Count < 2)
return stores.FirstOrDefault()?.Id;
Comment thread
KrzysztofPajak marked this conversation as resolved.

if (await groupService.IsStoreManager(workContext.CurrentCustomer)) return workContext.CurrentCustomer.StaffStoreId;

var storeId =
workContext.CurrentCustomer.GetUserFieldFromEntity<string>(SystemCustomerFieldNames
.AdminAreaStoreScopeConfiguration);
//empty scope means "all stores" - settings are loaded from/saved to the global scope
if (string.IsNullOrEmpty(storeId))
{
return stores.First()?.Id;
return "";
}

var store = await storeService.GetStoreById(storeId);
return store != null ? store.Id : stores.First()?.Id;
return store != null ? store.Id : "";
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -40,24 +40,6 @@
<span asp-validation-for="CustomerSettings.TwoFactorAuthenticationType"></span>
</div>
</div>
<div class="form-group">
<div class="col-8 col-md-4 col-sm-4 text-right">
<admin-label asp-for="CustomerSettings.DefaultPasswordFormat" class="control-label"/>
</div>
<div class="col-4 col-md-8 col-sm-8">
<admin-select asp-for="CustomerSettings.DefaultPasswordFormat" asp-items="EnumTranslationService.ToSelectList((PasswordFormat)Model.CustomerSettings.DefaultPasswordFormat)"/>
<span asp-validation-for="CustomerSettings.DefaultPasswordFormat"></span>
</div>
</div>
<div class="form-group">
<div class="col-8 col-md-4 col-sm-4 text-right">
<admin-label asp-for="CustomerSettings.HashedPasswordFormat" class="control-label"/>
</div>
<div class="col-4 col-md-8 col-sm-8">
<admin-select asp-for="CustomerSettings.HashedPasswordFormat" asp-items="EnumTranslationService.ToSelectList(Model.CustomerSettings.HashedPasswordFormat)"/>
<span asp-validation-for="CustomerSettings.HashedPasswordFormat"></span>
</div>
</div>
<div class="form-group">
<div class="col-8 col-md-4 col-sm-4 text-right">
<admin-label asp-for="CustomerSettings.PasswordRegularExpression" class="control-label"/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,18 +103,6 @@
<span asp-validation-for="LoyaltyPointsSettings.DisplayHowMuchWillBeEarned"></span>
</div>
</div>
<div class="form-group">
<div class="col-8 col-md-4 col-sm-4 text-right">
<admin-label asp-for="LoyaltyPointsSettings.PointsAccumulatedForAllStores" class="control-label"/>
</div>
<div class="col-4 col-md-8 col-sm-8">
<label class="mt-checkbox mt-checkbox-outline control control-checkbox">
<admin-input asp-for="LoyaltyPointsSettings.PointsAccumulatedForAllStores"/>
<div class="control__indicator"></div>
</label>
<span asp-validation-for="LoyaltyPointsSettings.PointsAccumulatedForAllStores"></span>
</div>
</div>
</div>
</div>
<vc:admin-widget widget-zone="loyalty_points_settings_bottom" additional-data="null"/>
13 changes: 13 additions & 0 deletions src/Web/Grand.Web.Store/Controllers/SettingController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -285,7 +285,13 @@ public async Task<IActionResult> Sales(SalesSettingsModel model,
if (ModelState.IsValid)
{
var loyaltyPointsSettings = await settingService.LoadSetting<LoyaltyPointsSettings>(storeScope);

// Cross-store accumulation is managed by the administrator - store owners cannot change it
var pointsAccumulatedForAllStores = loyaltyPointsSettings.PointsAccumulatedForAllStores;

loyaltyPointsSettings = model.LoyaltyPointsSettings.ToEntity(loyaltyPointsSettings);
loyaltyPointsSettings.PointsAccumulatedForAllStores = pointsAccumulatedForAllStores;

await settingService.SaveSetting(loyaltyPointsSettings, storeScope);

var shoppingCartSettings = await settingService.LoadSetting<ShoppingCartSettings>(storeScope);
Expand Down Expand Up @@ -625,7 +631,14 @@ public async Task<IActionResult> Customer(CustomerSettingsModel model)
var customerSettings = await settingService.LoadSetting<CustomerSettings>(storeScope);
var addressSettings = await settingService.LoadSetting<AddressSettings>(storeScope);

// Password storage formats are managed by the administrator - store owners cannot change them
var defaultPasswordFormat = customerSettings.DefaultPasswordFormat;
var hashedPasswordFormat = customerSettings.HashedPasswordFormat;

customerSettings = model.CustomerSettings.ToEntity(customerSettings);
customerSettings.DefaultPasswordFormat = defaultPasswordFormat;
customerSettings.HashedPasswordFormat = hashedPasswordFormat;

await settingService.SaveSetting(customerSettings, storeScope);

addressSettings = model.AddressSettings.ToEntity(addressSettings);
Expand Down
Loading