Press Ctrl / CMD + C to copy this to your clipboard.
This post will be reported to the moderators as potential spam to be looked at
Any suggestions on how to do this? I've been poking about the documentation and intellisense all day and not getting anywhere near it.
I'm using Razor
Hi Tony,
There's a GetCategories() method on UCommerce.EntitiesV2.Product, which will give you the categories for the product.
If someone wants this feature for XSLT, put the following function in a XSLT extension class and enjoy:
public static XPathNodeIterator GetProductCategories(string sku) {
XmlDocument xmlDoc = new XmlDocument();
try { var product = UCommerce.EntitiesV2.Product.Find(p => p.Sku == sku && p.VariantSku == null).Single(); var categories = product.GetCategories();
if(categories.Count() > 0) {
CategoryRenderer cr = new CategoryRenderer(new PropertyRenderer()); return cr.RenderDocument(categories, "categories").CreateNavigator().Select(".");
}
xmlDoc.LoadXml("<categories />"); return xmlDoc.CreateNavigator().Select(".");
} catch(Exception ex) { xmlDoc.LoadXml("<error><message>" + ex.Message + "</message><stack>" + HttpUtility.HtmlEncode(ex.StackTrace) + "</stack></error>"); return xmlDoc.CreateNavigator().Select("."); }
is working on a reply...
Write your reply to:
Upload image
Image will be uploaded when post is submitted
List all categories a product is in on it's details page
Any suggestions on how to do this? I've been poking about the documentation and intellisense all day and not getting anywhere near it.
I'm using Razor
Hi Tony,
There's a GetCategories() method on UCommerce.EntitiesV2.Product, which will give you the categories for the product.
If someone wants this feature for XSLT, put the following function in a XSLT extension class and enjoy:
public static XPathNodeIterator GetProductCategories(string sku) {
XmlDocument xmlDoc = new XmlDocument();
try {
var product = UCommerce.EntitiesV2.Product.Find(p => p.Sku == sku && p.VariantSku == null).Single();
var categories = product.GetCategories();
if(categories.Count() > 0) {
CategoryRenderer cr = new CategoryRenderer(new PropertyRenderer());
return cr.RenderDocument(categories, "categories").CreateNavigator().Select(".");
}
xmlDoc.LoadXml("<categories />");
return xmlDoc.CreateNavigator().Select(".");
}
catch(Exception ex) {
xmlDoc.LoadXml("<error><message>" + ex.Message + "</message><stack>" + HttpUtility.HtmlEncode(ex.StackTrace) + "</stack></error>");
return xmlDoc.CreateNavigator().Select(".");
}
}
is working on a reply...