Enterprise Framework

Software Solutions in the Enterprise

NopCommerce Plugin Best Practices

NopCommerce Plugin Best Practices

NOTE:  DRAFT IN PROGRESS

Versions:    3.7

What are NopCommerce Plugins?

  • NopCommerce plugin are components that can extend the core NopCommerce E-Commerce platform.
  • NopCommerce Plugins can be used to add, extend or replace features within NopCommerce
  • NopCommerce Plugins are mini MVC components, it can use Controllers, Views, Routes, Models, and JavaScript that you would typically include within a ASP.NET MVC App.
  • NopCommerce Plugins are registered within NopCommerce dynamically and then installed through configuration for use within your NopCommerce application.

What types of NopCommerce Plugins can you create?

  • Admin Plugin - Allow you create new screens for use on the Admin page or even replace existing Admin features.
  • Retail Product Plugin - Allows you create new screens or overwrite existing retail product page features
  • Checkout Plugin - Allows you add to checkout or replace existing checkout.
  • Web Service Plugin - Create a RESTful Web API end point.
  • Mixed plugin - A combination of plugins for use in your NopCommerce site.
  • more...

What are the advantages of using a Plugin
  • A isolated set of features that are distribute-able (Assuming you kept references clean)
  • A isolated set of features that aren't impacted by a NopCommerce upgrade (hopefully)
  • You can replace NopCommerce endpoint calls and replace it with a custom one in your plugin.
  • Easy way to add non-core tables to the system

What are the dis-advantages of using a Plugin

  • Replacing the Checkout process with a plugin is probably not the greatest idea.
  • No Referential Integrity against existing Nop tables
  • Plugins that intercept core NopCommerce endpoints can become a maintenance nightmare.
 
Custom Plugin development challenges. 

You should follow these rules to try and minimize work

  1. Use the same Nuget package versions across all projects.  Follow NuGet Best Practices.  By not managing NuGet Packages correct could result in weird behaviors in your application.
  2. DO NOT checkin the NuGet package into source control.
  3. No not directly reference DLL's in the Packges folder, use the NuGet to include
  4. Your plugin should encapsulate all the logic required to operate
  5. Minimize changes to the core NopCommerce code base
  6. Controllers should be responsible for hydrating the current session/request and then passing that information down to helper services.
  7. Controllers should not contain your business logic because it's hard to test
  8. Services that contain logic should not be aware of HTTP Context and Session.
  9. Minimize size of methods (SOLID principle)
  10. Using a Plugin to override the Checkout Workflow is a complex task and should be a last resort.

Custom Plugin Endpoints

  • Do NOT start custom route End Points with the word Admin
routes.MapRoute("Plugins.MyCompany.Admin.Product.List",
     "Admin/MyPlugin/Product/List",
     new { controller = "MyProduct", action = "Admin" },
     new[] { "MyCompany.Plugin.Misc.PluginName.Controllers" }
);
  • Start custom routes End Points with the word Plugins
routes.MapRoute("Plugins.MyCompany.Admin.Product.List",
     "Plugins/MyPlugin/Product/List",
     new { controller = "MyProduct", action = "Admin" },
     new[] { "MyCompany.Plugin.Misc.PluginName.Controllers" }
);

Base Plugin Folder and File Structure

  • \Content
  • \Controllers
  • \Extensions
  • \Infrastructure
  • \Models
  • \Scripts
  • \Services
  • \Validators
  • \Views
  • \Sql
  • Description.txt
  • Logo.png
  • Notes.Txt
  • packages.config
  • RouteProvider.cs

Routes



Resources

Comments are closed