Portal Engine Questions on portal engine and web parts.
Version 5.x > Portal Engine > Getting Content Values <cms:RatingControl> back from Linked document View modes: 
User avatar
Member
Member
jwbanning-gmail - 9/16/2011 11:49:15 AM
   
Getting Content Values <cms:RatingControl> back from Linked document
Within the site there is a doc type called Product and then there is a doc type called Featured Product. Featured product extends the Product doc type by containing a couple more fields. The Featured Product doc type also links back to the original Product. The users rate the Product, and I am able to show the ratings. But on the page where I display the Featured products, I would like to display the Product rating. I have having issues with pulling back the ExternalValue in my transformation:

ExternalValue='<%# CMS.GlobalHelper.ValidationHelper.GetDouble(GetSearchValue("DocumentRatingValue"), 0)/((CMS.GlobalHelper.ValidationHelper.GetDouble(GetSearchValue("DocumentRatings"), 0) == 0?1:CMS.GlobalHelper.ValidationHelper.GetDouble(GetSearchValue("DocumentRatings"), 1))) %>'

Any help would be appreciated.

User avatar
Kentico Developer
Kentico Developer
kentico_ivanat - 9/19/2011 2:56:15 AM
   
RE:Getting Content Values <cms:RatingControl> back from Linked document
Hi,

the rating is connected with a document, in the CMS_Document table there is a DocumentRatings column and DocumentRatingValue column. As I said, this value is connected with a document, in your case with a product document and the featured product does not seem to contain the value. I am not sure how you inherited the content from the parent product, but the rating does not seem to be a part of featured product. It is not indexed by the analyzer, therefore your transformation function does not seems to return correct value. You could create a custom field in a featured product document type and inherit the content from the parent. Then the value would be indexed. Alternatively, you could move the rating web part on a featured document.

Maybe, you could create a custom transformation function with parentID parameter (it is probably available in a featured product), and get appropriate value using document API.

If you would like to make this rating field searchable on the featured document (not only display the value), you can take a look at this thread.

Best regards,
Ivana Tomanickova

User avatar
Member
Member
jwbanning-gmail - 9/21/2011 5:38:06 PM
   
RE:Getting Content Values <cms:RatingControl> back from Linked document
"I am not sure how you inherited the content from the parent product, but the rating does not seem to be a part of featured product."

To do this I created a field in the featured product called LinkedProduct. As part of its definition I made LinkedProduct be a Document Selector. It is in this field that I select the Product.

To help me get other attributes out of the main product, Ihave written a helper function that takes 2 parameters, a GUID and a field name. I was thinking that I should be able to use that and pass in "DocumentRatingValue" as the field name. I have included the function below.

private static string GetProductFieldByGuid(string guidStr, string key)
{
Guid guid;
try
{
guid = new Guid(guidStr);
}
catch (Exception e) { return String.Empty; }

TreeProvider tree = new TreeProvider();

DataSet ds = tree.SelectNodes(CMSContext.CurrentSiteName, "/%", CMSContext.CurrentDocumentCulture.CultureCode, true, "acme.Product",
String.Format("NodeGUID='{0}'", guid.ToString()));

if (!DataHelper.DataSourceIsEmpty(ds))
{
object rowVal = DataHelper.GetDataRowValue(ds.Tables[0].Rows[0], key);
if (rowVal != null)
return rowVal.ToString();
}

return String.Empty;
}


Do you see anything that would not allow me to get the DocumentRatingsValue

User avatar
Kentico Developer
Kentico Developer
kentico_ivanat - 9/22/2011 2:41:56 AM
   
RE:Getting Content Values <cms:RatingControl> back from Linked document
Hi,

I have tried to use your code and with a small change and the content rating was returned correctly. The only thing - I had to assign some default value to the guid variable.


string guidStr = "e859d6e1-3bd4-442a-9537-9990ae280fb3";
string key = "DocumentRatingValue";

Guid guid = Guid.Empty;
try
{
guid = new Guid(guidStr);
}
catch (Exception ex)
{
Response.Write("Empty");
}

TreeProvider tree = new TreeProvider();

DataSet ds = tree.SelectNodes(CMSContext.CurrentSiteName, "/%", CMSContext.CurrentDocumentCulture.CultureCode, true, "cms.menuitem",
String.Format("NodeGUID='{0}'", guid.ToString()));

if (!DataHelper.DataSourceIsEmpty(ds))
{
object rowVal = DataHelper.GetDataRowValue(ds.Tables[0].Rows[0], key);
if (rowVal != null)
Response.Write(rowVal.ToString());
}


Could you please check if the content rating for the guid really exists. Is your code executed?

Best regards,
Ivana Tomanickova

User avatar
Member
Member
jwbanning-gmail - 9/22/2011 1:18:47 PM
   
RE:Getting Content Values <cms:RatingControl> back from Linked document
Thanks... Looks like it is working.