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:
- Get an instance of the catalog manager.
Get an instance of the CatalogManager object.
- 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:
- Get an instance of the catalog manager.
Get an instance of the CatalogManager object.
- 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:
- Get an instance of the catalog manager.
Get an instance of the CatalogManager object.
- 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;
}