Altering Nopcommerce Code

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.
3 года назад
Working in nopcommerce for almost 6 months now and my team and I are really nervous about messing with the original nopcommerce code ( anything in Nop.Web  ) If we ever had to do it we would always mark a comment in the code with " // Nop Core Changes " so that later when Nopcommerce comes out with a new update it would be somewhat easy to identify what code we changed and why.

My question is should I be worried about altering the Original Code to meet my business needs? we are currently creating plugins/widgets to help get around messing with core code .. but it is getting frustrating and somewhat unmanageable...

I'm reaching out to my fellow Nopcommerce Developers what have you guys been doing ? what is the best practice?
3 года назад
It is highly recommended to NOT modify the original source code.  Plugins are definitely ideal for portability across multiple installations, but if it's just you and your team and 1 installation, or if plugins/widgets just do not suit your needs, then there numerous other ways to implement changes.  It really only depends on what you're trying to do.

Nearly every class is partial, so additional properties and methods are easy to add in a separate .cs file.  Or (in 4.3+) add to a domain entity with migrations:
https://docs.nopcommerce.com/en/developer/tutorials/update-existing-entity.html

You can override base methods through inheritance and register them higher with IDependencyRegistrar, or change the signature in your method and call it instead of the original (again, in separate .cs files).  

Create your own controllers and register their custom routes:
https://docs.nopcommerce.com/en/developer/tutorials/register-new-routes.html

You can create Consumers for dozens of published Events, as well as Entity Updated/Inserted/Deleted and OnModelCreating.
https://docs.nopcommerce.com/en/developer/tutorials/entity-event.html

If a specific Event doesn't already exist (or you don't want to create it), you can create Action Filters for intercepting controller actions before/after they execute:
https://docs.microsoft.com/en-us/aspnet/core/mvc/controllers/filters?view=aspnetcore-5.0

You can create your own settings:
https://docs.nopcommerce.com/en/developer/tutorials/settings.html

or your own background tasks:
https://docs.nopcommerce.com/en/developer/tutorials/scheduled-tasks.html

Modify any .cshtml View file and drop it in the appropriate matching directory in Themes, and it will be picked up after the original file.

The only limitation I've encountered is Enums (like OrderStatus) which can't be partial or inherited from.  Outside of that, the original source does not need to be touched.

If you post up an example of a few of your changes then the community can narrow in on the best practice for it pretty quickly.
3 года назад
I use a local git repository to track changes to my current source files for future upgrade modifications naming commits based on your current mods. Then planning on a new upgrade version you have the ability to see where your changes may need to be applied and if the new version source has changed significantly, your able to plan accordingly. Also using software like Beyond Compare can assist in the changes from version to version.
This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.