Default theme re-work approach.

2 weeks ago
Greetings,

I have a question regarding theme creation in nopCommerce. How should I organize the code and files? What are the best practices in this regard?

Here is my current state:

For an example in order to have different view for the register form,

- I have added a new Customer2Controller in the Controllers folder, part of the Nop.Web project that inherits the original CustomerController.
- By overridng the Register Action I am setting the path to my new Register form View.
- The View itself is in Themes->MyCustomThem->Views.
- Added new Route.

My only concern is for nopCommerce updates. Will this approach cause any issues?

2 weeks ago
savov wrote:
Greetings,
For an example in order to have different view for the register form,

- I have added a new Customer2Controller in the Controllers folder, part of the Nop.Web project that inherits the original CustomerController.
- By overridng the Register Action I am setting the path to my new Register form View.
- The View itself is in Themes->MyCustomThem->Views.
- Added new Route.

My only concern is for nopCommerce updates. Will this approach cause any issues?



Hi,
to customize the view files you don't have to override the controllers and the action method. You can simply create a new theme a. You can check the documentation on how to create a new theme from https://docs.nopcommerce.com/en/developer/design/new-theme.html

Nopcommerce's view engine, first searches the view file inside your active theme. If found, it will use the view file from the theme and if not then it will use the view file that is inside the Views folder(default views). You can customize the CSS and the view file inside the theme as you deem necessary.

While updating the NopCommerce you can simply use the same theme and make the necessary adjustments to make it compatible with the newer NopC version
2 weeks ago
Thank you very much for the prompt reply.

If I still need to inherit the CustomerController, let us say for creating different login/registration flow, but I still need the other logic that it exposes- where should I keep this new Customer2Controller?

I'd like to have it separate from core Nop Controllers. What us the accepted practice?

Thank you in advance.
2 weeks ago
If you want to make the NopCommerce version easy to upgrade in the future then I will recommend keeping all the override and customization in a new plugin and keep the NopC core code as intact as possible. This will add a couple of hours to your development hours but it will keep all the changes centralized in a single class library.

If you don't want to work with a plugin then you can add a new folder in Nop.Web (something like Extended) and keep all your custom changes inside the Extended folder maintaining the same folder hierarchy as it is inside Nop.Web (You can follow the same mechanism while overriding extending other class librariess like Nop.Core and Nop.Service and etc). This way, you can still track your custom changes in the future and will help with the upgrade.

You can override or extend almost everything in NopC because every class is partial and every method is virtual so personally, I think it will be better to not customize the core code coming out of the box with NopCommerce, if you want to make the NopC upgrade as easy as possible.
2 weeks ago
Thank you very much for your detailed reply. I will probably stick to the plugin approach. I'd really wouldn't want to make changes that would make upgrading difficult. I saw that the plugin controllers inherit different base controller(BasePluginController). I suppose it doesn't make much of a difference