预期效果:

Customer表新增一个Column

该新增字段可以在Admin段 新增 修改 列表查询及显示

示例步骤:

0.数据库表修改

alter table [Customer] add MemberType nvarchar(2) ;

1.Entity处理

Libraries\Nop.Core\Domain\Customers\Customer.cs

仿照 Username 新增

/// <summary>

/// Gets or sets the Member Type

/// </summary>

public string MemberType { get; set; }

2.EntityMap处理

Libraries\Nop.Data\Mapping\Customers\CustomerMap.cs

新增

this.Property(u => u.MemberType).HasMaxLength(2);

3.EntityModel处理

Presentation\Nop.Web\Administration\Models\Customers\CustomerModel.cs

仿照 GenderEnabled 及 Gender 新增

//可以不增加MemberTypeEnabled

//如需该设置的控制 可 NopCommerce 增加 Customer Settings

public bool MemberTypeEnabled { get; set; }

[NopResourceDisplayName("Admin.Customers.Customers.Fields.MemberType")]

[AllowHtml]

public string MemberType { get; set; }

4.增修页面

Presentation\Nop.Web\Administration\Views\Customer\_CreateOrUpdate.cshtml

仿照 @if (Model.CompanyEnabled) 新增

@if (Model.MemberTypeEnabled)

{

<div class="form-group">

<div class="col-md-3">

@Html.NopLabelFor(model => model.MemberType)

</div>

<div class="col-md-9">

@Html.NopEditorFor(model => model.MemberType)

@Html.ValidationMessageFor(model => model.MemberType)

</div>

</div>

}

5.新增操作

Presentation\Nop.Web\Administration\Controllers\CustomerController.cs

进入页面时 Model准备

修改 protected virtual void PrepareCustomerModel 的Action

新增 model.MemberTypeEnabled = _customerSettings.MemberTypeEnabled;

新增操作保存时 Post处理

修改 public ActionResult Create(CustomerModel model, bool continueEditing, FormCollection form)

的  var customer = new Customer

新增 MemberType = model.MemberType,

6.修改操作

Presentation\Nop.Web\Administration\Controllers\CustomerController.cs

进入页面时 Model准备

修改 protected virtual void PrepareCustomerModel 的Action

if (customer != null) 分支下

新增  model.MemberType = customer.MemberType;

修改操作保存时 Post处理

修改 public ActionResult Edit(CustomerModel model, bool continueEditing, FormCollection form)

仿照 username 新增

//MemberType

if (_customerSettings.MemberTypeEnabled )

{

customer.MemberType = model.MemberType;

}

7.列表页面 列表显示

Presentation\Nop.Web\Administration\Models\Customers\CustomerListModel.cs

仿照  ZipPostalCodeEnabled 新增

public bool MemberTypeEnabled { get; set; }

列表显示

Presentation\Nop.Web\Administration\Views\Customer\List.cshtml

$("#customers-grid").kendoGrid

仿照 @if (Model.CompanyEnabled) 新增

@if (Model.MemberTypeEnabled)

{

<text>{

field: "MemberType",

title: "@T("Admin.Customers.Customers.Fields.MemberType")",

width: 200

},</text>

}

其 $("#customers-grid").kendoGrid 的 url: "@Html.Raw(Url.Action("CustomerList", "Customer"))",

Presentation\Nop.Web\Administration\Controllers\CustomerController.cs

对应的  protected virtual CustomerModel PrepareCustomerModelForList(Customer customer)

return new CustomerModel 增加 MemberType = customer.MemberType,

8.列表页面 新增查询条件

1).Model处理

Presentation\Nop.Web\Administration\Models\Customers\CustomerListModel.cs

仿照 SearchZipPostalCode  新增

[NopResourceDisplayName("Admin.Customers.Customers.List.SearchMemberType")]

[AllowHtml]

public string SearchMemberType { get; set; }

2).Service处理

Libraries\Nop.Services\Customers\ICustomerService.cs

IPagedList<Customer> GetAllCustomers

增加查询参数 string memberType=null,

Libraries\Nop.Services\Customers\CustomerService.cs

public virtual IPagedList<Customer> GetAllCustomers

增加查询参数 string memberType=null,

及仿照 username 增加其Linq过滤

if (!String.IsNullOrWhiteSpace(memberType))

query = query.Where(c => c.MemberType.Contains(memberType));

3).Controller Action 处理

Presentation\Nop.Web\Administration\Controllers\CustomerController.cs

