Try our conversational search powered by Generative AI!

Deleting media in PIM does not properly remove the image from Epi CMS

Vote:
 

Hi there,

Adding images and deleting images works fine in PIM. But when I go back to the item the media belongs to in the CMS I can see the image is no longer there but the row for it is still there with 'media not found'. I have tried a few things but none have helped so far. Anyone know how to get around this?

Thanks, James

#202295
Mar 22, 2019 9:27
Vote:
 

I assume you are talking about this view

if that is the case then the linking between a catalog items and an asset is not automatically deleted when you delete that asset. You would have to do that yourself (or make your PIM do it)

#202303
Mar 22, 2019 11:24
Vote:
 

Hi Quan,

That is the view! It wouldnt let me upload a picture.

I am aware it does not get automatically deleted and that I have to add something to make it do it. But am new to Epi so am unsure how I go about this. I have found a few similar posts online but none have helped so far.

Have you got any pointers on this?

Thanks, James

#202304
Mar 22, 2019 11:38
Vote:
 

If people are going to downvote please say why. Otherwise I will not learn from whatever mistake I made ;)

#202306
Mar 22, 2019 11:41
Vote:
 

The standard way is to upload the picture in the assets pane on the right of the cms/episerver first. Then you can select it in the assets area.

#202314
Mar 22, 2019 14:12
Vote:
 

Also I imagine someone downvoted it due to the lack of information. I would read https://world.episerver.com/blogs/scott-reed/dates/2018/7/tips-for-posting-on-the-forums/ and https://vimvq1987.com/the-art-of-asking-questions/ and try to make any questions as thorough as possible as although there are episerver employees in here answering questions there's also a lot of normal developers and it can be quite frustrating when there's not a lot of info if you're just trying to help.

#202315
Mar 22, 2019 14:15
Vote:
 

@james: you can try to remove the asset from the entry.CommerceMediaCollection. 

var clone = currentContent.CreateWritableClone<EntryContentBase>();

var itemToRemove = clone.CommerceMediaCollection.FirstOrDefault(x => x.AssetLink.Equals(contentLink));

clone.CommerceMediaCollection.Remove(itemToRemove);

contentRepo.Save(clone, SaveAction.Publish, AccessLevel.NoAccess);

copied from Felicia 

Regarding the down vote, yes I did down vote you - but don't worry it will not hurt your point. I should have said that the information you provided is not enough to guess (the most important part was PIM which I guess this is a Commerce question). As Scott pointed out we aim to improve quality of questions and answers and being voted down here implies that the question is not clear enough. But I should have said that. 

When you have improved your question I will remove the down vote or even vote it up.

#202318
Edited, Mar 22, 2019 14:31
Vote:
 

Hi Scott,

I know that is a way to do it but unfortunately the company I am working for are using a tool from inRiver to provide the CMS with product information.

I did try to add a screenshot of what I was talking about but a message popped up telling me I am not allowed to do so. But thanks for your post in future I will also post code examples of what I have tried.

What is the standard way of finding a product and getting a list of assets that belong to it? 

Thanks, James

#202319
Mar 22, 2019 14:34
Vote:
 

Hi Quan,

I will leave the post how it is so others can learn from my mistake. I post regulary to Stackoverflow so I should have known better! I was in abit of rush this morning and should have spent more time adding information to my post.

I will try and implement the code you have posted now and will let you know how it goes. 

Thanks again for the help

#202320
Mar 22, 2019 14:37
Vote:
 

Morning Quan,

You were correct it needed removing from the CommerceMediaCollection but wasnt as simple as using :

var clone = currentContent.CreateWritableClone<EntryContentBase>();

I needed to use the ReferenceConverter to get the root link and then use the ContentLoader to get the descendents using the root link as a parameter. That gave me the child collection of the catalog which I could then loop through to find the Product which had the media associated to it. I had to use the ContentLoaders TryGet method to set the Product. I then used the GetAssets method of Product to get the list of IContentMedia. I could then loop through this list and find the media using the medias ContentLink. I could then do the following:

var data = product.CreateWritableClone<GlobalProduct>();
                            var itemtoremove = data.CommerceMediaCollection.FirstOrDefault(x => x.AssetLink.Equals(existingMediaData.ContentLink));
                            data.CommerceMediaCollection.Remove(itemtoremove);
                            contentRepository.Save(data, SaveAction.Publish, AccessLevel.NoAccess);
#202702
Mar 29, 2019 10:10
Vote:
 

Of course, I was not showing the complete code, I was showing only example of how to remove a media from an entry CommerceMediaCollection.

If you want to find where an asset is used, I have something better for you - use ContentProvider.GetReferencesToContentItems(mediaContentLink) would return you list of contents (cms and catalog) that are using that asset 

#202704
Mar 29, 2019 10:42
Vote:
 

I should of said I am new to Epi so when I saw EntryContentBase I was under the impression I would need to use this. If I ever need to refactor that piece of code in the future I will use GetReferencesToContentItems.

Thanks for your help Quan :)

#202718
Mar 29, 2019 10:56
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.