+1-888-365-2779
Try Now
More in this section

Forums / Developing with Sitefinity / How to get ratings and reviews on a products by api?

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

3 posts, 0 answered
  1. Ajai
    Ajai avatar
    15 posts
    Registered:
    02 Mar 2015
    12 May 2015
    Link to this post

    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

  2. OC
    OC avatar
    129 posts
    Registered:
    17 Nov 2004
    25 May 2015
    Link to this post
    Anyone?
  3. Kaloyan
    Kaloyan avatar
    272 posts
    Registered:
    02 Dec 2016
    26 May 2015
    Link to this post
    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
     
3 posts, 0 answered