Hi,
Mario and I found today that an error is thrown when the platform attempts to render a list of variant children whose family has a variant group which contains two or more variant options with the same name. The error and a code snippet are included below.
Repro
- Create a variant group
- Add at least two options and give them the same name
- Create a new product
- Add two variants, one with each same-named option
- Turn on extended variants
- You should get an error in the backend either when you do one of the following. (We saw slightly different behavior on different sites)
- Turn on the extended variant for the second variant, or
- Expand the variant list from the product group view, or
- Open the product then click Variants on the ribbon
Suggestion
Prevent creating variant options with the same name or handle same-named variant options
Error
[ArgumentException: An entry with the same key already exists.]
System.ThrowHelper.ThrowArgumentException(ExceptionResource resource) +60
System.Collections.Generic.SortedList`2.Add(TKey key, TValue value) +167
Dynamicweb.Admin.eComBackend.EcomProductVariants.ShowVariantGroupList(Boolean isDraftEcomProduct) +1383
Dynamicweb.Admin.eComBackend.EcomProductVariants.Page_Load(Object sender, EventArgs e) +896
System.Web.UI.Control.OnLoad(EventArgs e) +99
System.Web.UI.Control.LoadRecursive() +154
System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +4082
Relevant code
https://dev.azure.com/dynamicwebsoftware/Dynamicweb/_git/Dynamicweb?path=/src/11%20-%20DW9/Dynamicweb.Admin/Dynamicweb.Admin/Admin/Module/eCom_Catalog/dw7/edit/EcomProductVariants.aspx.vb&_a=contents&version=GBmain
Dim sortedVariantCombos As New SortedList(Of String, VariantCombination)
For Each varCombo As VariantCombination In varCombos
Dim variantText As String = variantService.GetVariantName(varCombo.VariantId, _product.LanguageId)
If varCombo.HasRowInProductTable Then
variantText = $"{variantText} [{If(If(varCombo.GetProduct(_product.LanguageId)?.Active, False), "Active", "Inactive")}]"
End If
sortedVariantCombos.Add(variantText, varCombo)
Next