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

Geting product from Variation(SKU)

Vote:
 
var catalogEntryResponse = new CatalogEntryResponseGroup(CatalogEntryResponseGroup.ResponseGroup.CatalogEntryFull);
var catalogEntries = CatalogContext.Current.GetCatalogEntries(new[] { 555555 }, catalogEntryResponse);

    this is how im geting variation(SKU), there are fields: Entry and ParentEntry, both are always null, nomatter what i change in CatalogEntryResponseGroup.

 

So if i have Variation what are the ways to get product?

#59096
May 21, 2012 14:18
Vote:
 

actually entry is filled for product and from product i can get variation but not vice versa

#59098
May 21, 2012 15:38
Vote:
 

this:

http://world.episerver.com/Modules/Forum/Pages/thread.aspx?id=54275

helped me resolve this

#59158
May 23, 2012 10:51
Vote:
 

In R2SP2 you can use 

CatalogRelationDto relation = CatalogContext.Current.GetCatalogRelationDto(childId);
if (relation != null && relation.CatalogEntryRelation != null)
{

    int parentid = relation.CatalogEntryRelation[0].ParentEntryId

}

#59226
May 24, 2012 21:54
Vote:
 

in my opinion this will be faster compared to your solution of getting parentId and then geting entry for parent id, cos there is one request to db and db does the joining:

public static Entry GetParent(this Entry entry, CatalogEntryResponseGroup.ResponseGroup responseGroup)
        {
            var searchOptions = new CatalogSearchOptions {CacheResults = true};

            var searchParams =
                new CatalogSearchParameters
                    {
                        JoinType = "Inner Join",
                        JoinSourceTable = "CatalogEntry",
                        JoinTargetQuery =
                            "(Select ParentEntryId, ChildEntryId, RelationTypeId From CatalogEntryRelation) CatalogEntryRelation",
                        JoinSourceTableKey = "CatalogEntryId",
                        JoinTargetTableKey = "CatalogEntryRelation.ParentEntryId",
                        SqlWhereClause = "CatalogEntryRelation.ChildEntryId=" + entry.CatalogEntryId +
                                         " And CatalogEntryRelation.RelationTypeId=N'" + EntryRelationType.ProductVariation + "'"
                    };

            var catalogEntryResponseGroup = new CatalogEntryResponseGroup(responseGroup);

            var result = CatalogContext.Current.FindItems(searchParams, searchOptions, catalogEntryResponseGroup);

            if (result.Entry == null || !result.Entry.Any())
            {
                return null;
            }

            return result.Entry.First();
        }

    am i wrong, why?

#59233
Edited, May 25, 2012 9:49
Vote:
 

I have not tested which one would be faster but they would be both be making two database calls as FindItems first gets a group of catalog entry ids and stores those ids in catalogsearchreults with a search set guid.  Another call is made to populate the catalogentrydto bases on the ids stored with the catalogsearchresults.

Also just showing there was a new overload to get parententryids for a child entry id as it has been a requested method.  Although you will still need to check the RelationType as it brings back all EntryRelationTypes

 

#59249
May 25, 2012 23:23
Vote:
 
#76342
Oct 22, 2013 14:07
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.