Introduction
There are two approaches to customize nopCommerce to fit our needs. Plugin can be used to extend the functionality of nopCommerce. Theme can be used to define the look and feel of pages and controls.
nopCommerce has some built-in plugins. For example, payment methods (such as PayPal), tax providers, shipping method computation methods (such as UPS, USP, FedEx), widgets. There are many different plugins including free anc commercial ones in nopCommerce website. We can search plugins which suit our needs.
Basically, we create a class implements Nop.Core.Plugins.IPlugin interface to build our own plugin. nopCommerce also provides a BasePlugin class which already implements some IPlugin methods and simplify our development work.
Create a simple plugin
Here are major steps how to create our own plugin and add it to nopCommerce.
-
Create a new project > windows classic library. As convention, please select project-dir>Plugins as the location.
-
specify output dir to ....\Presentation\Nop.Web\Plugins\MyPlugins\
-
Add reference > nop.core
-
Create a plugin class, implements IPlugin interface
-
Add a plugin.json file
```` { "Group": "User Plugins", "FriendlyName": "Andy's Plugins", "SystemName": "MyPlugins", "Version": "1.00", "SupportedVersions": [ "4.00" ], "Author": "nopCommerce team", "DisplayOrder": 1, "FileName": "MyPlugins.dll", "Description": "This plugin just for demo pupose" } ```
-
make sure plugin.json always copy to compiled output directory:
right click plugin.json > properties > copy to output directory > always newer
or
open MyPlugins.csproj, specify we want to copy plugin.json to output directory
change
``` <ItemGroup> <None Include="plugin.json" /> </ItemGroup> ```
to
``` <ItemGroup> <Content Include="plugin.json"> <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory> </Content> </ItemGroup> ```
Here is the explanation (https://msdn.microsoft.com/library/0c6xyb66(v=vs.100).aspx):
None - the file is not included in the project output group and is not compiled in the build process. An example is a text file that contains documentation, such as a Readme file.
Content - The file is not compiled, but is included in the Content output group. For example, this setting is the default value for an .htm or other kind of Web file.
Compile - The file is compiled into the build output. This setting is used for code files.
-
Build the new plugin project, we will find the output dlls at: project-dir\Presentation\Nop.Web\Plugins\
-
Rebuild and start the web project
-
login as admin > administration > configuration > plugins > local plugins, we will find the new plugin
Also, nopCommerce provides some specific plugin interfaces derived from IPlugin. We can move on implementing them to build more plugins with customized appearance and advanced logic.
- External authentication methods - IExternalAuthenticationMethod interface
- Widgets - IWidgetPlugin interface
- Rxchange rate providers - IExchangeRateProvider interface
- Fiscount rules - IDiscountRequirementRule interface
- Payment methods - IPaymentMethod interface
- Shipping method computation methods - IShippingRateComputationMethod interface
- Tax providers - ITaxProvider interface
- Other plugins - IMiscPlugin interface
References
http://docs.nopcommerce.com/pages/viewpage.action?pageId=1442493
-
Previous
nopCommerce tutorial (2) increase file upload size -
Next
Entity Framework working with stored procedure