Hi,
You should be using the Content API for Commerce9, then set VersionStatus, StartPublish and StopPublish with ease. However if it's not an option for you right now, you can load the MetaObject and then
metaObject["Epi_StopPublish"] = DateTime.UtcNow;
metaObject["Epi_IsPublished"] = false;
metaObject.AcceptChanges();
You'll have to do this for all language versions,
Regards,
/Q
Islam, are you trying to do this via some service or within the web context? You may need to consider events also if its out of the web context.
Regards
/K
Thanks Quan!
I hope calling Content API will not be expensive.
One more question, if I do the following:
metaObject["Epi_IsPublished"] = false;
What is the proper version status to set?
Thanks Khan for your reply.
It is a custom schedule job that expire products based on specific criteria.
What is the best way to expire a product/variant in EPiServer Commerce 9?
I used to deactivate products in Commerce 8 as below:
CatalogEntryDto entry = CatalogContext.Current.GetCatalogEntryDto(entryCode);
if (entry != null && entry.CatalogEntry.Count > 0)
{
CatalogEntryDto.CatalogEntryRow entryrow = entry.CatalogEntry[0];
entryrow.EndDate = DateTime.Now;
entryrow.IsActive = false;
CatalogContext.Current.SaveCatalogEntry(entry);
}
But it doesn't work properly in Commerce 9 as new meta fields added to the meta object Epi_StopPublish and Epi_IsPublished.
Appreciate your help guys!