How to get ratings and reviews on a products by api?
Hi all,
i am working on sitefinity version 7.0.
I am using eCommerce section in that. I have created the products and enabled the comments and review on products.So users can review and comment on products.
How can i retrieve the ratings and reviews on a particular product by using Api?
Thanks
Anyone?
Hello Guys,
What you need to use is comments API. I have a sample for news items based on the last code snippet provided in the following documentation article. The approach for products is just the same.
Query comments
NewsManager manager = NewsManager.GetManager();
var newsItem = manager.GetNewsItems().Where(t => t.Title ==
"Test"
&& t.Status == ContentLifecycleStatus.Live).FirstOrDefault();
// Gets an instance of the comments service
var cs = SystemManager.GetCommentsService();
//instantiate comment filter
var commentFilter =
new
CommentFilter();
//add filter by News
commentFilter.ThreadType.Add(
typeof
(NewsItem).FullName);
//get the comment with the specified commentKey
var comments = cs.GetComments(commentFilter);
var ratings = cs.GetThread(newsItem.Id +
"_"
+ CultureInfo.CurrentCulture.Name.ToString() +
"_review"
).AverageRating.Value;