Condividi tramite


How to Create a Category Definition

For the latest version of Commerce Server 2007 Help, see the Microsoft Web site.

A category definition describes the categories in your catalog. It is a collection of properties that specifies the information that is stored for the category. When you create a category definition it is added to the catalog schema. For more information about category definitions, see What is a Category Definition?

To create a category definition

  1. Create a category definition by using the CreateDefinition method of the CatalogContext object that has the definitionType parameter set to CategoryDefinition.

  2. Create the properties needed by the category by using the CreateProperty method of the CatalogContext object.

  3. Add the properties to the category definition by using the AddProperty method on the CatalogDefinition object.

  4. Save the definition by using the Save method on the CatalogDefinition object.

Example

This example creates a catalog definition "Music Category" by creating a CatalogDefinition object that has the property DefinitionType set to CategoryDefinition. This example then adds a description to the definition. After this, the example then adds a property named "Description" to provide a description of the categories in the catalog. Finally, the example saves the definition.

public static void CreateCategoryDefinition(CatalogContext context)
{
    // Create a category definition for categories in a CD catalog.
    CatalogDefinition categoryDefinition = context.CreateDefinition("Music Category", CatalogDefinitionType.CategoryDefinition);
    categoryDefinition.Description = "Categories for music CDs";

    // Create a description property for this category.
    CatalogProperty description = context.CreateProperty("Description", CatalogDataType.String, 500);

    // Add the property to the category definition.
    categoryDefinition.AddProperty(description.Name, DefinitionPropertyType.NormalProperty);

    // Save the definition.
    categoryDefinition.Save();
}

See Also

Other Resources

How to Create a CatalogContext Object

Managing Base Catalogs by Using the Catalog API