Implementing a Misc NopCommerce Plugin

Initial Setup

Follow the steps in the Implementing a Base NopCommerce Plugin tutorial and name your project
Nop.Plugin.Misc.[ProjectName]

This tutorial is directed toward building upon the previous tutorial in order to implement a misc plugin and demonstrate some of NopCommere's plugin capabilities.

Description.txt

Set your plugin as a Misc plugin type in the description.txt file.

Group: Misc
FriendlyName: [PluginName]
SystemName: Nop.Plugin.Misc.[PluginName]
Version: 1.0
SupportedVersions: [CurrentNopVersion, ex. 3.08]
Author: [YourName]
DisplayOrder: 1
FileName: Nop.Plugin.Misc.[PluginName].dll

Create the main Plugin Class file

1. In the root directory of your plugin create a new C# file named

[PluginName]Plugin.cs

2. Make your plugin implement BasePlugin and IMiscPlugin

namespace Nop.Plugin.Misc.[PluginName]
{
    public class [ProjectName]Plugin : BasePlugin, IMiscPlugin
    {
        ...
    }
}

3. Implement Plugin Class Contructor and Private Members

Add any needed NopCommerce Services that you need to use in your plugin by using dependency injection.

Add the needed private members, ex:
private readonly ISettingService _settingService;
private readonly ILocalizationService _localizationService;
private readonly ILogger _logger;
Implement the constructor and inject the services into your local members, ex:
public [PluginName]Plugin(
    ISettingService settingService
    ILocalizationService localizationService
    , ILogger logger
    )
{
    _settingService = settingService;
    _localizationService = localizationService;
    _logger = logger;
}

4. Implement IMisc Plugin Members

Implement the configuration route for the plugin's configuration page in NopCommerce:
public void GetConfigurationRoute(
    out string actionName, 
    out string controllerName, 
    out RouteValueDictionary routeValues)
{
    actionName = "Configure";
    controllerName = "[PluginName]";
    routeValues = new RouteValueDictionary { 
        { "Namespaces", "Nop.Plugin.Misc.[PluginName].Controllers" },
        { "area", null } };
}

Note: ControllerName should not include the word Controller from [PluginName]Controller.cs

5. Implement Base Plugin Members as neccessary

You may want to implement a method from the base plugin. For example, given a that you set up a settings class for your plugin that implements ISettings like this:
public class [PluginName]Settings : ISettings
    {
        public bool Enabled { get; set; }
    }
You may want initialize settings or pepare NopCommerce in another way when the plugin is installed through NopCommerce Admin:
public override void Install()
{
    var settings = new [PluginName]Settings()
    {
        Enabled = true
    };
    _settingService.SaveSetting(settings);

    base.Install();
}

And to remove them when the plugin is uninstalled:

public override void Uninstall()
{
    _settingService.DeleteSetting<[PluginName]Settings>();

    base.Uninstall();
}

6. Implement further needed features and logic


Documentation and Notes by Lee Jones July-2017

results matching ""

    No results matching ""