Developer forum

Forum » Ecommerce - Standard features » An entry with the same key already exists (Same-named variant options)

An entry with the same key already exists (Same-named variant options)

Carolee Schuck Dynamicweb Employee
Carolee Schuck
Reply

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

  1. Create a variant group
  2. Add at least two options and give them the same name
  3. Create a new product
  4. Add two variants, one with each same-named option
  5. Turn on extended variants
  6. You should get an error in the backend either when you do one of the following.  (We saw slightly different behavior on different sites)
    1. Turn on the extended variant for the second variant, or
    2. Expand the variant list from the product group view, or
    3. 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


Replies

 
Shiwanka Chathuranga Dynamicweb Employee
Shiwanka Chathuranga
Reply

what kind of practical scenario is with this?

"Add at least two options and give them the same name"

 
Carolee Schuck Dynamicweb Employee
Carolee Schuck
Reply

Reasonable question!

In the current case, the client has too many variant groups and options to create manually so we're importing them from the ERP.  It's a result of bad data in the ERP and took a long time to troubleshoot in Dynamicweb because VariantOptionName is a strange field to use as a "key" field in code.

Having said that, I now realize the suggestion of "Prevent creating variant options with the same name" won't solve our problem.

Thanks,

Carolee

 
Shiwanka Chathuranga Dynamicweb Employee
Shiwanka Chathuranga
Reply

"importing them from the ERP"

base on this statement you can manage it easily if you use DataIntegration job, it will not create duplicates 

 
Carolee Schuck Dynamicweb Employee
Carolee Schuck
Reply

Hi,

We are using a data integration job to import the variant options.  Because the records were given different VariantOptionIds upon import, the duplicate named records were created.

 
Shiwanka Chathuranga Dynamicweb Employee
Shiwanka Chathuranga
Reply

Make Name and OptionGroupId as Key kolumn

 
Carolee Schuck Dynamicweb Employee
Carolee Schuck
Reply

That seems like a reasonable work-around but it's not a fix for the problem...

 
Oleg Rodionov Dynamicweb Employee
Oleg Rodionov
Reply
This post has been marked as an answer

Hi,

New task #13952 has been created against the issue. Thanks.

BR, Oleg QA

Votes for this answer: 1

 

You must be logged in to post in the forum