NOPCommerce 增加功能 颜色和尺码管理研究实现:
2012-02-25 14:13
375 查看
添加颜色和尺码管理菜单(配图是网友使用的Nop1.9修改的效果,本文是2.4 MVC架构下的):
打开Administration下面的Sitemap:
服装颜色:<siteMapNodetitle="Color attributes" nopResource="Admin.Catalog.Attributes.ColorAttributes"controller="ColorAttribute" action="List"/>
服装尺码:<siteMapNodetitle="Size attributes" nopResource="Admin.Catalog.Attributes.SizeAttributes"controller="SizeAttribute" action="List"/>
同步需要进行的事情:
1. 增加ResourceString: Admin.Catalog.Attributes.ColorAttributes=Color/”颜色”
2. Admin.Catalog.Attributes.SizeAttributes=Size/”尺码”
insert into LocaleStringResource
values(1,'Admin.Catalog.Attributes.ColorAttributes','Color Attribute')
insert into LocaleStringResource
values(1,'Admin.Catalog.Attributes.SizeAttributes','Size Attribute')
3. 增加Controller:
具体实现可以参考CheckoutAttributeController.cs
4. 增加Action:public ActionResultList()
{ returnView(); }
增加对应的Partial View
请注意以上只是架构并未实现实际代码,View也没有内容现实
后台的Mapping代码: Infrastructure\AutoMapperStartupTask.cs||MappingExtensions.cs
using Nop.Admin.Models.Snatches;
using Nop.Core.Domain.Snatches;
通过比对Model和Entity之间的差异:
//Snatch
Mapper.CreateMap<Snatch,SnatchModel>()
.ForMember(dest => dest.FriendlyName, mo => mo.MapFrom(src =>src.ProductVariant.Name));
Mapper.CreateMap<SnatchModel,Snatch>()
.ForMember(dest => dest.ProductVariantID, mo => mo.Ignore());
//以上方法会在IstartupTask中被调用到:
public static SnatchModel ToModel(thisSnatch entity)
{
return Mapper.Map<Snatch, SnatchModel>(entity);
}
public static Snatch ToEntity(thisSnatchModel model)
{
return Mapper.Map<SnatchModel, Snatch>(model);
}
public static Snatch ToEntity(thisSnatchModel model, Snatchdestination)
{
return Mapper.Map(model,destination);
}
颜色管理
接下来要填充点内容了,否则菜单点下去看到空白的View. MVC中先建立Model的类ColorAttributeModel:
namespace Nop.Admin.Models.Catalog public class ColorAttributeModel// public class BaseNopEntityModel : BaseNopModel { public virtual int Id { get; set; } } [NopResourceDisplayName("Admin.Catalog.Attributes.ColorAttributes.Fields.Name")] [AllowHtml] public string Name { get; set; } [NopResourceDisplayName("Admin.Catalog.Attributes.ColorAttributes.Fields.ColorImageUrl")] public stringColorImageUrl { get; set;}
ColorAttributeController,其中第一个需要完成可以测试的代码,Binding-List Action
public ActionResultList() { IList<ColorAttributeModel>activityColorAttributeModel=new List<ColorAttributeModel>(); activityColorAttributeModel.Add( new ColorAttributeModel(){ Name = "red", ColorImageUrl = "~/content/images/Green.png" } ); activityColorAttributeModel.Add( new ColorAttributeModel(){ Name = "black", ColorImageUrl = "~/content/images/Black.png" } ); var gridModel = new GridModel<ColorAttributeModel> { Data = activityColorAttributeModel, Total = activityColorAttributeModel.Count() }; return View(gridModel); }
View的主要代码,布局类似上截图:
<table class="adminContent"> <tr> <td> @(Html.Telerik().Grid<ColorAttributeModel>(Model.Data) .Name("colorattributes-grid") .Columns(columns=> { columns.Bound(x =>x.Name) .Width(300); columns.Bound(x =>x.ColorImageUrl) .Template( @<text> <img alt="@item.Id"src="@item.ColorImageUrl"/> </text> ) //通过Template和Link设置链接 .ClientTemplate("<imgalt='<#= Id #>' src='<#= ColorImageUrl #>' />"); columns.Bound(x =>x.Id) .Width(50) .Centered() .Template(x =>Html.ActionLink(T("Admin.Common.Edit").Text,"Edit", new{ id = x.Id })) .ClientTemplate("<a href=\"Edit/<#= Id#>\">" + T("Admin.Common.Edit").Text+ "</a>") .Title(T("Admin.Common.Edit").Text); }) //通过List Action绑定数据源 .DataBinding(dataBinding => dataBinding.Ajax().Select("List", "ColorAttribute")) .EnableCustomBinding(true)) </td> </tr> </table>
The URL is incorrectJ//所以如何获取正确的URL需要学习下?很简单,之前有目录service/Media/pictureservice,分析下:
关于图片的内容,由PictureService提供
public virtual stringGetDefaultPictureUrl(int targetSize = 0, PictureType defaultPictureType = PictureType.Entity) { ….. string relPath =_webHelper.GetStoreLocation() + "content/images/"+ defaultImageName; if(targetSize == 0) returnrelPath;
…..
vardefaultProductPicture = _pictureService.GetPicturesByProductId(product.Id,1).FirstOrDefault();
model.PictureThumbnailUrl= _pictureService.GetPictureUrl(defaultProductPicture, 75, true);
相关文章推荐
- NOPCommerce 增加功能 颜色和尺码管理研究实现<九>
- javascript实现后台图书管理增加、修改、删除功能
- 模块管理常规功能自己定义系统的设计与实现(22--第二个模块的增加)
- 学生管理系统初步实现增加功能
- c语言实现的货物管理系统实例代码(增加删除 查找货物信息等功能)
- Winform开发框架之参数配置管理功能实现-基于SettingsProvider.net的构建
- SysAid 9.0 发布,增加移动设备管理功能
- 使用easyui实现的添加公告功能(后台管理)
- java-第三章-升级我行我素购物管理系统,实现会员信息录入的功能
- 6.代理功能实现服务器批量管理功能
- 在ecshop 首页中实现增加刷选功能
- 项目实战篇-餐馆管理系统—MFC,PHP,MySql:2.登陆功能的实现
- 模块管理常规功能自定义系统的设计与实现(17--模块数据的导出和打印[2])
- php实现文件管理与基础功能操作
- 实现图片编辑软件的“填充颜色”功能
- Android app基于DownloadProvider实现下载管理功能
- 完成一个学生管理程序,使用学号作为键添加5个学生对象,并可以将全部信息保存在文件中,可以实现对学生信息的学号查找,输出全部学生信息的功能。
- python---名片管理(并对名片进行增、删、改、查、功能的实现)
- 用选择结构实现购物管理系统的部分功能
- node.js学习笔记——学生信息管理的实现(把功能模块化)使用官方提供的http模块实现