Write an Orchard online store module (5) from the beginning-create and render the content type of the ProductCatalog

Source: Internet
Author: User

Address: http://skywalkersoftwaredevelopment.net/blog/writing-an-orchard-webshop-module-from-scratch-part-5
Content type for creating and rendering ProductCatalog

This is the first tutorial to write a new Orchard module.
For an overview of this tutorial, see Introduction.

To allow visitors to add products to their shopping cart, we need a product directory.
The product catalog can be a simple product list. However, in this tutorial, we want the topic author to take over the rendering (rendering) work, for example, to classify products by category. To do this, we need to be able to 'sknnable '. The list itself is not easy to skin (it can be skin changed, but all the lists will have the same appearance, this is not what we want. I have to admit that I don't know if this case is feasible, but I have encountered some problems during custom list rendering and I have to change it to something else ).

Therefore, we will introduce the ProductCatalog content type, from which we can create a ProductCatalog content item. In turn, if we decide to customize rendering, we can create a template.
The requirements for our product catalog are as follows:

  • Each directory displays a category of products (such as books, DVDs, and CD ). There are no technical restrictions to prevent other product types from being displayed. This is only required for our demonstration.
  • Directory rendering can be overwritten by other topics, so we create it as a content type (instead of letting users create a new list ).

Let's start to define the ProductCatalog to the Migration class and add the following code definition:

public int UpdateFrom2()
{
ContentDefinitionManager.AlterTypeDefinition("ProductCatalog", type => type
.WithPart(typeof(ContainerPart).Name)
.WithPart(typeof(MenuPart).Name)
.WithPart(typeof(AdminMenuPart).Name)
.WithPart(typeof(RoutePart).Name)
.Creatable()
);

return 3;
}

This Code uses ContentDefinitionManager to create a new Content Type named "ProductCatalog", which contains three parts and can be created on the management interface. Finally, it returns the version number of A New Ochard Migration to keep track of the current version of our module.

About Parts (Parts ):

So that ProductCatalog can contain other content items,ContainerPartYes.
MenuPartIs optional, but it allows our website administrator to add the product directory to the main menu.
AdminMenuPartIt is also optional, but it allows our website administrator to add the product directory to the main menu of the management interface, which is very convenient.
RoutePartIn fact, it is to be able to access from the front end andProductCatalogThe Slug and title attributes are provided.

As you can see, I use the typeof (ContainerPart). Name expression. This is because the project is added to our module.Orchard. Core.
For other types of Content, you may need to append some Content parts that have been defined in a third-party module. However, when you add references to other modules, you should remind the users of your modules that they must install the dependent modules first. If they first install your module without installing the dependency module, Orchard will throw an exception. The only way to restore the website is to delete your module.
This means that if you only need to attach some parts of other modules, you only need to use the Name (such as "AdvancedMenuPart", rather than typeof (AdvancedMenuPart). Name ).

When you refresh the management page, Orchard will notify you that you need to upgrade your module. When we continue and update the module, we will see that the orchard has created a new Content Type ):

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.