Posted on 08/09/2016 08:33:30
That loop dosen't contain information about the variant name or the Ecom:VariantOption.ImgSmall.Clean which is use to display a hex code/thumbnail. I think it only renders the size options, which still dosen't have a relation to the color.
I have fixed it, but the code requires a bit too many loops..
// colorList out {id,name,color value,selected}
List colorList = new List();
// sizeList out {id,name,stock count, available (related to selected color), selected}
List sizeList = new List();
// Reconstruct the variant data
string productVariantId = GetString("Ecom:Product.VariantID").Length > 0 ? GetString("Ecom:Product.VariantID").Split('.')[1] : null;
foreach( var item in GetLoop("VariantCombinations"))
{
string variantId = item.GetString("Ecom:VariantCombination.VariantID");
string variantStock = item.GetString("Ecom:VariantCombination.Product.Stock");
string variantSelected = item.GetString("Ecom:VariantCombination.Selected");
foreach( LoopItem subitem in item.GetLoop("VariantGroups").Where( subitem => subitem.GetString("Ecom:VariantGroup.ID") == "FARVE" ).SelectMany( subitem => subitem.GetLoop("VariantAvailableOptions") ).Where( subitem => subitem.GetString("Ecom:VariantOption.ID") == variantId.Split('.')[1] ) )
{
string variantName = subitem.GetString("Ecom:VariantOption.Name");
string colorValue = !string.IsNullOrWhiteSpace( subitem.GetString("Ecom:VariantOption.ImgSmall.Clean") ) ? subitem.GetString("Ecom:VariantOption.ImgSmall.Clean") : variantName;
string variantColorSelected = variantId.Split('.')[1] == productVariantId ? "true" : "false";
if( !colorList.Any(c => c.Contains( colorValue ) ) )
{
colorList.Add( variantId + "," + variantName + "," + colorValue + "," + variantColorSelected);
}
}
foreach( LoopItem subitem in item.GetLoop("VariantGroups").Where( subitem => subitem.GetString("Ecom:VariantGroup.ID") == "STR" ).SelectMany( subitem => subitem.GetLoop("VariantAvailableOptions") ).Where( subitem => subitem.GetString("Ecom:VariantOption.ID") == variantId.Split('.')[0] ) )
{
string sizeAvailable = variantId.Split('.')[1] == productVariantId ? "true" : "false";
string variantName = subitem.GetString("Ecom:VariantOption.Name");
sizeList.Add( variantId + "," + variantName + "," + variantStock + "," + sizeAvailable + "," + variantSelected );
}
}