Setting up a Configuration Page for Your 3.90 or Below NopCommerce Plugin

After writing your NopCommerce plugin, a common next step is to create a ‘Configure’ page to allow for configuring the settings of the plugin.

First, create a model that will represent the values to configure in the plugin – Models/YourPluginModel.cs

Next, create a controller Controllers/YourPluginController.cs, which will look something like this:

...
[AdminAuthorize]
public class YourPluginController: BasePluginController
    {
        private readonly ILocalizationService _localizationService;

        public YourPluginController(ILocalizationService localizationService)
        {
            _localizationService = localizationService;
        }

        [ChildActionOnly]
        public ActionResult Configure()
        {
            return View("~/Plugins/Misc.YourPlugin/Views/YourPlugin/Configure.cshtml", model);
        }

        [HttpPost]
        [ChildActionOnly]
        public ActionResult Configure(YourPluginModel model)
        {
            if (!ModelState.IsValid)
            {
                return Configure();
            }

            SuccessNotification(_localizationService.GetResource("Admin.Plugins.Saved"));

            return Configure();
        }
    }
...

Finally, create a view Views/YourPlugin/Configure.cshtml:

@{
    Layout = "";
}
@using Nop.Web.Framework

@using (Html.BeginForm())
{
    @Html.AntiForgeryToken()
    <div class="panel-group">
        <div class="panel panel-default">
            <div class="panel-body">
                <div class="form-group">
                    <div class="col-md-3">
                         
                    </div>
                    <div class="col-md-9">
                        <input type="submit" name="save" class="btn bg-blue" value="@T("Admin.Common.Save")" />
                    </div>
                </div>
            </div>
        </div>
    </div>
}

Make sure the newly created View is set to ‘Copy if newer’.

Now when running your store, you should be able to enter the Configure page for your plugin, assuming the plugin is installed:

Leave a Reply

Your email address will not be published. Required fields are marked *