November Happy Hour will be moved to Thursday December 5th.

Expire a Product

Vote:
 

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!

#149186
May 25, 2016 20:12
Vote:
 

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

#149203
May 26, 2016 10:12
Vote:
 

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

#149211
May 26, 2016 12:30
Vote:
 

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?

#149227
May 26, 2016 15:47
Vote:
 

Thanks Khan for your reply.

It is a custom schedule job that expire products based on specific criteria.

#149230
May 26, 2016 15:58
Vote:
 

Hi,

The ContentAPI is not be expensive, the overhead is small compared to the the CatalogEntryDto way.

I think the reasonable status is CheckedOut. It's the same when you set the IsActive to false.

Regards,

/Q

#149231
May 26, 2016 16:07
This topic was created over six months ago and has been resolved. If you have a similar question, please create a new topic and refer to this one.
* 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.