public ActionResult CustomerList(

var customers = _customerService.GetAllCustomers( 中 新增

memberType:model.SearchMemberType,

4).页面处理

Presentation\Nop.Web\Administration\Views\Customer\List.cshtml

仿照 @if (Model.ZipPostalCodeEnabled) 新增

@if (Model.MemberTypeEnabled )

{

<div class="form-group">

<div class="col-md-4">

@Html.NopLabelFor(model => model.SearchMemberType)

</div>

<div class="col-md-8">

@Html.NopEditorFor(model => model.SearchMemberType)

</div>

</div>

}

js查找及新增SearchMemberType

$("".concat("#@Html.FieldIdFor(model => model.SearchEmail),",

"#@Html.FieldIdFor(model => model.SearchUsername),",

"#@Html.FieldIdFor(model => model.SearchMemberType),",

js查找及新增SearchMemberType

function additionalData() {

var data = {

SearchCustomerRoleIds: $('#@Html.FieldIdFor(model => model.SearchCustomerRoleIds)').val(),

SearchEmail: $('#@Html.FieldIdFor(model => model.SearchEmail)').val(),

SearchMemberType: $('#@Html.FieldIdFor(model => model.SearchMemberType)').val(),

9.增加文本资源

运行站点

Admin -> Configuration -> Languages -> Edit

-> String resources -> Add new record

Admin.Customers.Customers.Fields.MemberType

Admin.Customers.Customers.List.SearchMemberType

10.解决方案 Clean 和 Rebuild

运行站点 查看效果

NopCommerce 增加 Customer Field的更多相关文章

  1. NopCommerce 增加 Customer Settings

    预期: 仿照Customer 的 Phone number enabled 和 required 增加MemberType 相关步骤如下: 1.运行站点 Admin -> Settings -& ...

  2. NopCommerce 增加 Customer Attributes

    预期: Customer 新增一个自定义属性 运行站点 1.Admin -> Settings -> Customer settings -> Customer form field ...

  3. 如何为Rails作贡献:例增加rich_text field generators

    如何为Rails作贡献 例增加rich_text field generators 下载https://github.com/rails/rails 打开atom,在 rails/railties/l ...

  4. [转]教你一招 - 如何给nopcommerce增加新闻类别模块

    本文转自:http://www.nopchina.net/post/nopchina-teach-newscategory.html nopcommerce的新闻模块一直都没有新闻类别,但是很多情况下 ...

  5. [转]教你一招 - 如何给nopcommerce增加一个类似admin的area

    本文转自:http://www.cnblogs.com/wucf2004/p/nopcommerce-area.html asp.net mvc里面的area是什么,点击这里查看 如果在nopcomm ...

  6. NopCommerce 关于Customer的会员类别及会员价处理 的尝试途径

    示例效果: 当Customer是某个会员级别或内部员工时, 购物结算时享受一定的折扣: 相关设定如下: Step1.新增会员类别    Admin - Customers - Customer rol ...

  7. 教你一招 - 如何给nopcommerce增加一个类似admin的area

    asp.net mvc里面的area是什么,点击这里查看 如果在nopcommerce里面加入类似admin的area,步骤如下: 1.新建一个mvc空项目MvcApplication1,位置放在\N ...

  8. openerp 经典收藏 Openerp开发进销存系统完毕总结(转载)

    原文地址:http://blog.csdn.net/heartrude/article/details/9142463 Openerp开发进销存系统完毕总结 分类: 代码历程 OpenERP 工程思想 ...

  9. mysql中的sql

    变量 用户变量: 在用户变量前加@ 系统变量: 在系统变量前加@@ 运算符 算术运算符有: +(加), -(减), * (乘), / (除) 和% (求模) 五中运算 位运算符有: & (位于 ...

随机推荐

  1. 在c#中get同步访问http

    参照文章:http://blog.csdn.net/qianmenfei/article/details/37974767 public static string SendMessage(strin ...

  2. iOS学习笔记——AutoLayout的约束

    iOS学习笔记——AutoLayout约束 之前在开发iOS app时一直以为苹果的布局是绝对布局,在IB中拖拉控件运行或者直接使用代码去调整控件都会发上一些不尽人意的结果,后来发现iOS在引入了Au ...

  3. Visual Studio 2015在.NET Core RC2项目中的一个错误。

    更新了.NET Core RC2 之后,VS的Web Tools更新为“Preview 1”了. 这个版本有一个问题,害我折腾了一个下午. 就是在项目界面的“依赖项 - NPM”上面错误地显示了不必要 ...

  4. jquery css事件编程 尺寸设置

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...

  5. Java时间和时间戳的相互转换

    时间转换为时间戳: /* * 将时间转换为时间戳 */ public static String dateToStamp(String s) throws ParseException{ String ...

  6. No.021:Merge Two Sorted Lists

    问题: Merge two sorted linked lists and return it as a new list. The new list should be made by splici ...

  7. Javaweb学习笔记——使用Jdom解析xml

    一.前言 Jdom是什么? Jdom是一个开源项目,基于树形结构,利用纯java的技术对XML文档实现解析,生成,序列化以及多种操作.它是直接为java编程服务,利用java语言的特性(方法重载,集合 ...

  8. Lind.DDD敏捷领域驱动框架~Lind.DDD各层介绍

    回到目录 Lind.DDD项目主要面向敏捷,快速开发,领域驱动等,对于它的分层也是能合并的合并,比之前大叔的框架分层更粗糙一些,或者说更大胆一些,在开发人员使用上,可能会感觉更方便了,更益使用了,这就 ...

  9. Android打造属于自己的数据库操作类。

    1.概述 开发Android的同学都知道sdk已经为我们提供了一个SQLiteOpenHelper类来创建和管理SQLite数据库,通过写一个子类去继承它,就可以方便的创建.管理数据库.但是当我们需要 ...

  10. Python聊天室

    小编心语:锵锵锵!各位看官注意了啊,走过路过表错过!上篇博文主要介绍了基于基于Server-Sent Event的简单在线聊天室,相信不管各位是大牛.小牛还是跟小编一样的小白,可能觉得看得不够过瘾,区 ...