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.
Settings and Localization
Purpose
Create, modify, and review GrandNode settings classes, setting persistence, store-scoped overrides, localization resources, translation resource lifecycle, and localized domain and admin models.
When To Use
Use this skill when adding or changing a settings class, loading or saving settings per store, reading or writing localization resources, adding translation keys for a plugin or module, seeding default settings or resources in the installer, building localized admin models, or working with ITranslationService, ISettingService, IPluginTranslateResource, or ILanguageService.
When Not To Use
Do not use this skill for pure UI work without settings or localization changes; combine it with template-creation or admin-area-changes when UI is involved.
Do not use this skill as the primary review for MongoDB query safety or security; combine it with the relevant skill when those concerns apply.
Inputs Required
- Repository root.
- Target feature, plugin, or module name.
- Whether settings are global or per-store.
- Which admin panels expose the settings (Admin, Store Owner, Vendor, plugin config page).
- Required localization resource keys and their text.
- Whether domain entities carry per-language values (
ITranslationEntity/Locales).
Instructions
Mandatory Rules
Settings
- Define core settings classes in
src/Core/Grand.Domainand implement the marker interfaceGrand.Domain.Configuration.ISettings(plugin settings classes stay in the owning plugin project). - Keep settings as plain properties with no business logic. Store primitive types, enums, and simple value types.
- Load settings with
ISettingService.LoadSetting<T>(storeId). Pass an empty string to load the global fallback; pass the active store ID for per-store overrides. - Obtain the active store ID from
IAdminStoreService.GetActiveStore()in admin, store, and plugin controllers. - Save settings with
ISettingService.SaveSetting<T>(settings, storeId). Callawait settingService.ClearCache()immediately after. - Delete all settings for a type with
ISettingService.DeleteSetting<T>()in pluginUninstall. - Seed default settings in
src/Modules/Grand.Module.Installer/Services/InstallDataSettings.csusingSaveSettingwithout a store ID. - Map between settings and admin models using static extension methods in
src/Web/Grand.Web.AdminShared/Extensions/Mapping/Settings/, following theToModel()/ToEntity(model, destination)pattern backed byMapTo. - Register mapper profiles for settings models in
Grand.Web.AdminSharedwhen the model is shared across panels.
Localization
- Identify resources by a lowercase dot-separated key, for example
plugins.payment.cashondelivery.additionalfee. - Use
IPluginTranslateResource.AddOrUpdatePluginTranslateResource(name, value, area)in pluginInstallto register all resource keys. - Use
IPluginTranslateResource.DeletePluginTranslationResource(name)in pluginUninstallfor every key added during install. - Assign the correct
TranslationResourceAreaenum value when adding resources:Common(0) — shared across all areas.Admin(1) — admin panel only.Front(2) — public storefront.Plugin(3) — plugin-owned resources.Vendor(5) — vendor panel.
- Seed default resources for core features in
src/Modules/Grand.Module.Installer/Services/InstallDataLocaleResources.csviasrc/Web/Grand.Web/App_Data/Resources/DefaultLanguage.xml. - Access resources in controllers and services by injecting
ITranslationServiceand callingGetResource(key)orGetResource(key, languageId, defaultValue). - Access resources in Razor views through the
Locindexer:@Loc["key"]. Do not callITranslationServicedirectly from views. - Translate enum values using
IEnumTranslationServicewith keys formatted asEnums.{TypeName}.{ValueName}.
Localized Domain Entities
- Implement
ITranslationEntityon domain entities that require per-language field values. This adds aIList<TranslationEntity> Localescollection where each entry carriesLanguageId,LocaleKey, andLocaleValue. - Implement
ILocalizedModel<TLocalizedModel>on admin models for entities with localized fields. Each inner model must implementILocalizedModelLocal(has aLanguageIdproperty).
Recommendations
- Prefer
LoadSetting<T>(storeId)over individual key lookups for settings objects with multiple properties. - Prefer a single
SaveSetting<T>call that persists the whole settings object rather than saving individual keys. - Prefer store-scoped settings only when the feature must behave differently across stores.
- Prefer adding all resource keys in a single
Installmethod block so they are easy to match withUninstalldeletions. - Prefer using
Admin.Configuration.UpdatedandAdmin.Plugins.Savedas generic success messages rather than inventing new keys. - Prefer placing plugin-specific settings classes inside the plugin project, not in
Grand.Domain.
Constraints
- Never place a settings class outside
Grand.Domainfor core features (plugin settings are the exception and stay in the plugin project). - Never load settings without passing a store ID when the feature supports per-store configuration.
- Never skip
ClearCache()after saving settings. - Never leave resource keys in
Installthat are not removed inUninstall. - Never hardcode display text in controllers or views when a resource key is available.
- Never call
ITranslationServicedirectly from Razor views; useLoc[...]instead. - Never add
TranslationResourcedocuments directly to the database without going throughITranslationServiceorIPluginTranslateResource.
Key Contracts
ISettingService (src/Business/Grand.Business.Core/Interfaces/Common/Configuration/ISettingService.cs)
Task<T> LoadSetting<T>(string storeId = "") where T : ISettings, new();
Task SaveSetting<T>(T settings, string storeId = "") where T : ISettings, new();
Task DeleteSetting<T>() where T : ISettings, new();
Task ClearCache();
Task<T> GetSettingByKey<T>(string key, T defaultValue = default, string storeId = "");
Task SetSetting<T>(string key, T value, string storeId = "");
IList<Setting> GetAllSettings();
ITranslationService (src/Business/Grand.Business.Core/Interfaces/Common/Localization/ITranslationService.cs)
string GetResource(string name);
string GetResource(string name, string languageId, string defaultValue = "", bool returnEmptyIfNotFound = false);
Task InsertTranslateResource(TranslationResource resource);
Task UpdateTranslateResource(TranslationResource resource);
Task DeleteTranslateResource(TranslationResource resource);
Task<TranslationResource> GetTranslateResourceByName(string name, string languageId);
IPluginTranslateResource (src/Business/Grand.Business.Core/Interfaces/Common/Localization/IPluginTranslateResource.cs)
Task AddOrUpdatePluginTranslateResource(string name, string value,
TranslationResourceArea area = TranslationResourceArea.Common, string languageCulture = null);
Task DeletePluginTranslationResource(string name);
IAdminStoreService (src/Web/Grand.Web.Common/Helpers/AdminStoreService.cs)
Task<string> GetActiveStore(); // returns storeId or "" if single-store
File Locations
| Concern | Path |
|---|---|
| Settings domain classes | src/Core/Grand.Domain/{Area}/{Feature}Settings.cs |
| ISettings marker | src/Core/Grand.Domain/Configuration/ISettings.cs |
| ISettingService interface | src/Business/Grand.Business.Core/Interfaces/Common/Configuration/ISettingService.cs |
| SettingService implementation | src/Business/Grand.Business.Common/Services/Configuration/SettingService.cs |
| Settings admin models (shared) | src/Web/Grand.Web.AdminShared/Models/Settings/ |
| Settings mapping extensions | src/Web/Grand.Web.AdminShared/Extensions/Mapping/Settings/ |
| ITranslationService interface | src/Business/Grand.Business.Core/Interfaces/Common/Localization/ITranslationService.cs |
| IPluginTranslateResource interface | src/Business/Grand.Business.Core/Interfaces/Common/Localization/IPluginTranslateResource.cs |
| ILanguageService interface | src/Business/Grand.Business.Core/Interfaces/Common/Localization/ILanguageService.cs |
| TranslationResource entity | src/Core/Grand.Domain/Localization/TranslationResource.cs |
| TranslationResourceArea enum | src/Core/Grand.Domain/Localization/TranslationResourceArea.cs |
| ITranslationEntity interface | src/Core/Grand.Domain/Localization/ITranslationEntity.cs |
| LocService (view localizer) | src/Web/Grand.Web.Common/Localization/LocService.cs |
| ILocalizedModel interface | src/Web/Grand.Web.Common/Models/ILocalizedModel.cs |
| Default resource XML | src/Web/Grand.Web/App_Data/Resources/DefaultLanguage.xml |
| Installer — settings seed | src/Modules/Grand.Module.Installer/Services/InstallDataSettings.cs |
| Installer — resource seed | src/Modules/Grand.Module.Installer/Services/InstallDataLocaleResources.cs |
| IAdminStoreService | src/Web/Grand.Web.Common/Helpers/AdminStoreService.cs |
| SettingService tests | src/Tests/Grand.Business.Common.Tests/Services/Configuration/SettingServiceTests.cs |
| TranslationService tests | src/Tests/Grand.Business.Common.Tests/Services/Localization/TranslationServiceTests.cs |
Expected Output
Produce one of these results:
- A new or modified settings class, mapping extension, admin model, and controller flow.
- A new or modified set of localization resource keys with matching install and uninstall handling.
- A review report listing settings or localization issues by severity.
Include changed files, store-scope behavior, resource area classification, validation commands, and remaining risks.
Validation Checklist
- Settings class implements
ISettingsand lives in the correct project. -
LoadSettingandSaveSettingpass the correct store ID. -
ClearCacheis called after everySaveSetting. -
DeleteSetting<T>is called in pluginUninstall. - Every resource key added in
Installis removed inUninstall. - Resource area is set correctly (
TranslationResourceArea). - Controllers use
ITranslationService.GetResource(key)for display messages. - Views use
@Loc["key"]and do not callITranslationServicedirectly. - Entities that need per-language values implement
ITranslationEntity. - Admin models that expose localized fields implement
ILocalizedModel<T>. - Settings mapping extensions follow the
ToModel()/ToEntity(model, destination)pattern. - Tests or build commands were run or reported as not run.
Examples
Example 1: Plugin Settings with Store Scope
Input: Add configurable additional fee to a payment plugin.
Output:
- Add
AdditionalFeeproperty toXPaymentSettings : ISettingsin the plugin project. - In
Configure(GET): call_adminStoreService.GetActiveStore(), then_settingService.LoadSetting<XPaymentSettings>(storeScope), map to model. - In
Configure(POST): reload settings, update property, callSaveSetting(settings, storeScope), thenClearCache(), thenSuccess(translationService.GetResource("Admin.Plugins.Saved")). - In
Install: callSaveSetting(new XPaymentSettings { AdditionalFee = 0 })andAddOrUpdatePluginTranslateResource("Plugins.Payment.X.AdditionalFee", "Additional fee", TranslationResourceArea.Plugin). - In
Uninstall: callDeleteSetting<XPaymentSettings>()andDeletePluginTranslationResource("Plugins.Payment.X.AdditionalFee").
Example 2: Core Settings Field
Input: Add a new catalog setting that controls whether product reviews require approval.
Output:
- Add
ProductReviewsMustBeApprovedproperty toCatalogSettingsinsrc/Core/Grand.Domain/Catalog/CatalogSettings.cs. - Add matching property to
CatalogSettingsModelinsrc/Web/Grand.Web.AdminShared/Models/Settings/CatalogSettingsModel.cs. - Update
CatalogSettingsMappingExtensionsto include the property inToModel()andToEntity(). - Update the Admin and Store Owner settings views and controllers to read and write the field.
- Add a resource key
admin.configuration.settings.catalog.productreviewsmustbeapprovedtoDefaultLanguage.xml.
Example 3: Localized Domain Entity Field
Input: Add a per-language description to a custom entity.
Output:
- Implement
ITranslationEntityon the domain entity to getIList<TranslationEntity> Locales. - In the admin model, implement
ILocalizedModel<TLocalizedModel>where the inner model hasLanguageIdandDescription. - In the admin view, render a localization tab using the existing localized tab pattern.
- In the controller save action, persist each locale entry back to
entity.Locales.