How to get the relations to package item from a package entry

Vote:
 

When you configure a package items for a package you can specify quantity of the specific package item. How do you get the child relations from the parent package item entry object (we use Entry). The entryInstance.Entries.Entry is filled with the pacakge item child entries, but they dont contain the relation info, specificly the quantity information.

We can get the relation from the child objects with CatalogContext.Current.GetCatalogRelationDto(), but that means we have to make n number of queries against the api for each packetitem. There must be a easier way?

 

#59321
May 31, 2012 16:24
Vote:
 

Hi Palle,

You're on the right track. Here's a little info that may help.

The CatalogRelationDto is just a DataSet with the following DataTables:

  • CatalogEntryRelation
  • CatalogItemAsset
  • CatalogNodeRelation
  • NodeEntryRelation

The CatalogEntryRelation is a DataTable with the following columns:

  • ParentEntryId
  • ChildEntryId
  • RelationTypeId
  • Quantity
  • GroupName
  • SortOrder

Luckily we've got that Quantity field there to contain the quantities for your package's child entries.

Regarding "but that means we have to make n number of queries against the api for each [package item]", we actually avoid that overhead in this case. The CatalogContext.Current.GetCatalogRelationDto() method, called with the proper parameters, passes execution down the chain from CatalogRelationManager to CatalogRelationAdmin where ultimately the stored procedure [ecf_CatalogRelation] is run. In that stored procedure certain select queries are conditionally executed depending on parameters, and results are mapped in-memory to some of the DataTable objects above.

Below is a sample method GetPackageChildEntries() where we create a List of KeyValuePair objects and then add pairs of child entry ids and quantities from the CatalogEntryRelation DataTable. Hopefully you can use this as a starting point to achieve your objectives.

public List<KeyValuePair<int, decimal>> GetPackageChildEntries(Entry parent)
{
  List<KeyValuePair<int, decimal>> childEntryQuanities = new List<KeyValuePair<int, decimal>>();

  CatalogRelationResponseGroup group =
    new CatalogRelationResponseGroup(CatalogRelationResponseGroup.ResponseGroup.CatalogEntry);
  CatalogRelationDto relations = CatalogContext.Current.GetCatalogRelationDto(0, 0, parent.CatalogEntryId, string.Empty, group);

  if (relations != null && relations.CatalogEntryRelation != null && relations.CatalogEntryRelation.Count > 0)
  {
    foreach (CatalogRelationDto.CatalogEntryRelationRow row in relations.CatalogEntryRelation.Rows)
    {
      childEntryQuanities.Add(new KeyValuePair<int, decimal>(row.ChildEntryId, row.Quantity));
    }
  }

  return childEntryQuanities;
}

The GetCatalogRelationDto() signature is as follows, below is a little description about how we used each parameter in the short sample above:

public CatalogRelationDto GetCatalogRelationDto(int catalogId, int catalogNodeId, int catalogEntryId, string groupName, CatalogRelationResponseGroup responseGroup)

catalogId: passing 0 here, do not filter by catalog

catalogNodeId: passing 0 here, do not filter by catalog

catalogEntryId: the catalog entry id of the package

groupName: passing empty string here, do not filter by group name, you can query the GroupName values of the CatalogEntryRelation to specify this as an additional filtering query

responseGroup: passing the CatalogRelationResponseGroup.ResponseGroup.CatalogEntry enum value to specify that the corresponding select query in the ecf_CatalogRelation stored procedure be executed and its results be mapped to the CatalogEntryRelation data table; the enum has the Flags attribute so other values can be bit OR'd to retreive additional results, i.e. ResponseGroup.CatalogNode will map execution results to CatalogNodeRelation and ResponseGroup.NodeEntry will map execution results to NodeEntryRelation

#59327
Jun 01, 2012 1:40
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.