Upgrading Plugins from nopCommerce 4.3 to 4.4

Upgrading nopCommerce plugins from version 4.30 to 4.40

  • 1. To start off, the latest update of Visual Studio (VS), version 2019, 16.9 needs to be downloaded. Here is a link for convenience: https://visualstudio.microsoft.com/downloads/. If the visual studio is already installed, then it is needed to open the visual studio installer and update the 2019 version only.
  • 3. After the project has been downloaded, the NopCommerce.sln file needs to be opened from the src folder.

nopCommerce plugin upgrade part 2

  • 4. Now the plugins need to be added to the project from the plugin folder. The required plugin folder must be inside the same project folder. It is the best practice to add the plugins one by one and debug them for NopCommerce 4.4.
  • 5. First of all, the target plugin’s project folder needs to be placed in the “src/Plugins” directory. Then from the solution explorer of the Visual Studio, the Plugins folder needs to be right clicked, an existing project needs to be added and the Plugin moved that has just been moved should be chosen. Here, an in-house plugin of Nop Station named NopStation-Ocarosels has been used as an example.

nopCommerce plugin upgrade part 3 nopCommerce plugin upgrade part 4 nopCommerce plugin upgrade part 5 nopCommerce plugin upgrade part 6

  • 6. After the Project has been loaded, open the “.csproj” file of the project by double clicking on the project. Here the Target Framework must be changed to “net5.0”. Inside the Plugin folder, there should be a plugin.json file. The file should be opened and the Supported Version field must be updated to 4.40.

nopCommerce plugin upgrade part 7nopCommerce plugin upgrade part 8nopCommerce plugin upgrade part 9nopCommerce plugin upgrade part 10

  • 7. After changing the Target Framework and building the plugin, there should be errors in the “.cs” files. Each of the “.cs” files can be opened and the errors can be fixed one by on. Or another way to list all the errors is to build the Project and let the IDE detect all the error. The errors should be showing up at the output box below, click on each of them and go directly to the file and line containing the errors. A folder for the required plugin should appear in the shown directory after building the plugin.

nopCommerce plugin upgrade part 11nopCommerce plugin upgrade part 12nopCommerce plugin upgrade part 13

  • 8. Most of the errors we will be because of missing methods. Many of the functions existing in NopCommerce 4.3 do not exist in the core library anymore. It’s because, on its core, the NopCommerce Platform uses the Nop.Core, Nop.Services and Nop.Data. The libraries have been upgraded to use net5.0 as target framework and as a result, many of the functions that existed before had been changed to asynchronous functions. To indicate that the functions are asynchronous, the name of the functions now end with the word “Async.” As the name of the methods have been changed, the definition of the old functions no longer exists in the library. So, in order to develop plugins for NC 4.4, the functions used must be changed. In most cases, adding the word “Async” at the end of the missing functions will be able to detect the new ones.

nopCommerce plugin upgrade part 14

  • 9. Now that Asynchronous methods are being used, “System.Threading.Tasks'' must be imported and from there the Task<> class to use with the asynchronous methods should be found. The Asynchronous functions return a Task<T> and the methods are waitable. By using the “await” keyword in front of a method that returns a Task<T>, the desired object T returned should be found.

nopCommerce plugin upgrade part 15

This programming method enables us to read the program as a sequence of statements like before, but the compiler executes these codes in a much more complicated manner. Asynchronous tasks are running in a concurrent manner using parallel-processing, so they are utilizing the CPU more efficiently and, in many times, these programs are executed faster than synchronous programs. By using Tasks, we are actually executing multiple instructions parallelly. But it is required to use the result of the Tasks in a synchronous manner and this is where the “await” keyword comes in. By using await we allow the Task to start without blocking a single thread and then wait for the execution to complete to get the result. 

  • 12. To use the await keyword inside a function or lambda expression, the async keyword before the name of the function or the parameter of the lambda expression should be used.
  • 13. In Plugin’s services folder, existing services of type Task<> should be used and debug the code again to fix the methods that use these services.
  • 14. Some of the old existing Classes and Interfaces no longer exist in the Nop libraries. In that case, look around in the other places to check if the Class or Interface looking for has been moved to other libraries or not. If yes then import the new namespace and remove the old one.
  • 15. The implementation of the IDependencyRegistrar interface has been changed significantly. So, if the plugin has a DependencyRegistrar inside the Infrastructure folder, update the register function. Here the Autofac library used before are no longer used, Microsoft.Extensions.DependencyInjection for the IServiceCollection needs to be imported and remove the Autofac import. Inside the method body of register, the old ones should be changed as follows:

services.AddScoped<InterfaceName, ClassName>();

  • 16. As the NopCommerce 4.4 is still new, there aren’t many resources available on the internet on new plugin development methods. So, it is necessary to look into the implementation of the plugins provided by the NopCommerce Team which comes with the NopCommerce 4.4 in the Plugins folder. Many of the implementations of those Plugins will guide us on coding the new functions in net5.0.
  • 17. Finally, the Plugin should be built and run the Visual Studio Project when there are no errors. After the NopCommerce Platform loads, go to the administration and enable the required plugin and restart the application.

nopCommerce plugin upgrade part 16nopCommerce plugin upgrade part 17

  • 18. After restarting, the site may break and some errors will show up on the browser and indicating the .cshtml files have some errors. Then it is necessary to go to the .cshtml file and the errors which are almost always caused by missing functions are needed to be fixed. Changing the functions name to end with Async and adding an await keyword before the return value will solve this error.
  • 19. If no further errors exist, the website should load up nicely with our newly added plugin. Now move on to the next plugin and repeat the steps. 

 

Leave your comment
Only registered users can leave comments.
card icon