Condividi tramite


How to Get Related Products

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

You can use the Catalog API to get products from a product catalog that are related to a specific product. That is, you can get the products that have a relationship with the specified product.

  1. Use the RelatedProducts property on the CatalogItem object to get a dataset that contains the related products for the specified product.

  2. Iterate through the dataset to access the individual products and display them.

Example

This example gets a catalog item specified by the productId. The example then gets a dataset of the products related to the catalog item and iterates through the dataset to access the individual products and writes the DisplayName of the products to the console.

private static void GetRelatedProducts(Catalog catalog, string productId)
{
    // Get the product specified by productId.
    catalogItem = catalog.GetProduct(productId);
    // Get the products related to the specified product.
    CatalogRelationshipsDataSet relatedProducts = catalogItem.RelatedProducts;
    // Access the products in the dataset and display the name.
    foreach (CatalogRelationshipsDataSet.CatalogRelationship relatedProduct in relatedProducts.CatalogRelationships)
    {
        Console.WriteLine(relatedProduct.DisplayName);
    }
}

See Also

Other Resources

How to Browse a Catalog

Managing Products and Categories by Using the Catalog API