+1-888-365-2779
Try Now
More in this section
Categories
Bloggers
Blogs RSS feed

Sample Generic Content based module: Products module

by Ivan Osmak

[This post is part of the developer's manual preview published on this blog. You can find temporary TOC here.]

 

 

In this article we are providing a sample Products module which is based on Generic Content module. The Products module supports following features:
  • Dynamic meta fields
  • Hierarchical categories
  • Tagging
  • Comments
  • Permissions
  • History (rollback)
  • Localization
  • Embedded templates
Generally speaking, it takes about 3-4 hours to build such a module and if the requirements for your module are similar to the features provided by Generic Content module, this is by far the simplest and fastest way to build a new module. We will explore different aspects of this approach in the articles to come.

 

You can download the module from here.

 

Installation instructions:
  • Download the module from here (if you haven't already)
  • Open an existing or create new Sitefinity website
  • Paste the contents of the Website folder in the root of your website (if asked to overwrite, say yes).
  • Add Telerik.Samples.Products project to your website, thus creating a solution (go to File > Add > Existing Project… Navigate to the Telerik.Samples.Products.csproj file that came with this sample)
  • Expand the References folder in the Telerik.Samples.Products and fix reference problems if any (this can happen if your website is using a different version of Sitefinity than the one I used to create a sample)
  • Reference Telerik.Samples.Products project from your website (right click on the website in the Solution Explorer, select “Add Reference…”, select “Projects” tab and then select the Telerik.Samples.Products from the available projects. Click OK.
  • Register the products configuration section by pasting the following line in the web.config file as an immediate child of <sectionGroup name=”telerik”>:
    <section name="products" type="Telerik.Samples.Products.Configuration.SectionHandler, Telerik.Samples.Products" requirePermission="false" />
  • Register Products module by pasting following line as an immediate child of telerik/framework/modules section:
    <add type="Telerik.Samples.Products.ProductsModule, Telerik.Samples.Products" /> 
  • Add new Generic Content provider by pasting following line as an immediate child of the telerik/cmsEngine/providers section:
    <add name="Products" urlRewriteFormat="[Name].aspx" urlWhitespaceChar="_" visible="False" defaultMetaField="Name" securityProviderName="" allowVersioning="True" applicationName="/Products" versioningProviderName="" allowComments="false" commentsModeration="true" connectionStringName="GenericContentConnection" type="Telerik.Cms.Engine.Data.Providers.DefaultProvider, Telerik.Cms.Engine.Data"></add> 
  • Declare the metafields for the products module by pasting following lines as an immediate child of telerik/cmsEngine/metaFields:
    <add key="Products.Name" valueType="ShortText" visible="True" searchable="True" sortable="True" defaultValue="Name this content" mandatory="True" /> 
    <add key="Products.Price" valueType="ShortText" visible="True" searchable="True" sortable="True" defaultValue="" /> 
    <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.Category" valueType="ShortText" visible="True" searchable="True" sortable="True" defaultValue="" /> 
     
  • Declare the products module section by pasting following lines as an immediate child of telerik/cmsEngine section:
    <products defaultGenericProvider="Products"
          <genericContentProviders> 
            <add providerName="Products" urlRewriteFormat="[Name].aspx" urlWhitespaceChar="_" /> 
          </genericContentProviders> 
    </products> 
     
  • Save web.config file, build your solution and run it. Products module will be available in the Modules section.
In case you have any questions or run into problems, please let us know. Also if there are some features that you would like explained in more detail, do not hesitate to leave a comment. Your feedback is greatly appreciated.

 


20 comments

Leave a comment
  1. Lesley-Ann Mar 12, 2009
    Hi there

    I'm interested in learning if anyone has used Sitefinity yet as a framework for delivering a customer management system.  I think modules are the way to go, but I'm still very new to the product and in evaluation mode.

    the components needed are:
    1) search for the customer (search based on standard customer fields, held in the central database)
    2) verify the customer - by showing onscreen more verification details once the account has been selected
    3) once verified allow the web user to perform further actions against the account (view statement, change customer details, enter a new transaction etc). 

    There are 2 levels of context:
    1) who am I logged in as (what functionality am I allowed access to?)
    2) whose account am I accessing - different account holder types will allow different functionality to be presented.

    Traditionally a unique identifier for the selected account would form part of the URL - and we've in the past added a session identifier to that also, to ensure only access from within a vetted session.  I haven't yet spotted how to make this happen, and I wonder/hope modules will allow me to explore that (about to go have a look through this example, when I can get it to build...).  The context for the webuser, I presume is available via the login API.

    Can you help enlighten me?  Is Sitefinity a good starting point for such a system?  So far I've been pretty impressed, but haven't got to the bottom of this "context" question yet....

  2. steve Mar 16, 2009
    - L0 -------------------------------------------------------------------------------

    Exception Type: System.TypeInitializationException

    Message: The type initializer for 'Telerik.ModuleManager' threw an exception.

    Source: Telerik.Framework

    Stack Trace:
       at Telerik.ModuleManager.LoadModules(Boolean reload)
       at Telerik.Cms.Web.CmsHttpModule.Init(HttpApplication context)
       at System.Web.HttpApplication.RegisterEventSubscriptionsWithIIS(IntPtr appContext, HttpContext context, MethodInfo[] handlers)
       at System.Web.HttpApplication.InitSpecial(HttpApplicationState state, MethodInfo[] handlers, IntPtr appContext, HttpContext context)
       at System.Web.HttpApplicationFactory.GetSpecialApplicationInstance(IntPtr appContext, HttpContext context)
       at System.Web.HttpApplicationFactory.GetPipelineApplicationInstance(IntPtr appContext, HttpContext context)
       at System.Web.Hosting.PipelineRuntime.InitializeApplication(IntPtr appContext)
    ------------------------------------------------------------------------------------
    - L1 -------------------------------------------------------------------------------

    Exception Type: System.TypeLoadException

    Message: Method 'get_Controls' in type 'Telerik.Samples.Products.ProductsModule' from assembly 'Telerik.Samples.Products, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null' does not have an implementation.

    Source: mscorlib

    Stack Trace:
       at System.RuntimeTypeHandle._GetTypeByName(String name, Boolean throwOnError, Boolean ignoreCase, Boolean reflectionOnly, StackCrawlMark& stackMark, Boolean loadTypeFromPartialName)
       at System.RuntimeTypeHandle.GetTypeByName(String name, Boolean throwOnError, Boolean ignoreCase, Boolean reflectionOnly, StackCrawlMark& stackMark)
       at System.RuntimeType.PrivateGetType(String typeName, Boolean throwOnError, Boolean ignoreCase, Boolean reflectionOnly, StackCrawlMark& stackMark)
       at System.Type.GetType(String typeName, Boolean throwOnError, Boolean ignoreCase)
       at Telerik.Utilities.TypeResolutionService.GetType(String name, Boolean throwOnError, Boolean ignoreCase)
       at Telerik.Utilities.TypeResolutionService.GetType(String name, Boolean throwOnError)
       at Telerik.Utilities.TypeResolutionService.ResolveType(String name, Boolean throwOnError)
       at Telerik.ModuleManager.LoadModules(Boolean reload)
       at Telerik.ModuleManager.LoadModules()
       at Telerik.ModuleManager..cctor()
    ------------------------------------------------------------------------------------
  3. Tom Janssens Mar 17, 2009
    Is there a way to implement a search provider?
    I tried implementing it the 3.5 way, but the module then gives me an error on all pages.
  4. Ivan Mar 24, 2009
    @ Lesley-Ann

    Hi, yes modules are way to go and I think Sitefinity would do a great job for the CRM application.

    For example, you could create a customers module based on Generic Content. Provide search by simply implementing search provider for the module. Sitefinity also supports multiple membership providers which would allow you to separate CMS users from the clients, who could log on to some protected area on the public site - and so on. I don't think you would face any obstacles in developing this module, but feel free to contact us if you do and we'll help you out.
  5. Ivan Mar 24, 2009
    @ steve

    I am not sure if you have been modifying the code, but I cannot reproduce this problem. Please open the ProductsModule class in your Telerik.Samples.Products project and make sure that on line 78 you have following code:

    public override IList<IToolboxItem> Controls
            {
                get
                {
                    return new List<IToolboxItem> { new ProductsViewToolboxItem() };
                }
            }

    I hope this will solve your problem. Let me know if the problem persists.
  6. Ivan Mar 24, 2009
    @ Tom Janssens

    Yes, you can implement search provider. Actually it's a good idea for the documentation. I'll implement it on the products module and post the sample. (Should be online next week).
  7. Shaun Mitchem Mar 31, 2009
    This is really helpful Ivan - thanks.

    One thing though - i dont suppose you could explain how you could include a library selector control for one of the metafields for the control (i.e. you want to be able to a product image to go along with each product).  I have tried copying in the library selector control you have provided in the ExternalTemplates.zip into the control and registering that on the XXEditView.ascx / XXNewView.ascx controls in the module, but it is coming up with more errors than it is worth listing.

    Can you explain how we should be doing it?

    Thanks

    Shaun
  8. Stephen Apr 10, 2009
    I don't understand where the products data is being stored or pulling from?  Is there a new table added in the sitefinity CMS database?  How can change the data to pulled from a different table.  I have been able to clone the products module, I am having trouble switching the data to be pulled from a table I created in the sitefinity database.  The table I have create is tblbooklogs  ?

    Can you explain the steps to hookup a different database table?
  9. Kevin Apr 22, 2009
    Is there a visual studio template that we could use to create content based custom module?
  10. Kazi May 21, 2009
    And why dont you explain how one can get the products fields to display on the front-end?
  11. Lei May 27, 2009
    Hi IVan, thanks for this post, It really helps me!
    but for the following part:

    Declare the products module section by pasting following lines as an immediate child of telerik/cmsEngine section:
     <products defaultGenericProvider="Products">
              <genericContentProviders>
                  <add providerName="Products" urlRewriteFormat="[Name].aspx" urlWhitespaceChar="_" />
              </genericContentProviders>
          </products>

     I think it should be on the same level position of "news", "events"...
    like put it befor this part:
    <news defaultGenericProvider="News">
          <genericContentProviders>
            <add providerName="News" publicationDateField="Publication_Date" expirationDateField="Expiration_Date" thumbnailUrlField="Thumbnail" urlRewriteFormat="[Publication_Date]/[Title].aspx" urlDateTimeFormat="yy-MM-dd" urlWhitespaceChar="_"/>
          </genericContentProviders>
        </news>
    ...not "as an immediate child of telerik/cmsEngine section". At least works on mine.
    Thanks!

  12. iman Jul 17, 2009
    i did every thing i can run site and admin panel but product module is not exist in panel
  13. Peter Oct 05, 2009
    Hi Ivan,

    Thanks for the posts on the products module, they are really helpfull in creating my own custom pluggable module.

    One thing I'm missing is a HistoryView (or HistoriesView) in the Telerik.Cms.Engine.WebControls.Admin namespace.

    Any reason it's not there, or am I looking in the wrong place?

    Regards,
      Peter    
  14. Allen Nov 30, 2009
    Since you support the CMS app in both C# and VB, it would be nice if your examples were in both as well.
  15. Vimal Oct 15, 2010
    Hi Ivan,

    I am getting the following error. please advice.

    Error 102 It is an error to use a section registered as allowDefinition='MachineToApplication' beyond application level.  This error can be caused by a virtual directory not being configured as an application in IIS. C:\Program Files\telerik\Sitefinity3.7\WebSites\MyModule\website\web.config 109 
  16. Vimal Oct 15, 2010
    Hi Ivan,

    I am getting the following error. please advice.

    Error 102 It is an error to use a section registered as allowDefinition='MachineToApplication' beyond application level.  This error can be caused by a virtual directory not being configured as an application in IIS. C:\Program Files\telerik\Sitefinity3.7\WebSites\MyModule\website\web.config 109 
  17. Vimal Oct 15, 2010
    Hi Ivan,

    I have corrected it by delete the web.cofig file from wesite folder.

    I have the following problem ...

    Parser Error Message: Unrecognized element 'products'.

    Source Error:

    Line 529:      </contentViewSettings>
    Line 530:
    Line 531: <products defaultGenericProvider="Products">Line 532:        <genericContentProviders>
    Line 533:          <add providerName="Products" urlRewriteFormat="[Name].aspx" urlWhitespaceChar="_" />

    Thanks
  18. Grati Nov 10, 2010
    Hi,
    I downloaded this module and followed the steps and when i build the project everything is ok but when i buid the solution i get a bunch of errors regarding the resources (the resource object with key ... was not found).
    Am i missing something? i added all the references to solution and project but i can't figure out where is the problem.
  19. Cross2004 Nov 10, 2010
    @grati, watch out you still have the backup project in the main sitefinity, as it was converted ;)
  20. Shah Saumil Jan 06, 2011
    Hi Pradip Here,

    It all works fine when I logged in as an Administrator but when I logged in as other user It shows me an exception given below:

    A required control was not found in the template for "Telerik.Samples.Products.Resources.ControlTemplates.Backend.ProductItemsList.ascx". The control must be assignable form type "System.Web.UI.WebControls.IButtonControl" and must have ID "groupOperationsLink".

    Help me!

    Leave a comment