Delete Entry or CatalogNode via API

Vote:
 

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?

#70266
Apr 16, 2013 12:10
Vote:
 

Mediachase.Commerce.Catalog.Managers.CatalogNodeManager and CatalogEntryManager Classes have related Functions as 

DeleteNodeRecursive or DeleteCatalogNode.

#70267
Apr 16, 2013 12:30
Vote:
 

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

 

#70316
Apr 17, 2013 9:37
Vote:
 

Try public functions available in  Mediachase.Commerce.Catalog.Impl.CatalogContextProxyImpl or Mediachase.Commerce.Catalog.CatalogContext.Current.DeleteCatalogEntry

#70317
Edited, Apr 17, 2013 9:48
Vote:
 

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.

#70327
Apr 17, 2013 12:22
Vote:
 

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.

#70330
Apr 17, 2013 12:38
Vote:
 

Hello,

how to insert entry in catalogNode ?

 

#70390
Apr 18, 2013 11:54
Vote:
 

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

#70391
Apr 18, 2013 11:57
Vote:
 

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

#70545
Apr 23, 2013 9:41
Vote:
 

Thank you

#70550
Apr 23, 2013 10:22
Vote:
 

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

#79497
Dec 18, 2013 22:59
Vote:
 

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

 

 

#79511
Dec 19, 2013 4:42
Vote:
 

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.

#79599
Dec 20, 2013 21:14
Vote:
 

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

 

#79616
Dec 23, 2013 2:58
Vote:
 

Perfect! Thx Quan.

#79635
Dec 23, 2013 22:48
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.