Create nopCommerce PlugIn

 

Create nopCommerce PlugIn

 

What is plug in?

 

  •           Change behaviour or functionality of NopCommerce.
  •           Reusable package of a code that can be distributed to other store.

 

 

Plugin Components:

 

  •          Main plugin class
  •          Description file
  •          Domain and data context classes
  •          Dependency resolver
  •          Controllers, Views, CSS, Javascript
  •          Services

 

Types of plugin

 

  •         Payment Method
  •          Widget
  •          Shipping Method
  •           External Authentication
  •           Tex Provider
  •           Discount Calculator
  •           Exchange Rate

 

 

     Step 1: Open NopCommerce solution in visual studio and Add new class library project in plug in folder. Like: Nop.Plugin.Widget.YourPluginName

Here: Nop.Plugin.Widget(Plugin type).Promoslider(plugin name)

 

 Step 2 :Delete UN necessary class files Created by visual studio.

 

Step 3  Add Description.txt and web.config file

 Description.txt

Description: Group Name (Type of plugin)

Friendly Name; Name of plugin

Systemname: Widget.Promoslider

Version: 1.0 (Plugin version)

Supportedversion: Nopcommerce supported version, comma separated for multiple

Author: name of author

Filename: name of final output dll

 

Step 4 : Change Properties

 

  •  Right click on project and go to properties and change version of .net framework to 4.5.1
  •  Again go to properties and Change output path  (make same as other plugin)  just change name of your plug in

 

   ..\..\Presentation\Nop.Web\Plugins\Widgets.YourPluginName\

 

Step 5 : Add References

o   System.web from system

o   MVC System.Web.Mvc.dll from

~ \packages\Microsoft.AspNet.Mvc.5.2.2\lib\net45

o   nop.core.dll: ~\Libraries\ Nop.Core\bin\Debug

o   nop.data.dll: ~\Libraries\ Nop.data \bin\Debug

o   nop.services.dll: ~\Libraries\ Nop. services\bin\Debug

o   Nop.Web.Framework.dll from

~\Presentation\Nop.Web.Framework\bin\Debug

o   Nop.web

o   EntityFramework.dll

~\packages\EntityFramework.6.1.1\lib\net45

-                    o  Autofac and Autofac.Mvc   

 

Step 6: Create main plugin file

public class PromoSliderPlugin : BasePlugin, IWidgetPlugin, IAdminMenuPlugin

      {   

       // Code              

}

           Add using Statement

             using Nop.Core.Plugins;

using Nop.Services.Cms;

using Nop.Services.Common;

using System.Web.Routing;

 

·         GetConfigurationRoute() – this is required by IMiscPlugin. In the nopCommerce admin area, under Configuration / Plugins, some of the plugins in the list have a ‘Configure’ button. This method defines the route for this button

·         Install() – Any code that needs to be run when the plugin is installed should go here. The includes the base.Install() method call.

·         Uninstall() – Any code that needs to be run when the plugin is uninstalled should go here. The includes the base.Uninstall() method call.

·         GetDisplayWidgetRoute

·         GetWidgetZones

 

 

public void GetConfigurationRoute(out string actionName, out string controllerName, out RouteValueDictionary routeValues)

{

    actionName = "Index";

    controllerName = "Configuration";

 

    routeValues = new RouteValueDictionary();

    routeValues["NameSpaces"] = "Nop.Plugin.Widgets.MyPlugin.Controllers";

    routeValues["area"] = null;

}

 

public IList GetWidgetZones()

{

    return new List() { "home_page_top" };

}

 

public void GetDisplayWidgetRoute(string widgetZone, out string actionName, out string controllerName, out RouteValueDictionary routeValues)

{

    actionName = "Index";

    controllerName = "Widget";

    routeValues = new RouteValueDictionary()

    {

        {"Namespaces", "Nop.Plugin.Widgets.MyPlugin.Controllers"},

        {"area", null},

        {"widgetZone", widgetZone}

    };

}

 

public override void Install()

{

    base.Install();

}

 

public override void Uninstall()

{

    base.Uninstall();

}

    

Step 7: Create controllers for the widget and configuration elements

 

View("Nop.Plugin.Widget.MyPlugin.Views.Configuration.Index");

 

Step 8:Create view and Build