Try our conversational search powered by Generative AI!

Asset not deleted from CommerceMediaCollection

Vote:
 

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.)

#210680
Dec 03, 2019 14:24
Vote:
 

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

#210683
Dec 03, 2019 14:40
Vote:
 

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);

#210684
Dec 03, 2019 14:42
Vote:
 

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

#210685
Dec 03, 2019 14:53
Vote:
 

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.

#210735
Edited, Dec 04, 2019 11:27
Vote:
 

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?

#210738
Dec 04, 2019 12:09
Vote:
 

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.

#210742
Dec 04, 2019 12:34
Vote:
 

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

#210743
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.