一:分类用现有技术怎么实现?

实际就是创建 Query 和 Projection,如果不知道怎么做,参考:Orchard之在前台显式一个属于自己的列表(在这篇里,还进行了稍稍拓展),当然,基础的知道,我们可以参考 Orchard 相关文档,不难。

1.1 当前这种模式的缺点

这种模式的缺点就是,你要么查询 Book ,要么查询 DVD,

不能查询全部的 Product,这样一来,我们又要自己写代码了。

二:更新 Module.txt

因为我们的模块依赖一个特性, Orchard.Projections,所以,修改为:

name: tminji.shop
antiforgery: enabled
author: tminji.com
website: http://www.tminji.com
version: 1.0.0
orchardversion: 1.0.0
description: The tminji.com module is a shopping module.
Dependencies: Orchard.Projections
features:
    shop:
        Description: shopping module.
        Category: ASample

三:创建 Filter

然后,

1:增加 Filters 文件夹;

2:创建 ProductPartFilter.cs,如下:

using Orchard.Localization;
using Orchard.Mvc.Filters;
using Orchard.Projections.Descriptors.Filter;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using TMinji.Shop.Models;

namespace TMinji.Shop.Filters
{
    public class ProductPartFilter : Orchard.Projections.Services.IFilterProvider
    {
        public Localizer T { get; set; }

public ProductPartFilter()
        {
            T = NullLocalizer.Instance;
        }

public void Describe(DescribeFilterContext describe)
        {
            describe.For(
                "Content",          // The category of this filter
                T("Content"),       // The name of the filter (not used in 1.4)
                T("Content"))       // The description of the filter (not used in 1.4)

// Defines the actual filter (we could define multiple filters using the fluent syntax)
                .Element(
                    "ProductParts",     // Type of the element
                    T("Product Parts"), // Name of the element
                    T("Product parts"), // Description of the element
                    ApplyFilter,        // Delegate to a method that performs the actual filtering for this element
                    DisplayFilter       // Delegate to a method that returns a descriptive string for this element
                );
        }

private void ApplyFilter(FilterContext context)
        {

// Set the Query property of the context parameter to any IHqlQuery. In our case, we use a default query
            // and narrow it down by joining with the ProductPartRecord.
            context.Query = context.Query.Join(x => x.ContentPartRecord(typeof(ProductPartRecord)));
        }

private LocalizedString DisplayFilter(FilterContext context)
        {
            return T("Content with ProductPart");
        }
    }

}

现在,在后台,就可以看到这个 Filter 了,如下:

现在,我们增加这个 filter,就可以得到结果了,如下:

我们添加 Projection(不再赘述),然后在前台显式出来:

四:内容呈现(Dispaly)

但是,我们发现一个问题,就是 Price 和 SKU 并没有呈现出来,包括我们点击 More ,也并没有出现这些我们的核心数据。

还记得什么没有,我们在后台创建 Book 或者 DVD 的时候,一开始根本没有保存上,是因为我们没有在 Driver 中存在返回 DriverResult 的方法,以及定义对应的 cshtml 文件,现在,让我们来完成这件事情。

首先,修改 ProductPartDriver 类,增加方法:

protected override DriverResult Display(ProductPart part, string displayType, dynamic shapeHelper)
{
    return ContentShape("Parts_Product", () => shapeHelper.Parts_Product(
            Price: part.UnitPrice,
            Sku: part.Sku
        ));
}

前台在呈现含有 ProductPart 的页面的时候,会调用这个 Display 方法。根据这个方法,我们知道,创建了一个 Parts_Product 的 shape,它对应的 cshtml 文件是:

Views/Parts/Product.cshtml

现在,我们来创建这个文件:

@{
    var price = (decimal)Model.Price;
    var sku = (string)Model.Sku;
}
<article>
    Price: @price<br />
    Sku: @sku
</article>

然后,记住,修改我们的 placement.info:

<Placement>
  <Place Parts_Product_Edit="Content:1" />
  <Place Parts_Product="Content:0" />
</Placement>

大功告成,见:

参考:http://skywalkersoftwaredevelopment.net/blog/writing-an-orchard-webshop-module-from-scratch-part-1

转载于:https://www.cnblogs.com/luminji/p/3858977.html

