Querying product types

This topic contains the following:

  • Querying a single product type
  • Querying all product types

Querying a single product type

To query a single product type, you must perform the following:

  1. Get an instance of the manager.
    Get an instance of the CatalogManager object.
  2. Get the product type.
    To get the product type, you  must either call the GetProductType method and pass the ID of the product type as an argument, or call the GetProductTypes method and filter the collection by the desired criteria (e.g. by title).

Here are examples of querying a single product type by ID and by title:

Querying a product type by ID

public static ProductType GetProductTypeById(Guid id)
{
    CatalogManager catalogManager = CatalogManager.GetManager();
 
    ProductType productType = catalogManager.GetProductType(id);
 
    return productType;
}

Querying a product type by title

public static ProductType GetProductTypeByTitle(string title)
{
    CatalogManager catalogManager = CatalogManager.GetManager();
 
    ProductType productType = catalogManager.GetProductTypes().Where(x => x.Title == title).SingleOrDefault();
 
    return productType;
}

Querying all product types

To query all product types, you must perform the following:

  1. Get an instance of the manager.
    Get an instance of the CatalogManager object.
  2. Get the product types.
    To get the product types, you must call the GetProductTypes method of the manager and return it as a list.

Here is a code example:

public static IList<ProductType> GetProductTypes()
{
    CatalogManager catalogManager = CatalogManager.GetManager();
 
    List<ProductType> productTypes = catalogManager.GetProductTypes().ToList();
 
    return productTypes;
}

Next steps

+1-888-365-2779
sales@sitefinity.com

Related topics:

Feedback

How useful is this article?

Tell us more

Submit
Your message was successfully sent.

We appreciate your feedback.

Your message could not be sent.

OK