Sitefinity CMS

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

Glossary Item Box

In the previous topic about simple implementation of the Products module, we have implemented a simple Products module based on the Generic Content module. In this sample, we are taking that sample to the next step and we are going to enable categorization of products. Since Generic Content module supports categories by default our task will be very simple.

 

There are two basic tasks we need to perform:

  1. Add categories support to Admin side of our module
  2. Add categories support to Public side of our module (ProductsView control)

 

Add Categories Support to Admin Side of Simple Products Module

In order to add categories support to admin side we will need to register a new meta key for our module ("Category"), add the link to CategoriesManagement in CommandPanel and, finally, add the controls in ControlPanelInsert and ControlPanelEdit templates that users will use to assign a product to a category.

Products Module - Enabled Categories: Categories Management

Figure 1 – Categories Management on admin side

 

 

Add Categories Support to Public Side of Simple Products Module

By adding categories support to public side, we mainly think of modifying the ContentViewItemList and ContentViewSingleItem templates. We need to add Hyperlink control with the ID “Category” (same as the meta key we have defined in web.config). In addition to this, we will also add CategoriesList control and synchronize the CategoryKey properties of ProductsView and CategoriesList controls, so that both properties have the value of "ProductsCatID".
 

Products Module - Enabled Categories: ProductsView Control

Figure 2

 

 

Code Sample

You can download the full code sample for "Products module with Categories" from here.

In order to set up a project, please do following:

  1. Download the project from here (if you haven’t done that already)
  2. Follow the instructions for setting up simple implementation of this module, provided in this section (last part of the topic)
  3. Add additional meta key to Products module for Category. The line you should add to web.config should look like this:
    web.config Copy Code
    <add key="Products.Category" valueType="ShortText" visible="True" searchable="True" sortable="True" defaultValue="" />
  4. In order to make ProductsView control work together with CategoriesList control, do the following:
  5. Create a new page
  6. Drag ProductsView control on the page
  7. Drag CategoriesList control on the page
  8. Edit CategoriesList control
    • Set the provider name to "Products" (without double quotes)
    • Set the CategoryKey property to "ProductsCatID" (without double quotes)
  9. Edit ProductsView control
    • Make sure that the value of CategoryKey property is "ProductsCatID" (without double quotes)
  10.  

    See Also