Search
Back to all

Settings in nopCommerce

General rules for using settings in nopCommerce are as follows:

1. If you have a single store (so you don't use a multistore feature), you can always inject settings by DI.
2. If you use a multistore feature, then getting settings depends on the place of use:

a) you can still inject settings by DI in any code that is called by a user request (controller actions, factory methods, service methods, some code on views, etc.), they will be injected for the current store (for which the request is executed);
b) when configuring a plugin or settings in the admin area, you should load the settings for the selected store ID to override them for this store;
c) in any code that is called by third-party and not by user actions (for example, schedule tasks, webhook notifications from third-party services, etc.), getting settings should be considered case-by-case:

i) You can inject settings, but get ready that they will be injected for the store for which the webhook was registered, or from which the whole application was started (usually the first one from the list) in the case of schedule tasks.
ii) You can somehow get the store ID (e.g. from a query string in case of webhooks) and load the settings according to this ID.
iii) You can load all the settings, and then use them separately for each store (suitable for tasks with synchronization).

So in our Brevo plugin we use few approaches at the same time:
2-a in the view component, since this code is called by the user;
2-b in the plugin configuration;
2-c-iii in the schedule task since this is a synchronization task.

If you are developing your own plugin or customizing the solution, follow the rules above.

Comments
Leave your comment Close