Load Settings in an another Controller

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.
2 anos atrás
Hello everyone,
I'm developing a plugin and I've overloaded the Logout method of the CustomerController and i'm loading settingService inside. But when i'm load it, it is null. How can i load the settingService in my custom CustomerController knowing that I save them in the configure method of my primary controller.
this is where i would like to load setting:
ParagonAuthenticationController paragonAuthenticationController = new ParagonAuthenticationController();

                int activeStoreScopeConfiguration = this._storeContext.ActiveStoreScopeConfiguration;

                ISettingService settingService = paragonAuthenticationController.Get_settingService();
                ParagonExternalAuthSettings paragonExternalAuthSettings = settingService.LoadSetting<ParagonExternalAuthSettings>(activeStoreScopeConfiguration);

                HttpClient client = new HttpClient();

                var values = new Dictionary<string, string>
                {
                    {"client_id",paragonExternalAuthSettings.baseurl },
                    {"client_secret","u71sjOYPlFSU602ARv25rlOtuvZdoXG7" },
                    {"refresh_token",refreshToken }
                };
                var content = new FormUrlEncodedContent(values);

                client.PostAsync("https://keycloak-dev.paragon-editique.fr/auth/realms/Paragon/protocol/openid-connect/logout", content);


This is where i'm saving settings
if (!this._permissionService.Authorize(StandardPermissionProvider.ManagePlugins))
            {
                return this.AccessDeniedView();
            }
            int activeStoreScopeConfiguration = this._storeContext.ActiveStoreScopeConfiguration;
            ParagonExternalAuthSettings paragonExternalAuthSettings = this._settingService.LoadSetting<ParagonExternalAuthSettings>(activeStoreScopeConfiguration);
            string str = this.baseurl();
            paragonExternalAuthSettings.authorization_endpoint = model.authorization_endpoint;
            paragonExternalAuthSettings.token_endpoint = model.token_endpoint;
            paragonExternalAuthSettings.baseurl = str;
            paragonExternalAuthSettings.spentityid = str;
            paragonExternalAuthSettings.acsurl = string.Concat("http://localhost:44346", "/Admin/ParagonAuthentication/acs");
            paragonExternalAuthSettings.splogouturl = string.Concat(str, "/Admin/ParagonAuthentication/logout");

            if (string.IsNullOrEmpty(paragonExternalAuthSettings.authorization_endpoint) || string.IsNullOrEmpty(paragonExternalAuthSettings.token_endpoint))
            {
                return this.Content("Please fill in the empty IdP/SP configuration fields before saving.");
            }
            this._settingService.SaveSetting<ParagonExternalAuthSettings, string>(paragonExternalAuthSettings, (ParagonExternalAuthSettings x) => x.authorization_endpoint, activeStoreScopeConfiguration, false);
            this._settingService.SaveSetting<ParagonExternalAuthSettings, string>(paragonExternalAuthSettings, (ParagonExternalAuthSettings x) => x.token_endpoint, activeStoreScopeConfiguration, false);
            this._settingService.SaveSetting<ParagonExternalAuthSettings, string>(paragonExternalAuthSettings, (ParagonExternalAuthSettings x) => x.baseurl, activeStoreScopeConfiguration, false);
            this._settingService.SaveSetting<ParagonExternalAuthSettings, string>(paragonExternalAuthSettings, (ParagonExternalAuthSettings x) => x.spentityid, activeStoreScopeConfiguration, false);
            this._settingService.SaveSetting<ParagonExternalAuthSettings, string>(paragonExternalAuthSettings, (ParagonExternalAuthSettings x) => x.acsurl, activeStoreScopeConfiguration, false);
            this._settingService.SaveSetting<ParagonExternalAuthSettings, string>(paragonExternalAuthSettings, (ParagonExternalAuthSettings x) => x.splogouturl, activeStoreScopeConfiguration, false);
            
            this._settingService.ClearCache();
            this._notificationService.SuccessNotification(this._localizationService.GetResource("Admin.Plugins.Saved"), true);
            return this.Configure();


this is the get methode of settingService
public ISettingService Get_settingService()
        {
            return this._settingService;
        }
2 anos atrás
setting service itself is null or you are getting null value from setting?
if get null value, check setting table store id column. is this value saved for specific store or not?
do you try with current store id not active store id?
2 anos atrás
Rashed Khan wrote:
setting service itself is null or you are getting null value from setting?
if get null value, check setting table store id column. is this value saved for specific store or not?
do you try with current store id not active store id?


Thanks for your answer,

It's this variable which is null because the Get_settingService return null:
ISettingService settingService = paragonAuthenticationController.Get_settingService();


I load in an other controller
You think I have to search data in database ?
2 anos atrás
what version of nopCommerce you are using? why you need to get _settingService from return method, why not direct? check existing uses of _settingService at default nopCommerce
2 anos atrás
Rashed Khan wrote:
what version of nopCommerce you are using? why you need to get _settingService from return method, why not direct? check existing uses of _settingService at default nopCommerce


I'm on Nop 4.3
I create an instance of Setting when i log a user
And when i logout the user i'm obliged to create a new instance of Setting beacause i'm not in the same controller
This the new instance i create and it say that the object is not reference to an object
 
ParagonExternalAuthSettings paragonExternalAuthSettings = new ParagonExternalAuthSettings();

                int activeStoreScopeConfiguration = this._storeContext.ActiveStoreScopeConfiguration;
                paragonExternalAuthSettings = this._settingService.LoadSetting
<ParagonExternalAuthSettings>(activeStoreScopeConfiguration);


I use a get_settingService because i'm not in the same file
2 anos atrás
skyloRen wrote:

I use a get_settingService because i'm not in the same file

if you resolve dependency of settingService from used file. is that not working?
2 anos atrás
Rashed Khan wrote:

I use a get_settingService because i'm not in the same file
if you resolve dependency of settingService from used file. is that not working?


How can I do this ?
2 anos atrás
skyloRen wrote:

How can I do this ?

i need to do some RnD on it. you can check this link to check how to resolve dependency from plugin on runtime using ConfigurationProvider https://www.nopcommerce.com/en/boards/topic/55525/how-do-i-get-access-to-the-isettingservice-in-my-plugins-dependencyregistrar-class#212539
2 anos atrás
skyloRen wrote:
...
I create an instance of Setting when i log a user
And when i logout the user i'm obliged to create a new instance of Setting beacause i'm not in the same controller...

I'm confused as to what you are trying to do.  Settings are per system/store.  If you want 'settings' per user, then you should use GenericAttributes.
This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.