Mediachase.Commerce.Catalog.Managers.CatalogNodeManager and CatalogEntryManager Classes have related Functions as
DeleteNodeRecursive or DeleteCatalogNode.
1) these classes you mention are all static with internal only methods, so no way to use them directly.
I guess the implementation of ICatalogSystem (CatalogContext.Current) uses these classes to do their stuff.
2) ICatalogSystem.DeleteCatalogEntry(int entryId, bool recursive) does not delete the entries even if recursive is true. The method just moves the entries to the catalog root (i guess if i delete them again from here they will eventually be removed from the database, but there must be a better solution).
Try public functions available in Mediachase.Commerce.Catalog.Impl.CatalogContextProxyImpl or Mediachase.Commerce.Catalog.CatalogContext.Current.DeleteCatalogEntry
But Khan ... you get a ICatalogSystem from Mediachase.Commerce.Catalog.CatalogContext.Current (which i expect is implemented using Mediachase.Commerce.Catalog.Impl.CatalogContextProxyImpl), so my previous post already explained that this does not work.
The problem is that DeleteCatalogEntry deletes the relations but not the entry it self, which is silly.
Sorry Palle, You are right. I am sure it works as once i have used this. but not sure about recursive. Can you please test by setting recursive=false.
It should remove Relations, Asoociations, Inventory and Entry in itself.
if it works fine then you probably can iterate for each entry.
Perhaps you should have started a new thread.
But existing entry is related to a catalogNode using:
CatalogRelationDto relation = null;
relation = CatalogSystem.GetCatalogRelationDto(_catalogId, node.CatalogNodeId, newEntryRow.CatalogEntryId, "",
new CatalogRelationResponseGroup(CatalogRelationResponseGroup.ResponseGroup.NodeEntry));
CatalogRelationDto.NodeEntryRelationRow nodeRelation = null;
if (relation == null || relation.NodeEntryRelation.Count == 0)
{
nodeRelation = relation.NodeEntryRelation.NewNodeEntryRelationRow();
nodeRelation.CatalogId = _catalogId;
nodeRelation.CatalogEntryId = dto.CatalogEntry[0].CatalogEntryId;
nodeRelation.CatalogNodeId = node.CatalogNodeId;
nodeRelation.SortOrder = 0;
if (nodeRelation.RowState == DataRowState.Detached)
relation.NodeEntryRelation.AddNodeEntryRelationRow(nodeRelation);
}
if (relation.HasChanges())
CatalogSystem.SaveCatalogRelationDto(relation);
Hello!
Try this simple iteration. Maybe not the best practice but I think it would solve your situation.
ICatalogSystem system = CatalogContext.Current; // Get catalog lists CatalogDto catalogs = system.GetCatalogDto(); foreach (CatalogDto.CatalogRow catalog in catalogs.Catalog) { string catalogName = catalog.Name; // Get Catalog Nodes CatalogNodeDto nodes = system.GetCatalogNodesDto(catalogName); foreach (CatalogNodeDto.CatalogNodeRow node in nodes.CatalogNode) { Console.WriteLine(node.Name + " Category Node"); CatalogSearchParameters pars = new CatalogSearchParameters(); CatalogSearchOptions options = new CatalogSearchOptions(); options.CacheResults = false; options.RecordsToRetrieve = 8000; pars.CatalogNames.Add(catalogName); Mediachase.Commerce.Catalog.Objects.Entries entries = CatalogContext.Current.FindItems(pars, options, new CatalogEntryResponseGroup(CatalogEntryResponseGroup.ResponseGroup.CatalogEntryInfo));
if (entries.Entry != null) { foreach (Entry entryDelete in entries.Entry) { CatalogContext.Current.DeleteCatalogEntry(entryDelete.CatalogEntryId, true); Console.WriteLine(entryDelete.Name + " IS DELETED"); } }
} } Console.WriteLine("DONE DELETE");
Hi Palle,
I know that this thread is pretty old, but I stumbled on only this thread from entire internet with the same problem you mentioned here. Could you please help me or tell me the solution you found for deleting the entries with all the relations?
Thanks for your help!
Regs.
Jay
Hi,
You can use ICatalogSystem with two methods:
- DeleteCatalogEntry(int entryId, bool recursive) to delete a CatalogEntry.
- DeleteCatalogNode(int catalogNodeId, int catalogId) to delete a CatalogNode
Please note that in Commerce 7.5, two new methods were added to make the delete easier:
DeleteCatalogNodeAndEntries(int catalogNodeId);
DeleteCatalogNodesAndEntries(IEnumerable<int> catalogNodeIds);
Hope this helps.
/Q
Thanks Quan for your help. These APIs are deleting the CatalogEntry completly .. no matter how many relations they have. I want only the mentioned relation to be delted.
For ex; Coca cola (UPC=XYZ) is at two place 1. Products > Soda and 2. Products > Grocery > Soda
I want to just delete 2nd one and keep the first relation as it is. Please help. Thanks again for your help.
Hi,
You can do this by delete the relevant row in NodeEntryRelation table. Pseudo code:
var entry = CatalogContext.Current.GetCatalogEntryDto(123);
var row = entry.NodeEntryRelation.Rows.Cast<Mediachase.Commerce.Catalog.Dto.CatalogEntryDto.NodeEntryRelationRow>().First(c => c.CatalogNodeId == 123);
row.Delete();
CatalogContext.Current.SaveCatalogEntry(entry);
Hope this helps.
/Q
Any way to delete CatalogEntries easily (without going through each of the relating tables and delete its relations)?!?!
Same question for CatalogNodes? Any easy ways of deleting an entire catalog node including related catalog entries?