November Happy Hour will be moved to Thursday December 5th.

Deleting image asset

Vote:
 

How do I delete an image asset? Is there a way to delete the image and unlink it from all its products, or is that something I have to do manually?

Right now, I can delete an image but I cannot remove its link to a product, or rather, the products link to the image. I am trying to use a CatalogEntryDto because I hope to modify the collection of assets.

var entry = _catalogSystem.GetCatalogEntryDto(book.LoadEntry().ID, new CatalogEntryResponseGroup(CatalogEntryResponseGroup.ResponseGroup.Assets));

var asset = entry.CatalogItemAsset.FirstOrDefault();

// Delete image

var imageRef = PermanentLinkUtility.FindContentReference(new Guid(asset.AssetKey));

_contentRepository.Delete(imageRef, true, AccessLevel.NoAccess);

// Trying to remove the link

entry.CatalogItemAsset.RemoveCatalogItemAssetRow(asset);

entry.CatalogItemAsset.AcceptChanges();

_catalogSystem.SaveCatalogEntry(entry);

#90975
Sep 23, 2014 12:39
Vote:
 

Hi,

This should be posted to Commerce subforum instead :).

To clear the asset collection of a product, you'll need to do this:

foreach (CatalogEntryDto.CatalogItemAssetRow row in entryDto.CatalogItemAsset.Rows)
{
if (row.RowState == DataRowState.Deleted)

continue;

row.Delete();
}

to actually delete the row.

Regards.

/Q

#90977
Sep 23, 2014 12:54
Vote:
 

Hi,

Can some admin pls move this post to the correct forum.


Thank you for your response.

I have tried that too, but I cannot make it work. I have tried all the different combinations of marking the row as deleted and removing it from the collection. Am I missing some other step? What am I supposed to do after I’ve marked a row for deletion? Right now I use AcceptChanges and then SaveCatalogEntry but my changes doesn’t stick. When I’m adding an image I use AddCatalogItemAssetRow followed by SaveCatalogEntry and that works just fine.

Regards

#90998
Sep 23, 2014 16:06
Vote:
 

You don't need to call AcceptChanges, just callìng SaveCatalogEntry should be enough ...

/Q

#91000
Sep 23, 2014 16:23
* 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.