How to get ratings and reviews on a products by api?

Posted by Community Admin on 04-Aug-2018 09:24

How to get ratings and reviews on a products by api?

All Replies

Posted by Community Admin on 12-May-2015 00:00

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

Posted by Community Admin on 25-May-2015 00:00

Anyone?

Posted by Community Admin on 26-May-2015 00:00

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;

You can find more information about the threadKey that you have use as parameter for GetThread method directly from sf_cs_threads table.

Regards,
Kaloyan
Telerik
 
Do you want to have your say in the Sitefinity development roadmap? Do you want to know when a feature you requested is added or when a bug fixed? Explore the Telerik Sitefinity CMS Ideas&Feedback Portal and vote to affect the priority of the items
 

This thread is closed