Partager via


How to Rank Catalog Items

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

You can use ranking to control how items are displayed on your Web site. You can rank child products and categories in a category, variants in a product family, and root products and categories in base catalogs.

Ranking applies to both base catalogs and virtual catalogs. Items in a virtual catalog inherit their ranking from the base catalog. You can override the ranks in the virtual catalog.

It is possible to have the same ranking for two or more items. Items are first sorted by rank, then alphabetically. If you do not specify a rank for an item, relationship, or property, the sorting is alphabetical.

The rank of a catalog item is set with respect to its parent. To set the rank for a product, access the category and set the rank on the dataset of child items. To set the rank for the variants of a product, access the product and set the rank on the dataset of variants. To set the rank for a category, access the root or parent category and set the rank on the dataset of child categories.

To set or change the rank of a product in a catalog

  1. Use the ChildProducts property on the StaticCategory object to access the dataset and set the rank for the child products.

  2. Use one of the Save methods on the StaticCategory object to save the changes.

To set or change the rank of the variants of a product

  1. Use the Variants property on the ProductFamily object to access the dataset and set the rank for the product variants.

  2. Use one of the Save methods on the ProductFamily object to save the changes.

To set or change the rank of categories in a catalog

  1. Use the ChildCategories property of the StaticCategory object to access the dataset and set the rank for the categories.

  2. Use one of the Save methods of the StaticCategory object to save the changes.

Example

This example describes how to set the rank for categories, products, and variants. In each case, the example accesses the dataset and sets the rank for the item. The changes are then saved.

private static void SetProductRank(CatalogContext context, string catalogName, string categoryName)
{
    // Set the rank of the products in a category.
    // Get the catalog.
    ProductCatalog catalog = (ProductCatalog)context.GetCatalog(catalogName, "en-US");
    // Get the category.
    StaticCategory category = (StaticCategory)catalog.GetCategory(categoryName);
     
    // Access and change the rank.
    int rank = 0;
    category.ChildProducts.DataSet.CatalogItems[0].Rank = ++rank;
    category.ChildProducts.DataSet.CatalogItems[1].Rank = ++rank;
    category.ChildProducts.DataSet.CatalogItems[2].Rank = ++rank;

    // Save the changes to the category.
    category.Save();
}

private static void SetVariantRank(CatalogContext context, string catalogName, string categoryName)
{
    // Set the rank of the variants in a product family.
    // Get the catalog.
    ProductCatalog catalog = (ProductCatalog)context.GetCatalog(catalogName, "en-US");
    // Get the category.
    StaticCategory category = catalog.GetCategory(categoryName);
    // Get the product family. In this case, it is the fourth 
    // product in the category.
    ProductFamily product = (ProductFamily)category.ChildProducts[3];

    // Access and change the rank.
    product.Variants.DataSet.CatalogItems[0].Rank = 0;
    product.Variants.DataSet.CatalogItems[1].Rank = 1;

    // Save the changes to the product family.
    product.Save();
}

private static void SetCategoryRank(CatalogContext context, string catalogName)
{
    // Set the rank of the top level categories in a catalog.
    // Get the catalog.
    ProductCatalog catalog = (ProductCatalog)context.GetCatlog(catalogName, "en-US");

    // Get the root category.
    StaticCategory root = (StaticCategory)catalog.GetRootCategory();
    CatalogItemsDataSet categories = root.ChildCategories.DataSet;
   
    // Iterate through the categores and set the rank for each.
    int rank = 0;
    foreach (CatalogItemsDataSet.CatalogItem category in categories.CatalogItems)
    {
        category.Rank = ++rank;
    }

    // Save the changes.
    root.Save();
}

See Also

Other Resources

Managing Products and Categories by Using the Catalog API

Browsing Catalogs by Using the Catalog API