Product Parent(s) in Product XML Feed?

Greg Laycock asked on March 20, 2017 19:34

Good afternoon. I have a product catalog where the products are categorized via the site tree, so the parent node of a given product (page type) is the subcategory and the parent of that parent node is the category. I've been able to use a hierarchical transformation to display product data on the site, and this works quite well. At this point, however, I'm trying to create a product feed for a third-party, and I've been unable to determine a good method to get this hierarchy. When I try to get the current product's parent node, this results in the node of the location where the feed is present, not the page I'm trying to query. Thoughts? I'm using the Products RSS Feed webpart with a custom transformation.

Kentico 10, ASPX templates + portal

Recent Answers


Trevor Fayas answered on March 20, 2017 22:36 (last edited on December 10, 2019 02:30)

What Web part are you using? I assume Hierarchy Viewer, but i want to verify.

You can set the Path for most repeaters to be a parent path a couple ways:

1: Use the {#} in the Path to get the path at certain levels, ex: /{0}/{1}/% would select the /FirstLevel/SecondLevel node alias path.

2: Use macros to get the parent/grandparent's NodeAliasPath of the current document (I think {% DocumentContext.CurrentDocument.Parent.Parent.NodeAliasPath |(identity)GlobalAdministrator%} , but try that)

3: A buddy used a Macro DataSource to load in the Documents in the Path of the current document and repeated that, i would have to look at what the specific macro context was though.

0 votesVote for this answer Mark as a Correct answer

Greg Laycock answered on March 21, 2017 14:28

I'm using the Kentico Products RSS Feed webpart (as mentioned above). Your first method doesn't help, as I have no issue going through the tree. Your second method won't work because the feed itself is located in a different directory than the products themselves, so the CurrentDocument is the page I'm on, not the product page that I want to retrieve. What I'm trying to get is <productGroup> in the following transformation, where <productGroup> is the page name of the parent of the product page in question.

<Product>
    <Country code="US">
        <manufacturerName><%# CMS.Helpers.URLHelper.URLEncode(CMS.SiteProvider.SiteContext.CurrentSite.DisplayName.ToString()) %></manufacturerName>
        <sku><%# Eval("SKUNumber") %></sku>
        <alternateSkus>
            <%# IfEmpty(Eval("SKUNumberAlternate"),"","<altSku>" + Eval("SKUNumberAlternate").ToString().Replace(System.Environment.NewLine,"</altSku><altSku>") + "</altSku>") %>
        </alternateSkus>
        <model><%# EvalCDATA("SKUName") %></model>
        <productName><%# EvalCDATA("SKUDescriptiveName") %></productName>
        <upc><%# Eval("SKUUPC") %></upc>
        <releaseDate></releaseDate>
        <productPageUrl><![CDATA[<%# GetAbsoluteUrl(GetProductUrlForFeed(Eval("SKUGUID"),Eval("SKUName"),Eval<int>("NodeSiteID")),Eval<int>("NodeSiteID")) %>]]></productPageUrl>
        <imageUrl><![CDATA[<%# GetAbsoluteUrl(GetSKUImageUrl(720)) %>]]></imageUrl>
        <productGroup></productGroup>
        <category></category>
    </Country>
</Product>
0 votesVote for this answer Mark as a Correct answer

Trevor Fayas answered on March 21, 2017 14:36 (last edited on March 21, 2017 14:37)

Is there not a value from the RSS feed that contains that item's document id (or better yet, node id)?

If there is you can use <%# CMS.DocumentEngine.DocumentHelper.GetDocument(Eval<int>("TheDocumentID"), new CMS.DocumentEngine.TreeProvider()).Parent %>

Or if node id

<%# CMS.DocumentEngine.TreeHelper.SelectSingleNode(Eval<int>("TheNodeID")).Parent %>

Note that when calling the nodes/documents this way, it often will only get the Document/Node fields, once you get the parent's document ID you may need to call the below to access fields that are not universal to all pages.

<%# CMS.DocumentEngine.DocumentHelper.GetDocuments("My.Class").Where("DocumentID = "+ParentDocumentID).FirstObject.GetValue("TheValue") %>

Lastly, if you add this to the top of your transformation, you can cut out the "CMS.DocumentEngine" from each of the calls, makes it cleaner

<%@ Register Namespace="CMS.DocumentEngine" %>

<%# DocumentHelper.GetDocument(Eval<int>("TheDocumentID"), new TreeProvider()).Parent %>
<%# TreeHelper.SelectSingleNode(Eval<int>("TheNodeID")).Parent %>
<%# DocumentHelper.GetDocuments("My.Class").Where("DocumentID = "+ParentDocumentID).FirstObject.GetValue("TheValue") %>
0 votesVote for this answer Mark as a Correct answer

Greg Laycock answered on March 21, 2017 15:36

I'm not sure I can get a node or document ID. Being that I'm working with the e-commerce module, I have both an auto-generated SKUID and a ProductID for the page, but both values return null when passed as an ID to the GetDocument method. I'm pretty sure I can't get the node ID, but that would definitely solve the issue if I could.

0 votesVote for this answer Mark as a Correct answer

Trevor Fayas answered on March 21, 2017 15:44

You will have to get the Document/NodeID from the SKUID

At this point i would highly recommend adding a custom transformation method that will take your SkuID and give you the NodeID, it can be done in the transformation but it's going to be messy, but try this:

<%# CMS.DocumentEngine.TreeHelper.SelectNodes("/%", true, where: "SkuID = "+Eval<int>("SkuID")).FirstOrDefault().Parent %>

0 votesVote for this answer Mark as a Correct answer

   Please, sign in to be able to submit a new answer.