Removing unavailable Variant Product options from the ShoppingCartItemSelector
When using Variants defined using just one Product option class Kentico removes the unavailable Product options from the list of available Product options. However when using multiple Product option classes to define Variants the unavailable options are left in the list, to indicate that other combinations may be available for purchase.
If you would like to change this behavior, you can do so by modifying the ShoppingCartItemSelector control, located here:
\CMS\CMSModules\Ecommerce\Controls\ProductOptions\ShoppingCartItemSelector.ascx.cs
First, locate this comment in method SetDisabledProductOptions():
// Check if selected options from other categories with this current option have existing variant
And modify the code following it, like this:
// Check if selected options from other categories with this current option have existing variant
foreach (var variant in Variants.Where(variantsItem => variantsItem.Variant.SKUEnabled))
{
if (variant.ProductAttributes.Contains(selectedOptionsFromOtherCategories))
{
// If so, add this option into enabledOptionIds collection
enabledOptionIds.Add(optionId);
}
}
}
// For all related selectors set enabled options, or remove unused
foreach (var selector in RelatedSelectors)
{
// Choose one of the following two options:
// Make unavailable options grayed out in the selector
selector.SetEnabledOptions(enabledOptionIds);
// Completely remove unavailable options
selector.RemoveDisabledOptions(enabledOptionIds);
}
Depending on which method you choose from SetEnabledOptions and RemoveDisabledOptions, the items will be either grayed out, or completely removed from the list.
One further extension you can make is to test the Variant is in stock, using method SKUInfoProvider.IsSKUAvailableForSale(variant);