Quantcast
Channel: Using Optimizely Platforms
Viewing all articles
Browse latest Browse all 8020

"Media not found" - how to delete and find the media relation in later version of commerce

$
0
0

Hi!! Commerce v13.24.0

I have this old code that seems to stopped working. 

We have a Delete Media from Commerce entries functionality. But the problem is that it never finds the asset. How do we find the catalog/product/variant that is related if we only have the media ContentReference?

Old code, which is not working anylonger: 

            if (_contentRepository.TryGet<MediaData>(new ContentReference(mediaId), out MediaData existingMediaData))
            {
                CommerceMedia media = new CommerceMedia(existingMediaData.ContentLink, "episerver.core.icontentmedia", "default", 0);
                CatalogRelationDto relations = CatalogContext.Current.GetCatalogRelationDto(media.AssetLink.ID);
                _logger.Debug($"{relations?.CatalogItemAsset?.Count} CatalogItemAssets found");
                _logger.Debug($"{relations?.CatalogEntryRelation?.Count} CatalogEntryRelations found");
                _logger.Debug($"{relations?.CatalogNodeRelation?.Count} CatalogNodeRelations found");

All Counts are 0. 

Also we used 

foreach (var row in relations.CatalogNodeRelation)
{
    row.Delete();
}

to remove the relation, but i found out that you should do like this with the new apis:  https://support.episerver.com/hc/en-us/articles/115003738211-Deleting-CommerceMedia-leaves-the-asset-row-intact 

So, how am i suppose to do to find where an media asset is used? Any ideas?


Viewing all articles
Browse latest Browse all 8020

Trending Articles