You are on page 1of 10

4/10/2015 IDeliverable 

­ Writing an Orchard Webshop Module from scratch ­ Part 3

Writing an Orchard Webshop


Module from scratch - Part 3
orchard (/Tags/orchard)

This post has been updated to be compatible for Orchard >= 1.4.

updated to be compatible for Orchard >= 1.4.

This is part 3 of a tutorial on writing a new Orchard module from scratch.


For an overview of the tutorial, please see the introduction (writing-an-orchard-webshop-module-
from-scratch-part-1).

In Orchard, a module is really just an ASP.NET MVC Area


(http://elegantcode.com/2010/03/13/asp-net-mvc-2-areas/) class library that follows both
ASP.NET MVC as Orchard specific conventions.
Amost all of the features that come out of the box are implemented as modules. The only
exception is the Orchard.Framework class library and the web site itself. The Framework
contains all that is needed to host Modules, and the web site uses this framework to fire up a
shell that will load all of the installed modules and themes.

To create a module, the minimum requirements are that you create a class library and add a text
file to it that is called Module.txt, which in turn has a minimum amount of information to
describe the module: one of which being the name of the module.
We'll have a look at the manifest in a few moments.

Instead of creating a module by hand, we could use the Orchard command line application to
generate a basic structure for us (http://docs.orchardproject.net/Documentation/Creating-a-
module-with-a-simple-text-editor). This will create a class library with some tweaked settings,

http://www.ideliverable.com/blog/writing­an­orchard­webshop­module­from­scratch­part­3 1/10
4/10/2015 IDeliverable ­ Writing an Orchard Webshop Module from scratch ­ Part 3

project references to Orchard.Core and Orchard.Framework, a stub manifest and a default set of


folders and files. However, I think it's interesting to do all of this ourselves to make sure that no
special magic is required to create an Orchard module, so that's what we're gonna do next.

Although our module will not look like much when we first create it, but in the end, our module
will consist of:

A Module Manifest
Models & ViewModels
Views
Controllers
Drivers
Service classes
Handlers
Shapes
Javascript
Css
A Migration
A ResourceManifest
Routes
Helpers methods

We will discuss each item as we go along.

Let's get started, shall we?

Creating the Class Library


First, let's create a new Class Library project.

Inside Visual Studio, create a new Class Library Project under the Modules Solution Folder, and
make sure that the project is physically located in \src\Orchard.Web\Modules:

http://www.ideliverable.com/blog/writing­an­orchard­webshop­module­from­scratch­part­3 2/10
4/10/2015 IDeliverable ­ Writing an Orchard Webshop Module from scratch ­ Part 3

Orchard requires that your module exists physically in the Modules directory.
First, let's get rid of the Class1.cs file that Visual Studio created for us, since we have no use for it
(we will create our own classes later).
Next, we will create the Module Manifest file, which is a simple text file describing our module,
with things such as the name of our module, a description, version number, our company url, etc.

Let's start with entering the following information to Module.txt:

Name: Skywalker.WebShop
AntiForgery: enabled
Author: Sipke Schoorstra
Website: http://skywalkersoftwaredevelopment.net
Version: 1.0
OrchardVersion: 1.4
Description: Orchard Webshop Module Demo
Category: Webshop

http://www.ideliverable.com/blog/writing­an­orchard­webshop­module­from­scratch­part­3 3/10
4/10/2015 IDeliverable ­ Writing an Orchard Webshop Module from scratch ­ Part 3

And there you have it: a basic Orchard module that does precisely: nothing. But that's about to
change.

Before we contrinue, let's make sure that Orchard recognizes our module. Launch the website by
pressing CTRL + F5.
Once the site starts, navigate to the admin area.

To enter the admin area, either navigate to http://localhost:30320/OrchardLocal/admin,


(http://localhost:30320/OrchardLocal/admin,) or click on the "Dashboard" link in the site footer.
Once inside the admin, go to Modules and enable our Orchard Webshop Module:

http://www.ideliverable.com/blog/writing­an­orchard­webshop­module­from­scratch­part­3 4/10
4/10/2015 IDeliverable ­ Writing an Orchard Webshop Module from scratch ­ Part 3

And that's all it takes to create a bare bones module! Next, let's make it do something useful.
What we want is to enable the administrator to define all sorts of products: Books, CDs, DVDs,
Phones, etc.
All these products have at least two properties in common: a unit price and a SKU
(http://en.wikipedia.org/wiki/Stock-keeping_unit).

http://www.ideliverable.com/blog/writing­an­orchard­webshop­module­from­scratch­part­3 5/10
4/10/2015 IDeliverable ­ Writing an Orchard Webshop Module from scratch ­ Part 3

At the heart of Orchard is the fact that every piece of content consists of content parts.
For example, the administrator will be able to define a new type of content: Book. The Book
content type is then defined by its Content Parts.
The administrator can pick the content parts he likes, like BodyPart, CommentsPart, RoutePart,
etc.

In order to turn any content type into a product that has a unit price and a sku, we need to
introduce our own custom part: a ProductPart.

Part 4 - Defining the ProductPart (writing-an-orchard-webshop-module-from-scratch-part-4)

Source code: Part03.zip (/Media/Default/Tutorials/WebshopDemo/Part03.zip).

 11/18/2014 10:53 PM by Sipke Schoorstra (/blog/author/sipke)

5 comments
Wangzhongyu11 03/25/2012 03:08 AM

this dose't work .


I use orchard 1.4

Rnt 04/04/2012 08:33 AM

Wangzhongyu11: Check that you have webshop module in


/src/modules/orchard.webshop not in /src/orchard.webshop

William Patrick 05/24/2012 09:16 AM [http://www.tatvasoft.com/]


(http://www.tatvasoft.com/)

http://www.ideliverable.com/blog/writing­an­orchard­webshop­module­from­scratch­part­3 6/10
4/10/2015 IDeliverable ­ Writing an Orchard Webshop Module from scratch ­ Part 3

I thought that with Orchard this won't be that easier but looking at the
solution over here I felt that this is far way easier to what I thought off.
Writing some codes can unleash the power of Orchard.

Nash Boyd 12/17/2012 05:51 AM


[http://www.amazines.com/article_detail.cfm/5223770?articleid=5223770]
(http://www.amazines.com/article_detail.cfm/5223770?articleid=5223770)

It's also essential to find out the business model of a business you would like
to employ the service of.

Kennedy Knapp 12/28/2012 09:01 AM [http://hamoljecal.webs.com/]


(http://hamoljecal.webs.com/)

You provide here good information which is very useful to the developer as
well as beginners even they got an idea and inspiration for their application.

Leave a comment
Name:

Enter your name

Email address:

Enter your email address

Not displayed on the site, used to obtain Gravatar image.

URL:

Enter your website URL

http://www.ideliverable.com/blog/writing­an­orchard­webshop­module­from­scratch­part­3 7/10
4/10/2015 IDeliverable ­ Writing an Orchard Webshop Module from scratch ­ Part 3

Comment:

How to Format

Type the text
Privacy & Terms
(http://www.google.com/intl/en/policies/)

Submit

 Subscribe to IDeliverable Blog (RSS)


(/rss?containerid=32)

 Subscribe (email) (/subscribe)

Topics
autofac (1) (/Tags/autofac) azure (2) (/Tags/azure) cloud services (2) (/Tags/cloud%20services)

codemirror (1) (/Tags/codemirror) globalization (1) (/Tags/globalization) jquery (1) (/Tags/jquery)

knockoutjs (1) (/Tags/knockoutjs) linqjs (1) (/Tags/linqjs) orchard (33) (/Tags/orchard)

orchard harvest (1) (/Tags/orchard%20harvest) performance (2) (/Tags/performance)

powershell (2) (/Tags/powershell) ssl (1) (/Tags/ssl) startup tasks (2) (/Tags/startup%20tasks)

webapi (1) (/Tags/webapi)

http://www.ideliverable.com/blog/writing­an­orchard­webshop­module­from­scratch­part­3 8/10
4/10/2015 IDeliverable ­ Writing an Orchard Webshop Module from scratch ­ Part 3

Authors
Daniel Stolt (/blog/author/daniel)
Daniel is the go-to guy here at IDeliverable for all things Azure. He
blogs about his experiences developing for the cloud.

(/blog/author/daniel)

Sipke Schoorstra (/blog/author/sipke)


Sipke is the resident Orchard CMS specialist here at IDeliverable. He
blogs about site building and module development.

(/blog/author/sipke)

Archive
2014 2013 2012
November (6) December (2) October (1)
(/blog/archive/2014/11) (/blog/archive/2013/12) (/blog/archive/2012/10)
September (3) June (5) September (3)
(/blog/archive/2014/9) (/blog/archive/2013/6) (/blog/archive/2012/9)
March (9) August (1)
(/blog/archive/2013/3) (/blog/archive/2012/8)
January (1) April (7)
(/blog/archive/2013/1) (/blog/archive/2012/4)
February (4)
(/blog/archive/2012/2)

http://www.ideliverable.com/blog/writing­an­orchard­webshop­module­from­scratch­part­3 9/10
4/10/2015 IDeliverable ­ Writing an Orchard Webshop Module from scratch ­ Part 3

January (18)
(/blog/archive/2012/1)

Postal address:
IDeliverable, Ltd.
PO Box 58341
3733 Limassol
CYPRUS

Visiting address:
IDeliverable, Ltd.
Sotiri Tofini 4, 2nd floor
Agios Athanasios
4102 Limassol
CYPRUS

VAT number: CY10318155U


TIC number: 12318155W
info@ideliverable.com (mailto:info@ideliverable.com)
http://www.ideliverable.com (http://www.ideliverable.com)

All information on this website copyright © 2015 by IDeliverable, Ltd.

http://www.ideliverable.com/blog/writing­an­orchard­webshop­module­from­scratch­part­3 10/10

You might also like