How to compile nopCommerce plug-in

Source: Internet
Author: User
Tags live chat nopcommerce
Document directory
  • Plug-in structure, used file, location
  • Routing
  • Handle "installation" and "Uninstall" Methods
  • Summary

Plug-ins (also called addin, add-in, addon, or add-on) are computer programs that interact with applications, it is used to add some specific functions required for the application. (Wikipedia)

Plug-ins are used to expand nopCommerce functions. nopcommcer has multiple types of plug-ins. For example, paypal in the payment method, tax supplier, distribution calculation method (UPS, USP, Fedex), and small part (live chat function. NopCommerce itself also comes with many different plug-ins. You can search the official website for any plug-ins that have been uploaded to meet your needs. If you don't have one, you can write one with your hand.


Article Description: a self-source blog is translated based on the understanding of the original article, rather than the word-based translation style of the publishing house. You are welcome to give your comments. You are also welcome to repost this article, but you must note the original address of this article. For more articles about nopcommerce, please follow the /? Tag = nopcommerce, or join our QQ Group 101675096 plug-in structure, file used, location

1. The first thing you need to do is to create a new "class library" project in the solution. The best way is to put all the plug-ins in the solution root directory (but be careful not to match Nop. the plugins directory under the Web is mixed up, where plug-ins have been configured ), and it is best to put all the plug-ins in the plugin directory of the solution directory (for more information about the solution folder, click here)

It is best to Name it in this way: "Nop. Plugin. {Group}. {Name }". {Group} is the classification of your plug-ins (such as payment), {Name} is your plug-in Name (such as "AuthorizeNet"), then Authorize. NET payment plug-in will have such a name: Nop. plugin. payments. authorizeNet.

2. once a plug-in project is created, change the input path ".. \.. \ Presentation \ Nop. web \ Plugins \ {Group }. {Name} \ ", such as Authorize. NET payment plug-in will have such input path: ".. \.. \ Presentation \ Nop. web \ Plugins \ Payments. authorizeNet \". After this is done, the corresponding plug-in DLL will be copied to the \ Presentation \ Nop. Web \ Plugins \ folder, and the nopCommerce kernel will search for this folder.

A. Click properties in the project menu.
B. Select the generate tab.
C. Click Browse next to the input path to select an input directory.

You need to perform this step in both debug and release modes. the next step, create a description.txt file for each plug-in. This file contains information about the description plug-in. You can copy it from other plug-ins. For example, description.txt of the authorize.netpayment plug-in has the following content:

Group: Payment methods FriendlyName: Credit Card SystemName: Payments. authorizeNet Version: 1.00 SupportedVersions: 2.30 Author: nopCommerce team DisplayOrder: 1 FileName: Nop. plugin. payments. authorizeNet. you can understand all the dll information, but there are some precautions.SystemNameMust be unique. The Version field is the Version number of your plug-in. You can set it to any value you like.SupportedVersionsYou can include a list of versions that are separated by commas (, make sure that the current version of nopCommerce is included in this list; otherwise, this plug-in will be unavailable.FileNameThis format is used: Nop. Plugin. {Group}. {Name}. dll (the assembly file Name of your plug-in ). Make sure that the "Copy to input directory" attribute of this file is "Copy if newer"

4. The last step is to create a class to implement the IPlugin interface (Nop. Core. Plugins namespace ). NopCommerce's BasePlugin class has implemented some IPlugin methods, so you don't have to bother writing it again. NopCommerce also provides some interfaces derived from IPlugin. For example, the scheduler has the "IPaymentMethod" interface to create a new payment plug-in that contains some specific methods for payment, such as ProcessPayment () or GetAdditionalHandlingFee (). NopCommerce currently has the following specific plug-in Interfaces:
IExternalAuthenticationMethod. Used to establish external authentication methods such as Facebook, Twitter, OpenID, etc.
IWidgetPlugin. allows you to create widgets that appear in some places on your website, such as the Live chat box on the left.
IExchangeRateProvider. Used to obtain the currency exchange rate.
IDiscountRequirementRule. allows you to create new discount rules, such as "the country where the bill is sent must be ...... "
ISMSProvider. The SMS provider allows you to receive text message notifications when placing an order.
IPaymentMethod. Plug-in used to process the payment process.
IPromotionFeed. These plug-ins are used to provide product information to Froogle or PriceGrabber
IShippingRateComputationMethod .. These plug-ins are used to obtain available delivery methods and correct shipping fees. For example, UPS, UPS, and FEDEX.
ITaxProvider. Tax Rate provider is used to obtain the tax rate.

Process the request. Controllers, models, and views.

Now you can see our plug-ins in Admin area> Configuration> Plugins, but as you may think, the plug-in for this cup cannot be done, or even a Configuration interface does not exist. Now let's create a configuration page. What we need to do now is to create a controller, model, and view.

  1. The MVC Controller is responsible for responding to requests to an ASP. net mvc website. Each browser request is mapped to a specific controller.
  2. A view contains HTML tags and content sent to the browser. A view is a page equivalent to an ASP. net mvc application.
  3. An MVC model contains all application logic other than a view or controller.

Here you can find more information about the MVC mode.

So we can start:

Create a model. Add a Models folder to the new plug-in, and then add a new model class as needed.
Create a view. Add a new view folder in the plug-in project and add a {Name} folder in it. Here {Name} refers to your plug-in Name. Then add a Configure. cshtml file. It is important to note that this view is an embedded resource.
Create a controller. Add a new controller folder in the plug-in project and a new controller class. The best naming method is PaymentAuthorizeNetController, for example, {Group} {Name} Controller. cs. Name an action Method for configuration. Brother calls it "Configure ". Prepare a model class and pass it to this view: Nop. Plugin. {Group}. {Name}. Views. {Group} {Name}. Configure, that is, the embedded view. For example, you can implement PaymentAuthorizeNetController in the Authorize. NET payment plug-in.

Tip 1: copy the web. config file from other plug-in projects to your project. In this way, you can intelligently perceive the view (Old Ding: ah? Really? What does this have to do with copying files ?). Intelligent perception is Microsoft's Automatic completion highlight.

Tip 2: the simplest way to do this is to directly copy other plug-in projects and rename the files and folders.

Tip 3: If you want to restrict some action methods of the backend (shopkeeper) controller, you only need to add the [AdminAuthorize] attribute to the method.

Tip 4: Make sure that the "Copy to local" attribute referenced by all third-party assembly is set to false to reduce the size of the deployment package.

For example, the project structure of the Authorize. NET plug-in is as follows:


Now we need to register the corresponding route for the plug-in. ASP. NET routing is used to map requests sent by the browser to the action Method of the MVC controller. You will read a lot of detailed information about routing in the following steps.

1. Create the following file: RouteProvider. cs, which will inform nopcommerce about the plug-in routing information. For example, the following RouteProvider adds a new route, which can be accessed through the browser path

public partial class RouteProvider : IRouteProvider {         public void RegisterRoutes(RouteCollection routes)         {             routes.MapRoute("Plugin.Payments.AuthorizeNet.Configure",                  "Plugins/PaymentAuthorizeNet/Configure",                  new { controller = "PaymentAuthorizeNet", action = "Configure" },                  new[] { "Nop.Plugin.Payments.AuthorizeNet.Controllers" }             );         }         public int Priority         {             get             {                 return 0;             }         } }

2. Some close-up plug-in interfaces (as mentioned above) and "IMiscPlugin" interfaces have a method of "GetConfigurationRoute ". It should return a route for plug-in background configuration to the Controller. Implement the "GetConfigurationRoute" method of your plug-in to inform nopCommerce of the background route configuration of your plug-in. If your plug-in does not require background configuration, this method returns NULL, such as the following:

Public void GetConfigurationRoute (out string actionName,
Out string controllerName,
Out RouteValueDictionary routeValues)
ActionName = "Configure ";
ControllerName = "PaymentAuthorizeNet ";
RouteValues = new RouteValueDictionary ()
{"Namespaces", "Nop. Plugin. Payments. AuthorizeNet. Controllers "},
{"Area", null}

If you have this Configuration method, you can find a Configuration link in Admin> Configuration> Plugins after installing the plug-in.

Handle "installation" and "Uninstall" Methods

This is an optional step. Some plug-ins need some installation logic, such as adding some local resource data to the plug-in. In your IPlugin implementation (in most cases, it is inherited directly from the BasePlugin class), reload the following methods:

1. Install: This method is called during plug-in installation. You can initialize any settings here, add new local resource data or add new database tables (if needed)

2. Uninstall: This method is called when the plug-in is uninstalled.

Important: If you overload these methods, do not hide the implementation of the base class. For example, you need to call base. Install () When reload "Install". The install method of Authorize. NET is as follows:

Public override void Install ()
Var settings = new AuthorizeNetPaymentSettings ()
UseSandbox = true,
TransactMode = TransactMode. Authorize,
TransactionKey = 123 ″,
LoginId = 456 ″
_ SettingService. SaveSetting (settings );

Base. Install ();

Tip: the list of installed plug-ins can be found in \ App_Data \ InstalledPlugins.txt. This list is created during installation.

Updating nopCommerce may cause plug-ins to crash

Some plug-ins may fail to work in the new nopCommerce version. If you have any problems after the upgrade, please delete the plug-in and go to the nopCommerce official website to see if some versions of the plug-in have been downloaded. Most plug-ins will upgrade their plug-ins to the new version. However, a few plug-ins will not be upgraded along with the upgrade so that the new version is no longer supported. However, in most cases, you can open the corresponding Description.txt file and edit it.SupportedVersionsField.


I hope this article will allow you to start the nopCommerce plug-in journey and build an outstanding plug-in.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.