Posted on 25/08/2023 18:05:45
Hi,
When we're loading Variant Options, my expectation is that the options by default would honor the sort order of the UI/database. Looking into the private FillVariants() method I see no specific instruction for that. Can that be added?
Below is the suggested fix for it. We can also apply that fix in the Swift templates, but seems like having it in the Core product is the proper way to do it.
private static void FillVariants(IList<VariantGroupViewModel> variants, VariantInfoViewModel variantInfo, Dictionary<string, VariantGroupViewModel> variantGroups, Dictionary<string, HashSet<string>> groupOptions)
{
if (variantInfo.VariantInfo != null)
{
VariantGroupViewModel variantGroup;
if (!variantGroups.TryGetValue(variantInfo.VariantInfoGroupName, out variantGroup))
{
variantGroup = new VariantGroupViewModel { Name = variantInfo.VariantInfoGroupName, Description = variantInfo.VariantInfoGroupDescription, Id = variantInfo.VariantInfoGroupId, Options = new List<VariantOptionViewModel>(), DisplayType = variantInfo.VariantGroupDisplayType };
variantGroups.Add(variantInfo.VariantInfoGroupName, variantGroup);
variants.Add(variantGroup);
}
HashSet<string> variantGroupOptions;
if (!groupOptions.TryGetValue(variantGroup.Name, out variantGroupOptions))
{
variantGroupOptions = new HashSet<string>();
groupOptions.Add(variantGroup.Name, variantGroupOptions);
}
foreach (var variantoption in variantInfo.VariantInfo.OrderBy(vo => vo.OptionSort))
{
if (!variantGroupOptions.Contains(variantoption.OptionID))
{
variantGroup.Options.Add(new VariantOptionViewModel()
{
Id = variantoption.OptionID,
Name = variantoption.OptionName,
Color = variantoption.OptionColor,
SortOrder = variantoption.OptionSort,
OptionImage = variantoption.OptionImage,
Image = variantoption.Image
});
variantGroupOptions.Add(variantoption.OptionID);
}
FillVariants(variants, variantoption, variantGroups, groupOptions);
}
}
}
Best Regards,
Nuno Aguiar