SaaS CMS has officially launched! Learn more now.

Asset not deleted from CommerceMediaCollection


Using ((IAssetContainer) clone).CommerceMediaCollection.Remove(commerceMedia); I expect the asset to be removed from the commerce media collection. The method returns true, but the asset is still visible in the catalog. What could be the cause of this? (Even ((IAssetContainer) clone).CommerceMediaCollection.Clear(); doesn't empty the commerce media collection.)

Dec 03, 2019 14:24

What is your complete code? You should create a write-able clone of the content, then remove the asset, and save it

Dec 03, 2019 14:40

var clone = catalogContent.CreateWritableClone<CatalogContentBase>();
var commerceMediaCollection = ((IAssetContainer) clone).CommerceMediaCollection;

var commerceMedia = commerceMediaCollection.FirstOrDefault(x => x.AssetLink == mediaReference);

commerceMediaCollection.Remove(commerceMedia); // returns true
_contentRepository.Save(clone, SaveAction.Publish | SaveAction.ForceCurrentVersion, AccessLevel.NoAccess);

Dec 03, 2019 14:42

That looks correct. Which version are you using? Does the asset disappear if you restart the site and/or clear the browser cache?

Dec 03, 2019 14:53

I'm using Episerver Commerce v12.0.0 with Episerver CMS v11.12.0. The asset does not disappear when I restart the site nor when I clear the browser cache. It has worked previously too, I might add.

Edited, Dec 04, 2019 11:27

What do you mean " has worked previously"? did it work on same version, of it worked on an older version and stopped working once you upgraded?

Dec 04, 2019 12:09

It has worked on the exact same code, same versions on the CMS and Commerce. That's why I can't figure out what's causing this.

Dec 04, 2019 12:34

Then I suggest you to contact developer support service for further assistance - there might be something wrong with your site 

Dec 04, 2019 12:40
* 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.