简体   繁体   English

定制 nopCommerce

[英]Customizing nopCommerce

We are developing an nopCommerce based application.我们正在开发一个基于 nopCommerce 的应用程序。 Our login page needs to be minimalistic and would need only an email id, password entry fields and a Login button.我们的登录页面需要简约,只需要一个 email id、密码输入字段和一个登录按钮。

Could you point me to best practices for achieving the above objective?您能否指出实现上述目标的最佳实践?

Do I modify the corresponding pages found in \Presentation\Nop.Web\Views\Customer\ & controllers in \Presentation\Nop.Web\Controllers\我是否修改 \Presentation\Nop.Web\Views\Customer\ 中的相应页面和 \Presentation\Nop.Web\Controllers\ 中的控制器

Or或者

Is there a better way of doing this and organizing all the modified files in one place/folder so that upgrading to future versions of nopCommerce will not be difficult?有没有更好的方法来做到这一点并将所有修改过的文件组织在一个地方/文件夹中,以便升级到 nopCommerce 的未来版本不会很困难?

The requirement is to ensure that all the changes made to the project(views/controllers etc) are in one folder so that they are not overwritten when we upgrade to a newer version of nopCommerce.要求是确保对项目(视图/控制器等)所做的所有更改都在一个文件夹中,这样当我们升级到更新版本的 nopCommerce 时它们不会被覆盖。

I read somewhere that you can copy stuff you need to change (Login.chtml, CustomerController) to Themes/DefaultClean and then make your changes in this folder.我在某处读到,您可以将需要更改的内容(Login.chtml、CustomerController)复制到 Themes/DefaultClean,然后在此文件夹中进行更改。 I dont remember where i read it.我不记得我在哪里读到的。

I feel doing so will make it that much easier to maintain our codebase because all your custom code is in one place/folder/sub folders我觉得这样做会使维护我们的代码库变得更加容易,因为您所有的自定义代码都在一个地方/文件夹/子文件夹中

Is this a best practise?这是最佳做法吗? And is there a disadvantage to this method of doing things?这种做事方法有缺点吗?

The best way to modify your nopCommerce project without changing anything in the core code would be to use the plugin functionality which is described here (assuming you're using the newest version 4.40).在不更改核心代码中的任何内容的情况下修改 nopCommerce 项目的最佳方法是使用此处描述的插件功能(假设您使用的是最新版本 4.40)。

To change the login page you would then need to create your modified version as a.cshtml file in your plugin.要更改登录页面,您需要在插件中将修改后的版本创建为 .cshtml 文件。 You then need to set this file as Content and set the Copy to Output Directory property to Copy if Newer or Copy Always.然后,您需要将此文件设置为内容并将Copy to Output Directory属性设置为 Copy if Newer 或 Copy Always。

You also need to implement the IViewLocationExpander interface so that the Razor Engine knows that it should use your custom Login Page.您还需要实现IViewLocationExpander接口,以便 Razor 引擎知道它应该使用您的自定义登录页面。 The implementation should look something like this:实现应该是这样的:

public class MyViewLocationExpander : IViewLocationExpander
{
   public IEnumerable<string> ExpandViewLocations(ViewLocationExpanderContext context, IEnumerable<string> viewLocations)
   {
      if(context.ViewName == "Login")
      {
         viewLocations = new[] { "PathToCustomLoginPage" }.Concat(viewLocations);
      }

      return viewLocations;
   }

   public void PopulateValues(ViewLocationExpanderContext context)
   {
      return;
   }
}

After that you also need to register your ViewExpander by implementing the INopStartup interface.之后,您还需要通过实现INopStartup接口来注册您的 ViewExpander。 The implementation would look something like this:实现看起来像这样:

public class MyStartup : INopStartup
{
   public int Order => int.MaxValue;

   public void Configure(IApplicationBuilder application)
   {
   }

   public void ConfigureServices(IServiceCollection services, IConfiguration configuration)
   {
      services.Configure<RazorViewEngineOptions>(options =>
      {
         options.ViewLocationExpanders.Add(new MyViewLocationExpander());
      });
   }
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM