Quantcast
Viewing all articles
Browse latest Browse all 6894

Schedule Job updating customer facing content but not visible when editing.

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


Viewing all articles
Browse latest Browse all 6894

Trending Articles