Comments
Comments and ratings on products
DynamicWeb contains support for implementing comments and ratings on products and reviewing them from the backend.
Posting comments & ratings
Comments are created by submitting a form with specific properties - such as the id commentform and a set of input fields with data, e.g. a comment and a rating, etc. - to the system.
Here is a example template which implements all features supported by the comments-feature:
<form method="post" action="/Default.aspx?ID=@pageView.ID" id="commentform">
<!--These fields instruct DW10 to create a comment for a product-->
<input type="hidden" name="Comment.Command" id="Comment.Command" value="create" />
<input type="hidden" name="Comment.ItemType" value="ecomProduct" />
<!--This field controls if the comment is active when created. Set to false if you want to approve comments before publishing them-->
<input type="hidden" name="Comment.Active" value="true" />
<!-- These values make sure the comment is registered to the right product -->
<input type="hidden" name="Comment.ItemID" value="@Model.Id" />
<input type="hidden" name="Comment.LangID" value="@Model.LanguageId" />
<!--Comment.Continue takes an URL to redirect the user to after submitting their comment. Defaults to -->
<input type="hidden" name="Comment.Continue" value="@pageView.SearchFriendlyUrl" />
<!--Comment.ParentID should be set to the ID of the comment which is being replied to - here this is done via the comment_reply JS function-->
<input type="hidden" name="Comment.ParentID" id="Comment.ParentID" value="0" />
<!--Notification email details - intended to notify someone to review this comment-->
<input type="hidden" name="Comment.Notify" value="true" />
<input type="hidden" name="Comment.NotifyTemplate" value="Comments/Notify.cshtml" />
<input type="hidden" name="Comment.NotifySubject" id="Comment.NotifySubject" value="New comment on @Model.Name " />
<input type="hidden" name="Comment.NotifySenderEmail" value="noreply@dynamicweb.dk" />
<input type="hidden" name="Comment.NotifySenderName" value="Website comment" />
<input type="hidden" name="Comment.NotifyEmail" value="cbo@dynamicweb.dk" />
<!--Notification email settings for replies-->
<input type="hidden" name="Comment.Reply.Notify" value="true" />
<input type="hidden" name="Comment.Reply.NotifyTemplate" value="Comments/ReplyNotify.cshtml" />
<input type="hidden" name="Comment.Reply.NotifySubject" value="SomeValue" />
<input type="hidden" name="Comment.Reply.NotifySenderEmail" value="noreply@dynamicweb.dk" />
<input type="hidden" name="Comment.Reply.NotifySenderName" value="Webmaster" />
<!-- Comment Input Fields - your users will typically add data to these-->
<label for="Comment.Name">Name</label>
<input type="text" class="form-control" name="Comment.Name" id="Comment.Name" value="@if (currentUser != null) {@currentUser.Name }" /><br />
<label for="Comment.Email">E-mail </label>
<input type="text" class="form-control" name="Comment.Email" id="Comment.Email" value="@if (currentUser != null) {@currentUser.Email }" /><br />
<label for="Comment.Website">Website</label>
<input type="text" class="form-control" name="Comment.Website" id="Comment.Website" value="" /><br />
<label for="Comment.Rating">Your rating</label>
<select class="form-control" name="Comment.Rating" id="Comment.Rating">
<option value="">Rate product....</option>
<option value="1">1 (Poor)</option>
<option value="2">2 (Below average)</option>
<option value="3">3 (Average)</option>
<option value="4">4 (Good)</option>
<option value="5">5 (Great)</option>
</select><br />
<label for="Comment.Text">Comment </label>
<textarea class="form-control" name="Comment.Text" id="Comment.Text" rows="10" cols="50"></textarea><br />
<input class="btn btn-primary" type="submit" value="Post Comment" />
</form>
Rendering comments & ratings
Comments are not available on the ProductViewModel - you have to use the C# API. In this example we create an instance of CommentService and CommentFilter, then use the GetComments()-method with the filter to retrieve all comments belonging to a specific product:
@{
Dynamicweb.Content.Commenting.CommentService commentservice = new Dynamicweb.Content.Commenting.CommentService();
Dynamicweb.Content.Commenting.CommentFilter filter = new Dynamicweb.Content.Commenting.CommentFilter();
filter.ItemType = "ecomProduct";
filter.ItemId = Model.Id;
Dynamicweb.Content.Commenting.CommentCollection comments = commentservice.GetComments(filter);
}
@foreach (var comment in comments)
{
<div>
<div><b>Commenter:</b> @comment.Name</div>
<div><b>Rating:</b> @comment.Rating</div>
<div><b>Comment:</b> @comment.Text</div>
</div>
}