Jaa


How to Create a Product Definition

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

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

To create a product definition

  1. Create the properties needed in the product by using the CreateProperty method of the CatalogContext object.

  2. Create a product definition by using the CreateDefinition method of the CatalogContext object that has the definitionType parameter set to ProductDefinition.

  3. Add the properties to the product 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 the properties Title, Runtime, Artist, and Label for a product in a catalog of CDs. It creates a product definition "CD" by creating a CatalogDefinition object that has the property DefinitionType set to ProductDefinition. This example then adds the properties to the definition and saves the definition.

public static void CreateProductDefinition(CatalogContext context)
{   
    // Create the properties for a product in a CD catalog. 
    CatalogProperty title = context.CreateProperty("Title", CatalogDataType.String, 250);
    CatalogProperty runtime = context.CreateProperty("RunTime", CatalogDataType.Integer, 0);
    CatalogProperty artist = context.CreateProperty("Artist", CatalogDataType.String, 100);
    CatalogProperty label = context.CreateProperty("Label", CatalogDataType.String, 25);
           
    // Create a product definition.
    CatalogDefinition productDefinition = context.CreateDefinition("CD", CatalogDefinitionType.ProductDefinition);
    productDefinition.Description = "CD product";
            
    // Add the properties to the product definition and save the definition.
    productDefinition.AddProperty(title.Name, DefinitionPropertyType.NormalProperty);
    productDefinition.AddProperty(artist.Name, DefinitionPropertyType.NormalProperty);
    productDefinition.AddProperty(label.Name, DefinitionPropertyType.NormalProperty);
    productDefinition.AddProperty(runtime.Name, DefinitionPropertyType.NormalProperty);
    productDefinition.Save();
}

See Also

Other Resources

How to Create a CatalogContext Object

How to Create a Base Catalog by Using the Catalog API