Developer forum

Forum » Ecommerce - Standard features » Filtering Variants

Filtering Variants

Kevin O''''Driscoll
Reply

Hi Im using Variants for the first time in DW 8. can anyone advise the best way to do this using the DW API's available methods:

Parameters:
VariantOptionId = "VO1"
LanguageId = "LANG1"
ProductName = "AProductName"

VariantGroup selectedVariantGroup = VariantGroup.GetGroupByOptionId(VariantOptionId );

List<Product> products = Product.GetProductsByVariantGroup(selectedVariantGroup).Where(n => n.LanguageID == LanguageId && n.Name == ProductName).ToList();

products = products.? now filter the product list for products with the variant option = VariantOptionId

Alternatively:

ProductCollection productsByNameAndLanguage = Product.GetProductsByNameAndLanguage(ProductName, LanguageId);

Product masterProduct = productsByNameAndLanguage.Select(n => n).Where(m => m.IsVariantMaster).FirstOrDefault();

ProductCollection ProductsAndVariantsByProduct = Product.GetProductsAndVariantsByProduct(masterProduct);

now filter the product list for products with the variant option = VariantOptionId ??

    foreach (var p in ProductsAndVariantsByProduct.Where(n=>!n.IsVariantMaster))
        {
               VariantCombinationCollection productCombinations = p.VariantCombinations;
               foreach(var comb in productCombinations)
               {
                    comb.VariantOptions is always null ??

                }                   
         }

Looking at values passed from the api it seems each product has all the Variants from the system, and not related to the conserned product

any help appreciated.


Replies

 
Nicolai Pedersen
Reply

Hi Kevin

What do you want to achieve - can you explain what the end result should be?

Thanks, Nicolai

 
Kevin O''''Driscoll
Reply

Hi Nicoli, the result I would like is a list of products that all have the selected variant and I would like to display the other options (Variants) each product has eg:

I want all brown footware (VO1) in the Language (LANG1) called %LIKE% 'Boots'

Returns:

PROD23 Climbing Boots (Brown) with variant White Soles and variant Black Laces

PROD23 Climbing Boots (Brown) with variant Black Soles and variant White Laces

PROD38 Walking Boots (Brown) with variant Black Soles and variant White Laces

I can get close to the end by using

var combTextx = VariantCombination.GetCombinationText(product, product.VariantID, " - "); or = VariantCombination.GetCombinationText(product, "VO1", " - ");

but its the final filter to get only products with the requested variant I cant get.

I dont really want to set up special search filtering for this as the api should be able to handle this.

 
Nicolai Pedersen
Reply

So you have 2 dimensions of variants on the products. i.e. Color and Size - and want to show all colors and not all sizes?

 

You must be logged in to post in the forum