Share via


How to Create a Virtual Catalog by Using the Catalog API

This topic describes how to create a Commerce Server Core Systems virtual catalog. It describes how to add base catalogs, categories, products, and variants to the virtual catalog and how to add a price rule.

To create a virtual catalog

  1. Create a virtual catalog by using one of the CreateVirtualCatalog methods of the CatalogContext object.

  2. Add or exclude a catalog, category, product, or product variant by using the AddVirtualCatalogRule method. Repeat this step as frequently as necessary to build the virtual catalog.

  3. Optionally, add a price rule by using the AddPriceRule method. Repeat this step as frequently as necessary.

  4. Optionally, add one or more languages to the virtual catalog by using the AddLanguage method.

  5. Save the changes to the virtual catalog by using the Save method.

  6. Rebuild the virtual catalog by using one of the Rebuild methods.

Example

This example creates a virtual catalog named "SpringCatalog". The example assumes that there are two base catalogs in the database. They are "Catalog1" with category "Category1", and "Catalog2" that contains a product with a product ID "Product1ID". This example adds the items from "Category1" of "Catalog1" to the virtual catalog. It then adds the product with product ID "Product1ID" from "Catalog2" as a root product of the virtual catalog.

This example creates the virtual catalog with English as the default language and reporting language. It adds Japanese as a language of the virtual catalog.

The example adds $5.00 to the price of all items from "Category1" of "Catalog1". It then saves the changes to the virtual catalog.

public static void CreateAVirtualCatalog()
{
    // 3 second refresh interval.
    const int RefreshInterval = 3000;

    // Create a virtual catalog.
    VirtualCatalog catalog = context.CreateVirtualCatalog("SpringCatalog", "en-US", "en-US");

    // Add a category from a base catalog.
    catalog.AddVirtualCatalogRule("Catalog1", "Category1", null, null, false);
    // Add a product from a second base catalog.
    catalog.AddVirtualCatalogRule("Catalog2", null, "Product1ID", null, false);
    // Add a language to the catalog.
    catalog.AddLanguage("ja-JP");
    // Add a price rule. This rule adds $5.00 to all items from Category1 of Catalog1.
    catalog.AddPriceRule("Catalog1", "Category1", null, null, CatalogPricingRuleType.AddFixedAmount, 5);
    // Save the changes and rebuild the virtual catalog.
    catalog.Save();
    RebuildProgress rebuildProgress = catalog.Rebuild();
    while (rebuildProgress.Status == CatalogOperationsStatus.InProgress)
    {
        System.Threading.Thread.Sleep(RefreshInterval);
        rebuildProgress.Refresh();
    }
}

See Also

Other Resources

How to Create a CatalogContext Object

Managing Base Catalogs by Using the Catalog API

How to Create a Base Catalog by Using the Catalog API