Delen via


How to Create a Dynamic Catalog Set

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

A catalog set consists of one or more catalogs that you make available to different users or organizations. You create a dynamic catalog set based on an expression. Any catalog that satisfies the expression automatically becomes part of the catalog set.

You can convert a dynamic catalog set to a static catalog set to prevent any newly created catalogs from being added to the set. When you convert a dynamic catalog set to a static catalog set, the dynamic expression is evaluated one final time before conversion and results are added to the static catalog set. After that, the set starts functioning as a static catalog set.

To create a dynamic catalog set

  1. Use the CatalogSetsContext property on the CatalogContext object to create a CatalogSetsContext object.

  2. Use the CreateDynamicCatalogSet method on the CatalogSetsContext object to create a DynamicCatalogSet object.

  3. Use the Save method on the CatalogSet object to save the catalog set to the system.

To convert a dynamic catalog set to a static catalog set

To delete a dynamic catalog set

Example

The following example creates a dynamic set of catalogs that include "Camping" as part of their catalog descriptions. It then iterates through the catalog set and writes the name of each catalog in the set to the console.

The example also demonstrates how to convert a dynamic catalog set to a static catalog set. The example gets a dynamic catalog set and writes the name of each catalog in the set to the console. It then converts the dynamic set to a static set.

public static void CreateDynamicCatalogSet(CatalogContext context)
{
    // Get the CatalogSetsContext object.
    CatalogSetsContext catalogSetsContext = context.CatalogSetsContext;

    // Create a dynamic catalog set. The expression creates a set of
    // all catalogs that include "Camping" in their descriptions.
    string setName = "PreferredCustomerCatalog";
    string description = "Catalog for preferred customers";
    string expression = @"Description like 'Camping'";
    DynamicCatalogSet dynamicCatalogSet = catalogSetsContext.CreateDynamicCatalogSet(setName, description, expression);
            
    // Save the changes to the Catalog System.
    dynamicCatalogSet.Save();
    
    // Iterate through the catalogs in the catalog set,
    // and write the catalog name to the console.
    foreach (ProductCatalog productCatalog in dynamicCatalogSet.IncludedCatalogs)
    {
        Console.WriteLine(productCatalog.Name);
    }
}

public static void ConvertCatalogSet(CatalogContext context, string setName)
{
    // Get the catalog set.
    CatalogSetsContext catalogSetsContext = context.CatalogSetsContext;
    DynamicCatalogSet dynamicCatalogSet = (DynamicCatalogSet)catalogSetsContext.GetCatalogSet(setName);

    // Iterate through the catalogs in the catalog set.
    foreach (ProductCatalog productCatalog in dynamicCatalogSet.IncludedCatalogs)
    {
        Console.WriteLine(productCatalog.Name);
    }
    
    // Convert the dynamic catalog set to a static catalog set.
    StaticCatalogSet staticCatalogSet = dynamicCatalogSet.ConvertToStaticCatalogSet();
}

See Also

Other Resources

Managing Catalog Sets by Using the Catalog API