Querying variations

This topic contains the following:

  • Querying a single variation
  • Querying variations by product
  • Querying all variations

Querying a single variation

To query a single variation, you must perform the following:

  1. Get an instance of the catalog manager.
    Get an instance of the CatalogManager object.
  2. Get the specified variation.
    To get the specified variation, you must either call the GetProductVariation method of the manager and pass the ID of the variation as an argument, or call the GetProductVariations method and filter the collection by one of the properties of the variation (e.g. Sku).

Here are examples of querying a single variation by ID and by SKU:

Querying variation by ID

public static ProductVariation GetProductVariationById(Guid id)
{
    CatalogManager catalogManager = new CatalogManager();
 
    ProductVariation variation = catalogManager.GetProductVariation(id);
 
    return variation;
}

Querying variation by SKU

public static ProductVariation GetProductVariationBySku(string sku)
{
    CatalogManager catalogManager = new CatalogManager();
 
    ProductVariation variation = catalogManager.GetProductVariations().Where(v => v.Sku == sku).SingleOrDefault();
 
    return variation;
}

Querying variations by product

To query variations by a specified product, you must perform the following:

  1. Get an instance of the catalog manager.
    Get an instance of the CatalogManager object.
  2. Get the variations.
    To get the variations, you must call the GetProductVariations method and pass the ID of the product as an argument.

Here is a code example:

public static List<ProductVariation> GetProductVariationsByProduct(Guid productId)
{
    CatalogManager catalogManager = new CatalogManager();
 
    List<ProductVariation> variations = catalogManager.GetProductVariations(productId).ToList();
 
    return variations;
}

Querying all variations

To query all variations, you must perform the following:

  1. Get an instance of the catalog manager.
    Get an instance of the CatalogManager object.
  2. Get the variations.
    To get the variations, you must call the GetProductVariations method.

Here is a code example:

public static List<ProductVariation> GetProductVariations()
{
    CatalogManager catalogManager = new CatalogManager();
 
    List<ProductVariation> variations = catalogManager.GetProductVariations().ToList();
 
    return variations;
}

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