Might be wrong, haven't worked with Commerce 8 (because it's a tad old, you should upgrade if you have the green bills to do it :D), but since it seems to already be content, set the content to expired and hopefully it'll work.
To be honest version handling in Commerce 8 was a bit sloppy (well, that might be an understatement depending on who you ask). To handle versions better you should upgrade to at least Commerce 9 - and latest version is always recommended.
There are several way to make a product unavailable:
So in short you would need to use ICatalogSystem/IsActive to control it. Note that this will make all languages "unpublished" - which I guess is what you want.
Thanks for the advice, guys.
Unfortunately, this piece of work is to help bridge the gap between a major upgrade project, so I can't really embark on upgrading this codebase further.
I've tried a combination of things and at some point, one of them seemed to work and mark the product as unavailable in Commerce Manager, however, I'd iterated a few times before I noticed and now I'm not sure what the magic combination was that worked.
Below is what I currently have -
var endDate = DateTime.UtcNow.AddDays(-1);
var dto = CatalogContext.Current.GetCatalogEntryDto(productInclusion); dto.CatalogEntry[0].IsActive = false; dto.CatalogEntry[0].EndDate = endDate; CatalogContext.Current.SaveCatalogEntry(dto); if (_catalogRepository.TryGetByEntryCode(productInclusion, out SiteProductContent productContent)) { var product = productContent.CreateWritableClone<SiteProductContent>(); //product.IsPendingPublish = true; product.StopPublish = endDate; product.AvailableDate = DateTime.UtcNow.AddYears(31); product.OnSale = false; _contentRepository.Save(product, SaveAction.Publish, AccessLevel.NoAccess); DataFactoryCache.RemovePage(product.ContentLink); result.DisableCount++; OnContentDisabled(product, result.DisableCount, total); } CatalogCache.Clear();
It's a bit of a mess but if either of you could narrow it down to the bits that should work, that'd be great. I'd hoped the top five lines alone would work but that hasn't appeared to be the case.
Yep, had literally just gotten it working based off of this article - https://world.episerver.com/forum/developer-forum/Episerver-Commerce/Thread-Container/2016/5/expire-a-product/
Thanks for all your help!
Hi all,
Is it possible to programmatically make products (and all child variations) unavailable?
I currently have this, but it doesn't seem to work:
If I fetch the product again immediately after, the OnSale value is null and when checking in Commerce Manager, it still shows as available...
I had thought there'd be plenty of docs on doing this kind of thing already but I've not been able to find any, so thought I'd try here.
Any help would be greatly appreciated,
Cheers,
James