Sitefinity CMS

Products Module: Simple Implementation Send comments on this topic.
See Also
Developing with Sitefinity > Modules > Adding New Modules to Sitefinity > Generic Content Based Module > Products Module: Simple Implementation

Glossary Item Box

This topic provides sample code for simple implementation of a Generic Content based module called Products.

 

The specifications for the module are as follows:

  • Users should have the ability to add any number of products
  • Each product should have the following information
    • Name
    • Description
    • Price
    • SKU (Stock Keeping Unit)
    • Weight
  • Products should be displayed on the public side as:
    • List of products (only summary)
    • Single product with full information

 

Implementation – High Level Overview

Since there are no additional data entities, except for Product (which we will treat as Content), we can use standard Generic Content provider. The following diagram (Figure 1) describes the steps of implementation:

 

Figure 1


New implementations

As you can see, we have been able to reuse vast majority of the Generic Content module. We have had to naturally create a new module class (this is the module definition class). We have implemented the manager class simply to have the access to proper instance of ContentManager through it (examine the code and you will see this implementation commented). The reason we have reimplemented CommandPanel is simply because this is a simple implementation and we did not want tags, categories, permissions and other commands there. Nevertheless, you will see later on how easy it is to add these features. Finally, we have implemented the Configuration files (in Configuration folder), because flexibility is needed in configuration, and they these files are not very complicated to implement.

Inherited implementations

We were able to completely reuse from Generic Content module the two most-time-consuming controls – ControlPanel and ProductsView. In case you are not familiar with ControlPanel, please take a look at Bare-bones Pluggable Modules - Explained.  On the other hand, ProductsView is a control based on ContentView and we have simply overridden the ProviderName property in order to use the default Products module provider when no provider is specified (if we omit that, default provider for Generic Content module will be used).

 

Not implemented, but implicitly reused

Finally, we were able to completely reuse the Data and Business layers of Generic Content module. By specifiying in web.config that we want to use DefaultProvider of Generic Content module as our provider we were able to pass all the work to this provider, while we were actually using the provider from a different module. Same goes for ContentManager, which we initialize through ProductsManager. Namely, the reason that we are able to do this lays in the fact that each Product object we actually treat as an IContent object. By doing so, DefaultProvider and ContentManager know how to work with these objects because they know how to work with IContent type of objects.

 

Code Sample

You can download the sample project for "Products" module simple implementation from here.


In order to set up project, please do following:

  1. Download the project file from here (if you haven't already)
  2. Create a new Sitefinity Web site or open an existing one
  3. From the project you have downloaded, open the Web site file and modify your web.config file according to the one you will find in Website folder:
  4. Add the following line to the configuration/configSections/sectionGroup name=”telerik” element:
    Products Section Declaration Copy Code
    <section name="products" type="Telerik.Samples.Products.Configuration.SectionHandler, Telerik.Samples.Products" requirePermission="false" />
  5. Add the following line to the telerik/framework/modules element:
    Products Module Registration Copy Code
    <add type="Telerik.Samples.Products.ProductsModule, Telerik.Samples.Products" />
  6. Add the following line to the telerik/cmsEngine/providers element:
    Products Module Generic Content Provider Declaration  Copy Code
    <add name="Products" urlRewriteFormat="[Name].aspx" urlWhitespaceChar="_" visible="False" defaultMetaField="Name" securityProviderName="" allowVersioning="False" applicationName="/Products" versioningProviderName="" commentsModeration="true" connectionStringName="GenericContentConnection" type="Telerik.Cms.Engine.Data.Providers.DefaultProvider, Telerik.Cms.Engine.Data" />
  7. Add the following lines to telerik/cmsEngine/metaFields element:
    Products Module Metafields Declaration  Copy Code
    <add key="Products.Name" valueType="ShortText" visible="True" searchable="True" sortable="True" defaultValue="Name this product" mandatory="True" />
    <
    add key="Products.SKU" valueType="ShortText" visible="True" searchable="True" sortable="True" defaultValue="" />
    <
    add key="Products.Weight" valueType="ShortText" visible="True" searchable="True" sortable="True" defaultValue="" />
    <
    add key="Products.Price" valueType="ShortText" visible="True" searchable="True" sortable="True" defaultValue="" />
  8. Add the following lines to telerik element:
    Products Module Declaration Copy Code
    <products defaultGenericProvider="Products">
     
    <genericContentProviders>
        
    <add providerName="Products" urlRewriteFormat="[Name].aspx" urlDateTimeFormat="yy-MM-dd" urlWhitespaceChar="_" />
     
    </genericContentProviders>
    </
    products>
  9. Copy the following folder from the project you have downloaded:
    Website/Sitefinity/ControlTemplates/Products
    and paste it to this folder in your Sitefinity Web site:
    ~/Sitefinity/ControlTemplates
  10. Copy the following folder from the project you have downloaded:
    Website/Sitefinity/Admin/ControlTemplates/Products
    and paste it to this folder in your Sitefinity Web site:
    ~/Sitefinity/Admin/ControlTemplates
  11. Open the following file in your Sitefinity Web site:
    ~/Sitefinity/Admin/Themes/Default/Modules.css
    and make sure you add the styles for Products module in the first five lines. To see how it should look like, look at the first five lines of this file that came with your project:
    Website/Sitefinity/Admin/Themes/Default/Modules.css
  12. Add new project to your Web site in Visual Studio. In the existing project dialog choose the file that came with the project you have downloaded:
    Telerik.Samples.Products/Telerik.Samples.Products.csproj
  13. Fix the references in this file by adding the references from the bin folder in your website. For example, to fix Telerik.Framework reference, right-click on Telerik.Samples.Products, select "Add reference", then select "Browse" tab and navigate to the bin folder of your Web site. There, select Telerik.Framework.dll file. Do this for all broken references.
  14. Save your changes and run your project.
  15.  

    See Also