Try our conversational search powered by Generative AI!

How to read the parent entry code from child entry object

Vote:
 

Hello I am working on a web site built on episerver, I am stuck at a stage where I have a object of variant/sku , but I need to get its parent entry object, problem is that in this variant object I cant spot any reference to the parent object

Also in the variant entry object parententry property is also null

If any one can help I would really appreciat it

Thanks

#54275
Oct 07, 2011 11:32
Vote:
 

If you get the parent entry (product) in full and look in the Entries (variations) of that entry, the ParentEntry is not null.

When you get the entry (package,bundle,variation/sku) on its own, this parent/child releationship isn't known. This is because the entry can potentially have many parents.

There are two ways that I know of. The best way, I think, of these two is to use the CatalogContext.FindItems() and add some sql joins to the SearchParameters parameter. The easiest way is to execute a sql queary directly to the ECF database and select parententryid from the CatalogEntryRelation table where the childentryid is your variation/sku catalog entry id and where the relationtypeid is ProductVariation.

Hope this helps you move forward.

#54278
Oct 07, 2011 13:51
Vote:
 

Hello thanks for your reply, Its the sku/variantid which I had and in our system we always have ony one parent for it, I can do the query to the database but can you tell me how to get the parent code id from the cache?

I would really appreciate any example code

Thanks

Alot

#54328
Oct 10, 2011 13:14
Vote:
 

A method using the FindItems on the CatalogContext joining and filtering on the catalogEntryRelation. Set the searchOptions.CacheResults = true for the result to be cached by ECF. Use the constants on the EntryRelationType class to pass as the relationType parameter. language is needed because the Entry binds to the metadata class and fetches the language dependent data.

public static Entry[] FindAssociatedParents(int childCatalogEntryId, string language, string relationType, CatalogEntryResponseGroup.ResponseGroup responseGroup)
{
  var searchOptions = new CatalogSearchOptions();
  searchOptions.CacheResults = false;

  var searchParams = new CatalogSearchParameters();
  searchParams.JoinType = "Inner Join";
  searchParams.Language = language;
  searchParams.JoinSourceTable = "CatalogEntry";
  searchParams.JoinTargetQuery = "(Select ParentEntryId,ChildEntryId,RelationTypeId From CatalogEntryRelation) CatalogEntryRelation";
  searchParams.JoinSourceTableKey = "CatalogEntryId";
  searchParams.JoinTargetTableKey = "CatalogEntryRelation.ParentEntryId";
  searchParams.SqlWhereClause = "CatalogEntryRelation.ChildEntryId=" + childCatalogEntryId + " And CatalogEntryRelation.RelationTypeId=N'" + relationType + "'";

  var result = CatalogContext.Current.FindItems(searchParams, searchOptions, new CatalogEntryResponseGroup(responseGroup));
  return result.Entry;
}

#54331
Oct 10, 2011 14:29
Vote:
 

Thanks alot it's really helpful :)

#54352
Oct 11, 2011 12:45
Vote:
 

Hello I had implement the above code and it's works fine but I am having problem to check if the results are getting cached or not

What I had done is on my local machine I first view the page where the results are populated using the above code now I had gone in and removed the variant/ sku from it's parent but I just saved the details but didnt rebuild the index what I was thinking that if I refreshed the page again it will pick up the data from the cache but it didnt and just give the error that parent didnt exists

Please tell me how the cache is working in this scinario

Thanks

 

#54431
Oct 14, 2011 13:57
Vote:
 

It seems that EPiServer Commerce uses the ASP.NET Runtime Cache to cache data. The different cached objects lives in the cache for configurable amount of time. Per default the catalog subsytem caches collections and entries for 1 minute. This can be configured in the Configs/ecf.catalog.config file.

The search index is not involved when doing calls as CatalogContext.Current.GetCatalogEntry().

#54433
Oct 14, 2011 14:42
Vote:
 

Hello I had made the following change in my ecf.catalog.config file

<Cache enabled="true" collectionTimeout="0:1:0" entryTimeout="0:20:0" nodeTimeout="0:1:0" schemaTimeout="0:2:0" />

Hello is this the chnage you are suggesting?

Please tell me is this a safe change ? or can it affect the website performace.

Thanks

#54532
Oct 19, 2011 15:33
Vote:
 

Yes, this is what I am suggesting. This should not affect the performance for the worse, I think. In this case for the better. The cache revolves around the ASP.Net Cache and, what I have found, is that this cache will invalidate entries that is updated through the EPiServer Commerce Manager.

#54569
Oct 20, 2011 22:25
* 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.