Get document from SKU

Matt Mason asked on October 24, 2014 21:48

Using 8.1 and C# I am trying to find the document associated with a SKU. Any clues on how to get that?

Thanks!

Recent Answers


Bill Tran answered on October 31, 2014 21:04

SKUInfo sku = CMS.Ecommerce.SKUInfoProvider.GetSKUInfo(skuId);

1 votesVote for this answer Mark as a Correct answer

Alex Johnson answered on April 22, 2015 16:44 (last edited on July 1, 2015 15:05)

The CMS.Ecommerce.SKUInfoProvider.GetSKUInfo(skuId) returns just the SKUInfo object and no document (page) information. Is there a way to get the actual document associated with the SKU in code? From the joined view in the database, I can see the SKUID, NodeID, DocumentID, and NodeSKUID in a single record. How can I get from SKU to Document in code?

For clarity, I would like the returned object to be of type CMS.DocumentEngine.TreeNode or comparable with an input of data gleaned from the SKUInfo object.

Thanks

Edit: I was able to reliably get to the actual document with the following.

CMS.DocumentEngine.TreeProvider tree = new CMS.DocumentEngine.TreeProvider();
var nodes = tree.SelectNodes(CMS.SiteProvider.SiteContext.CurrentSiteName, <path>, "en-us", false, <class name>, "NodeSKUID = '" + skuID + "'");
if (nodes != null)
{
   CMS.DocumentEngine.TreeNode node = nodes.FirstOrDefault();
}
0 votesVote for this answer Mark as a Correct answer

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