Portal Engine Questions on portal engine and web parts.
Version 6.x > Portal Engine > Custom Properties on E-Commerce Product View modes: 
User avatar
Member
Member
Andrew - 5/29/2012 5:28:57 PM
   
Custom Properties on E-Commerce Product
Hi,

I have multiple E-commerce products with custom properties and I'm working solely in the C# code-behind. Starting with only the SKUID of one specific product, I want to be able to take that SKUID and get the names and values of the custom properties for that product. I also have different document types for the various products, so they all have different custom properties.

(By custom properties, I'm referring to the ones for document types outlined here: http://devnet.kentico.com/Knowledge-Base/E-commerce/How-do-document-types-differ-from-e-commerce-produ.aspx)

User avatar
Member
Member
kentico_michal - 5/30/2012 4:21:57 AM
   
RE:Custom Properties on E-Commerce Product
Hi,

You can take advantage of the SKUInfo class that represents a product.

SKUInfo info = SKUInfoProvider.GetSKUInfo(skuid);

You can use the SKUInfo object to access all standard product properties including custom ones (with the help of the GetValue method).

Best regards,
Michal Legen

User avatar
Member
Member
Andrew - 5/30/2012 11:31:09 AM
   
RE:Custom Properties on E-Commerce Product
Hi,

Thanks for replying. I've worked with GetValue before and the problem with it is that you need to know the name of the column you want to get data for. I want to get the column names in addition to the data inside of them. (I don't know the column names because I want this to work for any kind of product/document type)

User avatar
Member
Member
Andrew - 5/30/2012 3:49:36 PM
   
RE:Custom Properties on E-Commerce Product
Actually, I forgot to mention that I've never gotten GetValue to work for custom properties. Properties in the SKU table work fine, but whenever I enter a custom property into GetValue it only returns null.

User avatar
Member
Member
kentico_michal - 5/31/2012 2:46:02 AM
   
RE:Custom Properties on E-Commerce Product
Hi,

I am sorry, I think I did not understand you correctly. You are trying to access custom document properties through the SKUInfo object? Is that correct?

If so, it is not possible because a simple product (SKUInfo) can be assigned to multiple documents (TreeNode) and the system would not know from which document you want to retrieve those custom properties. So, to get custom document properties, you need to get the TreeNode object to which the product is assigned and use the GetValue to access the properties.

The information about a product which is assigned to a document is stored in the NodeSKUID field:

TreeNode.NodeSKUID = SKUInfo.SKUID;

Best regards,
Michal Legen

User avatar
Member
Member
Andrew - 5/31/2012 11:56:30 AM
   
RE:Custom Properties on E-Commerce Product
Hi,

Using a document appears to be the solution I needed for getting custom properties. However, the other part of the problem that I outlined is that I need to also get what those property names are for a specific document. I can see them listed in, for example, the column names, but there are also a lot of other properties.

(I'm working under the assumption that I don't know what the column names are for the custom properties)

User avatar
Member
Member
kentico_michal - 6/1/2012 2:33:06 AM
   
RE:Custom Properties on E-Commerce Product
Hi,

You can use the following code to get a list of all custom document properties. All you need to specify is the class name such as cms.news or cms.article:

        DataClassInfo dci = DataClassInfoProvider.GetDataClass("<class name>");
if (dci != null)
{
CMS.FormEngine.FormInfo fi = new CMS.FormEngine.FormInfo(dci.ClassFormDefinition);
string [] columnNames = fi.GetColumnNames();
}


Best regards,
Michal Legen

User avatar
Member
Member
bryan.green@rockfishinteractive.com - 8/30/2013 2:23:10 PM
   
RE:Custom Properties on E-Commerce Product
The code that accomplishes this at runtime (this is for more clarity):

ascx -

<%=String.Format("{0}:{1}",GetCustomProductData(item,"VariantName","/Shop/%"),GetCustomProductData(item,"VariantValue","/Shop/%"))%></p>


code behind -


protected static object GetCustomProductData(ShoppingCartItemInfo item, String propertyName, string propertyPath, string documentType = "CMS.Product")
{
//get the product document
var d =
TreeHelper.SelectNodes(propertyPath, false, documentType, "", "", -1, true)
.Where(x=>x.NodeSKUID == item.SKUID)
.FirstOrDefault();

if (d != null)
{
return d.GetValue(propertyName);
}
else
return null;
}