Dynamically created metafield doesn't show on the Commerce UI

Vote:
 

We have an import that creates metafields from the code. The relations and the values reach the DB. But the fields don't show on the Commerce UI or on the code retrieving the data for PDPs.

When the site is restarted the metafields are present on the UI too.

Do you know how to make the fields displayed without a site restart? (for production)

I already looked at the MetaField.ClearCache and MetaClass.ClearCache, but no luck. Is there a call that we can do when the fields are created to force them to be dislayed?

Thanks

#205103
Jun 28, 2019 12:51
Vote:
 

After some more investigations I see that the [dbo].[tblPropertyDefinition] table is not updated with the new metafield.

Initially was an warning that we had a metafield with the name Weight same as a property for variants. We removed that and still the issue persists.

Any help would be appreciated.

Thank youm

#205301
Jul 04, 2019 14:09
Vote:
 

I can confirm that we have code to process cases when you linked/unlinked metafield from metaclass on a remote site (for example, Commerce Manager). However, if the changes happen in the same site then I'm not sure. I'll look into it. 

#205309
Jul 04, 2019 17:01
Vote:
 

I had a chance to look into it, and the reason for not processing local events was to avoid a loop of events. However, you can work around that by adding this into your code

var contentTypeModelScanners = ServiceLocator.Current.GetAllInstances<IContentTypeModelScanner>();

foreach (var scanner in contentTypeModelScanners)
{
scanner.RegisterModels();
scanner.Sync(true);
}

after adding or removing the metafield(s)

#205335
Jul 05, 2019 13:45
Vote:
 

Thank you, we'll try this approach.

#205336
Jul 05, 2019 14:32
Vote:
 

Hi again

Eventually we couldn't make that work.

We tried that approach, but unfortunatellywe didn't have success as the scanner.Sync(true) is throwing and error: "Value cannot be null. Parameter name: key"

And couldn't debug that. There seem to be around 140 objects in the scanner that needs to be updated and probably one of them has some issue.

I tried to look into what is throwing the error, but couldn't find the issue.

We tried to write a job trying to do that and got the same issue.

We also looked into trying to force the change from the commerce manager, still no luck, unlinking and save and then linking again the meta field would not display it

Do you have any idea on what could we looke further into this?

Is there a posibility to trigger this from a job or an API call or even maybe even isolate the call that are made initially at site start when the metafields are updated?

Thanks,

#206634
Aug 27, 2019 13:32
Vote:
 

This is done by Commerce during startup, so there is no need for you to do that yourself. 

#206638
Aug 27, 2019 13:50
Vote:
 

I was thinking to run the same code from a job, not at the start.

The issue is that we have releases each 2 weeks and we don't restart on other times.

But new metafields are sometimes added and we would like for them to be available faster.

#206640
Aug 27, 2019 13:56
* 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.