Try our conversational search powered by Generative AI!

Association Types



I want to limit the association types in Commerce to some specific names for our implementation. First off, it was very difficult to find any documentation about how to even add new association types - maybe I'm just blind? :)

Ultimately I stumbled into the best example I had seen, which is from Casper Rasmussen:

Here's my code in my initialization module:

public void Initialize(InitializationEngine context)
var associationDefinitionRepository = context.Locate.Advanced.GetInstance();

associationDefinitionRepository.Add(new AssociationGroupDefinition { Name = Global.AssociationTypes.Alternative });


But, when I tested this approach, it didn't work very well. I’m finding that the “Default” is never really deleted with this code. When I add a new relation it always starts with type “Default” still, if I hit the dropdown it only shows my new custom value – and once I change to this you can’t select “Default” again.. But this is messy since all new entries start with “Default”.

And sidenote, upon closer inspection, I notice that it is storing the new association types in the DDS - I was expecting this to be stored in Commerce DB.

Anyway, curious if anyone knows what I might be getting wrong or misunderstanding?

Commerce v11.8.2
CMS v11.4.0

Edited, May 17, 2018 1:12

Those are two different things. AssociationDefinitionRepository manages the group that you can select for a association in Catalog UI. That's why when you delete "Default" you no longer be able to select it again. You are correct that is in DDS.

The actual data belongs to the association, which is in Commerce DB. If you want to change all association, you would have to load them all and update to new group, by using IAssociationRepository.

May 17, 2018 7:32

Hi Quan

I think I follow, and I'm happy that it means "Default" can no longer be selected - this is my intent.. The problem I have is that new associations still always start with "Default" even though it's no longer in the drop down.. Is there anyway to stop that happening and have it just start new associations with the only one I have in the list now?

Hope I'm making sense.

Thanks, Matt

May 17, 2018 8:02

I think I understand your concern - however the AssociationGroupDefinitionStore will get the existing association names and union them with the definition. So as long as one of your entry associations is "Default", then "Default is still there". Well, unless you change all of them 

May 17, 2018 9:00
This topic was created over six months ago and has been resolved. If you have a similar question, please create a new topic and refer to this one.
* You are NOT allowed to include any hyperlinks in the post because your account hasn't associated to your company. User profile should be updated.