URGENT!: Adding a new setting to the GlobalSettings section

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.
13 years ago
Thx!

But I have this approach but still want to be able to use this

"$NopResources:Admin.GlobalSettings.Profiles.FormFields.MobileEnabled" declaritive code.

Also I found that once code the setting up this happens

http://img715.imageshack.us/img715/5276/1512201062104am.png
13 years ago
You are confusing localization settings with all settings.

Text and tooltip properties are stored in ContentMangement-->Localization.  These are ResourceName ("admin.globalsettings....") and ResourceValue("I want to display this message in English as the label for my label control") pairs that determine what TEXT is displayed for labels and tooltips.

The admin settings are stored in Configuration-->All Settings.  These work in the way I described in my previous post.  You need to go into the code behind (in your example) of GlobalSettings.ascx.cs and add the appropriate hook into your admin setting NOT the localization value.  

Hope this makes sense.

t
13 years ago
Eerm...... doh

SO all "NopResources" are for localisation.

I beleive you r correct. I will check into this further. To much time in front of the wall of code.

Thx very much forthe clarification.
13 years ago
Eerm...... doh

SO all "NopResources" are for localisation.

I beleive you r correct. I will check into this further. To much time in front of the wall of code.

Thx very much forthe clarification.
13 years ago
No worries.  It would be easy to mix the 2 up.

As long as you follow my first example, that will give you the functionality you are looking for.

To customize how the setting NAME is displayed, just enter a new localization setting matching the string in your screen shot and you are done.

NOTE: It looks like you are trying to add another field to the registration page.  If you want this value stored in the db, you have a little more work ahead of you.

t
11 years ago
joebloe wrote:
Ok.  That clears a few things up.

Most of the settings found in the admin area are simple strings that correspond to some arbitrary value.  What makes this approach powerful for customization is that you are not stuck using a single convention.  Open up all settings and you can see the long list of settings that correspond to strings, boolean values, integers, etc.  This allows you to setup a configuration type setting in anyway you want.

For your example you could create a new setting and call it something like, "Display.ShowCategoryNavigation".  You would then set it's value to true or false based on your needs.  However, this will only register the setting you would need to wire it up.

A quick and dirty example would be to override the OnInit event in /modules/categorynavigation.ascx.cs.  Like this:

protected override void OnInit(EventArgs e)
        {
            if (SettingManager.GetSettingValueBoolean("Display.ShowCategoryNavigation") == false)
            {
                this.Visible = false;
            }
        }


You would also need to reference NopSolutions.NopCommerce.BusinessLogic.Configuration.Settings.

As you can see there are countless ways in which you can use admin settings.  All you have to do is wire up your logic in the appropriate place and call the SettingManager.

Hope this helps.

EDIT:  I just noticed you wanted to make this setting available under Global Settings.  The solution I have above has the setting only in 'All Settings'.  If you wanted to make it available under the former then a little more work would be necessary.  Basically what you would have to do is either make a new control tab and then wire a checkbox to your setting or just add a checkbox and the wiring in a existing tab.  NOTE: You will find most of the tab names have corresponding control names in /admin/modules.


Hi joebloe,

Do you happen to know how to do this on nopcommerce 2.65?  

Particularly I would like to read a global setting on Nop.Services.Catalog.PriceCalculationService.

Thanks.
11 years ago
What setting are you trying to read, and from where are you trying to do the read?
11 years ago
New York wrote:
What setting are you trying to read, and from where are you trying to do the read?


Hi New York,

I would like to add a decimal setting to the Catalog Settings named CustomerEnterPricePercentageSurcharge in nopcommerce 2.65.  I would like to read it from "Libraries\Nop.Services\Catalog\PriceCalculationService.cs" in order to customize a percentage surcharge on "donation productos" as suggested by Andrei on this thread.

I followed the instructions on How to Add New Setting Value in Customer settings post.

However, after following the 3 steps ("tweacking" it for Catalog Settings) mentioned in the aforementioned post, when login into the admin section and save the catalog settings the value is always 0.0000. It seems that it isn't saving (or loading) the "catalogsettings.customerenterpricepercentagesurcharge" settings value.  

Also,  I can't see the value on the variable _catalogSettings inside "Libraries\Nop.Services\Catalog\PriceCalculationService.cs"

Thanks.
11 years ago
The stackoverflow response is inadequate.  It only covers how to add a setting to be visible on the Admin config page.
You need to also create the setting property in the CatalogSettings class (...src\Libraries\Nop.Core\Domain\Catalog\CatalogSettings.cs)

I recommend that you
1) in Visual Studio, open ...src\Libraries\Nop.Core\Domain\Catalog\CatalogSettings.cs
2) right click the last property ManufacturersBlockItemsToDisplay, and Find All references
Besides adding your new property after ManufacturersBlockItemsToDisplay, you will see the other places you need to modify

Do the same  Find All references in
src\Presentation\Nop.Web\Administration\Models\Settings\CatalogSettingsModel.cs
(this is what was referred to in the stackoverflow response)
11 years ago
New York wrote:
The stackoverflow response is inadequate.  It only covers how to add a setting to be visible on the Admin config page.
You need to also create the setting property in the CatalogSettings class (...src\Libraries\Nop.Core\Domain\Catalog\CatalogSettings.cs)

I recommend that you
1) in Visual Studio, open ...src\Libraries\Nop.Core\Domain\Catalog\CatalogSettings.cs
2) right click the last property ManufacturersBlockItemsToDisplay, and Find All references
Besides adding your new property after ManufacturersBlockItemsToDisplay, you will see the other places you need to modify

Do the same  Find All references in
src\Presentation\Nop.Web\Administration\Models\Settings\CatalogSettingsModel.cs
(this is what was referred to in the stackoverflow response)


Hi New York,

The final solution incorporated your suggestion.  I'll just summarize exaclty what I did for the benefit of others:

1. Added a new value in All Settings (configuration ->setting->AllSetting).  I named it catalogsettings.customerenterspricepercentagesurcharge

2. Added a new filed in Nop.Core.Domain.Catalog.CatalogSettings
public decimal CustomerEntersPricePercentageSurcharge { get; set; }

Thanks, your advice was very helpful.

p.s. I have to also give credit to Carlos who helped me as well.
This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.