Try our conversational search powered by Generative AI!

Default value based on catalog



I'm trying to set a default value in commerce on content based on the catalog I'm creating the Category/Product/Variant in. I was hoping to set the values by overriding SetDefaultValues(ContentType) but the catalogId is always 0 when creating a new content item until it's published. Second option was to use the content events from an initialization module such as OnCreatingContent but same issue. OnCreatedContent actually contains the catalogId but then it's already too late. Would there be another of dealing with this issue?

Thank you,


Nov 15, 2021 15:15

I just checked on a product item and SetDefaultValues worked fine for me. Can you provide some screenshots, code of your issues. It sounds like you make have something custom in your implementation causing issues

Nov 15, 2021 20:16

Hi Scott,

The following implementation isn't the one that supports the Catalog specific but shows the CatalogId not being set when I'm trying to define other values based on it.

Edited, Nov 15, 2021 20:30

Although SetDefaultValues doesn't have a CatalogId at this point the ParentLink is set which is a ContentReference. So you can load this to get the correct Catalog Node it belongs to and then look up it's ancestor tree to get the Catalog.

Nov 16, 2021 15:22
* 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.