November Happy Hour will be moved to Thursday December 5th.
November Happy Hour will be moved to Thursday December 5th.
Hi,
To save a metaobject, just call metaObject.AcceptChanges(), you don't have to care about the serialized data.
IContentRepository (to be exact, CatalogContentProvider) still does not support StringDictionary. You'll have to save it via MetaObject.
Regards,
/Q
Hi Quan
Thanks for the prompt reply!
Well, I experiemented with just using the metaObject.AcceptChanges(metaContext) as seen on Line 6, but the data doesn't persist. It's strange though because it will change the metaObject data for the duration of the AppPool's life - once the app pool has been recycled it reverts back to the original data - also, another telling sign, the commerce manager UI never shows the update data.
So you believe all I need is what I've got on Line 6 to persist the data properly?
Let me know if a larger snippet of code if it would help check what I'm doing.
Kind regards, Matt
Hi,
That's very strange - your code looks correct. Was you able to check if the data was saved to database or not?
- The revert to original data can be result of some initialization step. Do you have any custom initialization code?
- If you change other data in Catalog UI, does the change get reflected in Commerce Manager? I think there might be an issue with cache synchronization here.
/Q
Hi Quan
I can confirm that the dictionary values do not change in the database.
Definitely no initialization code that is messing with meta fields or commerce stuff.
Really don't know how to move forward on this - are MetaStringDictionary a lost cause? should I look at storing this data in a different way?
Matt
Hmm,
What is your customerItemSks?
Does it work if you simply do this:
var stringDict = new MetaStringDictionary(); stringDict.Add(<key>,<value>), ... metaObj[<fieldNam>] = stringDict; metaObj.AcceptChanges(metaDataContext);
/Q
Hi Quan
Interesting, I tried the following crude MetaStringDictionary like you suggested (see below) - and the data persists to the database!
var customerItemSkus = new MetaStringDictionary(); customerItemSkus.Add("amer_c009204_test1", "TEST1"); metaObj[MetaDataPlusConfigurator.CustomerSkuNumbers] = customerItemSkus; metaObj.AcceptChanges(metaContext);
So then I tried the following crude approach to add one but to my existing dictionary (see below) - and again the data doesn't persist :-/
var customerItemSkus = metaObj.GetStringDictionary(MetaDataPlusConfigurator.CustomerSkuNumbers); customerItemSkus.Add("amer_c009204_test2", "TEST2"); metaObj[MetaDataPlusConfigurator.CustomerSkuNumbers] = customerItemSkus; metaObj.AcceptChanges(metaContext);
It's promising that I can get it working with a new MetaStringDictionary but I need it to work with existing dictionaries. Maybe I will need to do something ugly like replace the full dictionary each time rather than try change the existing one?
I just can't figure how the first code above works whilst the second code doesn't..?
Matt
Hi,
Did you try to debug and see the value of customerItemSkus after:
var customerItemSkus = metaObj.GetStringDictionary(MetaDataPlusConfigurator.CustomerSkuNumbers);
/Q
Yes, and it looks correct to me - it has all the existing key/values in it..
To get past this problem I'm simply going to create a new MetaStringDictionary every time - at least it works this way!
Let me know if you have any other ideas but I'm happy with this anyway - thanks for all of your help!
In EPiServer Commerce 8 we had been using the following code to update a MetaStringDictionary:
But since upgrading to EPiServer Commerce 9 the .SerializedData property on the entry is deprecated and removed. I still haven't figured out how to make this data persist. I've tried a variety of code changes but think the core change is indicated in Quan's post "Moving away from ICatalogSystem, part 0" but I don't yet understand how to incorporate this with saving a MetaStringDictionary via the IContentRepository (simply getting this variant and saving it via the contentRepo doesn't help).
I know I'm missing something, is this enough information for someone else to help me figure out what to do?