Orchard模块开发全接触3:分类的实现及内容呈现(Display)相关推荐

  1. 物联网国赛LORA模块开发基础教程(通用库)—传感器

    LORA模块开发基础教程目录 物联网国赛LORA模块开发基础教程-开发环境配置 物联网国赛LORA模块开发基础教程-输出(LED) 物联网国赛LORA模块开发基础教程-输入(按键) 物联网国赛LORA ...

  2. 【转载】10种无线技术全接触

    10种无线技术全接触(转载) 这里列举出10种重要的能够完善无线应用程序的技术 ·之一:WAP技术 ·之二:移动标示语言 ·之三:多模式标示语言 ·之四:短信传送 ·之五:SyncML ·之六:802 ...

  3. FPGA开发全攻略——概念篇

    原文链接: FPGA开发全攻略连载之一:FPGA为什么这么热? FPGA开发全攻略连载之二:为什么工程师要掌握FPGA开发知识? FPGA开发全攻略连载之三:FPGA基本知识与发展趋势(part1) ...

  4. 搭建基于ASP.NET 2.0的DNN 4.X模块开发环境及模块实例(2)

    群里一直有朋友在问如何构建基于ASP.NET 2.0的DNN 4.X模块开发环境,受原来ASP.NET1.1多工程机制的思维影响,大家一直在等待VS2005支持多工程,经过一段时间的学习和摸索,发现其 ...

  5. C#,深入浅出全接触

    C#,深入浅出全接触青苹果工作室(编译)目 录 表一.什么是C#?二.Java与C# 三.C#的主要特征四.安装运行环境五.C#编辑器六.C#的程序结构七.C#和名称空间八.C#中一个经典例程的编写与 ...

  6. Julia 学习笔记(五) | 模块开发 - 保姆级教程

    唠唠闲话 今年参与了 OSPP'22 的 Julia 开源项目,期间学习了 Julia 模块从开发到测试的完整过程.借这个机会,整理这段时间学习到的知识.Julia 在开发提供的工具便捷丰富,且对新人 ...

  7. 02-Maven高级-分模块开发、依赖传递、聚合、继承(SpringBoot的部分底层原理)、多模块开发(环境切换)、Nexus私服搭建与使用

    文章目录 学习目标 一.分模块开发与设计 1. 分模块开发的意义 问题导入 模块拆分原则 2. 分模块开发(模块拆分) 问题导入 2.1 创建Maven模块 2.2 书写模块代码 2.3 通过mave ...

  8. 一文解锁华为云新技能-AIOT开发全流程【设备接入-ESP端侧数据收集[MQTT]-实时数据分析】(步步截图较详细)

    一文解锁华为云新技能-AIOT开发全流程[设备接入-ESP端侧数据收集[MQTT]-实时数据分析](步步截图较详细) 在这篇你将会接触到:从物联网工程师从硬件层-通信层到应用层全流程:开发华为云最基本 ...

  9. 六款最主流的免费网络嗅探软件全接触

    六款最主流的免费网络嗅探软件全接触 要如何才能找到网络传输的性能瓶颈?要如何才能快速定位已经失效了的网络设备?以及要如何才能迅速找到网络病毒(一种具有隐蔽性破坏性传染性的恶意代码)传播或拒绝服务*** ...

最新文章

  1. Jenkins进阶系列之——01使用email-ext替换Jenkins的默认邮件通知
  2. python十:字典(dict)
  3. python语言 行业_如何入门编程开发行业 选择Python语言怎么样
  4. Hibernate的检索策略
  5. python 基类 派生类_在Python中具有两个子(派生)类的继承示例
  6. greenplum 替代mysql_转:MySQL到Greenplum迁移分析
  7. 果园机器人反思稿_《果园机器人》教学反思
  8. php单图上传并预览,JavaScript实现单图片上传并预览功能
  9. vector常见用法
  10. spark pineline流水线+聚类评估函数 小结
  11. 项目实施流程和规范模板(测试方向)
  12. swarm 集群配置
  13. 开源博客网站搭建之Catfish
  14. G代码表《G代码大全》
  15. python爬取谷歌学术_对于python抓取google搜索结果的一些了解
  16. 网站推广优化教程100条(完整版)-
  17. 瑞利 随机 matlab,matlab产生瑞利分布随机信号
  18. QThread 结束后,不发射Finished问题
  19. 云计算企业级小架构部署应用综合练习-docker变种(一)
  20. Flutter 安装包体积优化

热门文章

  1. .net中使用反射的简单例子
  2. Linux系统管理工具-iostat、free、ps、netstat、tcpdump
  3. 《Cacti实战》——3.1 检索流程
  4. BZOJ1295 [SCOI2009]最长距离
  5. Linux命令 swap:内存交换空间
  6. ZooKeeper集群安装
  7. linux下Redis以及phpredis扩展安装
  8. ganglia metric 默认监控项翻译
  9. SpringCloud成长之路 一 注册与发现(Eureka)
  10. BZOJ1833:[ZJOI2010]数字计数——题解