November Happy Hour will be moved to Thursday December 5th.
November Happy Hour will be moved to Thursday December 5th.
Hi John,
Did you check the details of the log error? What it is?
And what does the "SetField(metaContext, metaObj, "ActivityLevel", actLevel);" method do?
Best regards,
GiangTran
Hey Giang,
The error logs are clear.... like I said in the initial comment the value is being saved it's just not coming into editing the document - the activity level field is blank.
the SetField() is just short hand for MetaHelper.SetMetaFieldValue().
First of all we recommend to use content API instead, it is the way forward.
It sounds like everything works as expected but in Catalog UI you are seeing a different version. Make sure to add Versions gadget and check
Hey Quan,
are you referring to using the IContentLoader and CMS API
https://world.episerver.com/documentation/developer-guides/commerce/catalogs/catalog-content/Catalog-content-provider/
Or using the IRelationRepository stuff?
https://world.episerver.com/documentation/developer-guides/commerce/catalogs/catalog-content/Bundles-and-packages/
Best,
John
From what I can tell you are updating some metafields, so the content API - which also works with catalog content should be used. IRelationRepository should be used when you need to update the relations between catalog entities, and it's also recommended over ICatalogSystem
Thanks Quan, what I needed in the end was the IContentRepository to make the update.
Worked a charm.
Thanks guys,
John
Hey guys,
I've a small niggly issue here. I've created a scheduled job to add a new value to each of the products we have. The value (integer) is stored in the database e.g. product code - ts_77 is updated with activity level = 3. This is visible on the customer facing product page.
When a member of the team want to update the content on the page the new activity level field is blank (null) which causes and issue when a manual content update occurs where a null value is published.
The code I'm using to update the database is:
public static bool UpdateActivityLevel(string code, int actLevel, string lastSyncBy)
{
if (CatalogRef == null) CatalogRef = CatalogContext.Current;
int holidayCatalogID = GetCatalogId(HOLIDAY_CATALOG_NAME);
if (holidayCatalogID == 0)
throw new Exception(string.Format("No Catalog found with the name {0}", HOLIDAY_CATALOG_NAME));
// Get a CatalogDto object.
CatalogDto catalogDto = CatalogRef.GetCatalogDto(holidayCatalogID, new CatalogResponseGroup(CatalogResponseGroup.ResponseGroup.CatalogFull));
CatalogEntryDto entryDto = null;
entryDto = CatalogRef.GetCatalogEntryDto(code, new CatalogEntryResponseGroup(CatalogEntryResponseGroup.ResponseGroup.CatalogEntryInfo));
string skuMetaClassName = "Package_Product_Class";
bool retVal = false;
//try updating Package_Product_Class
try
{
MetaDataContext metaContext = CatalogContext.MetaDataContext;
MetaClass metaClass = MetaClass.Load(metaContext, skuMetaClassName);
MetaObject metaObj = MetaObject.Load(metaContext, entryDto.CatalogEntry[0].CatalogEntryId, metaClass.Id);
//only update the Activity level
SetField(metaContext, metaObj, "ActivityLevel", actLevel);
//last updated information
MetaHelper.SetMetaFieldValue(metaContext, metaObj, "LastSync", new object[] { DateTime.UtcNow });
MetaHelper.SetMetaFieldValue(metaContext, metaObj, "LastSyncBy", new object[] { lastSyncBy });
metaObj.AcceptChanges(metaContext);
// Save the entry.
CatalogContext.Current.SaveCatalogEntry(entryDto);
retVal = true;
} catch (Exception e)
{
ErrorLogger.LogError(e, e.Message);
retVal = false;
}
return retVal;
}
Furthermore, the LastSync field is not updating in the editing CMS end which lead me to believe both are related.
Any help / suggestions would be greatly appreciated.
Best,
John