Sort comments on frontend product page

  • Posts: 50
  • Thank you received: 1
12 years 2 months ago #66771

Is there any way to add an front-end option for users to sort the vote/comments on product page according to 3 things?

  • Most Helpful
  • Latest Comment
  • Highest Rating

Currently, we can only sort it from the backend and only based on 2 criteria -> Date & Helpful.

If there's an frontend option for users to sort, it would be great. I believe users would want to have the freedom to choose how they want to view the comments instead of pre-set on backend, especially if a certain product has over 100+ comments.

Any way to achieve this in the current 1.6.0?

Thanks in advance.

Please Log in or Create an account to join the conversation.

  • Posts: 13201
  • Thank you received: 2322
12 years 1 month ago #66972

Hi hawkeyentjc,

Most helpful && Highest rating is the same thing, and latest comment is like date.

To do this, you will have to edit the file "yourSite/components/com_hikashop/views/vote/view.html.php" and in the function "listing()" add a variable like:

$sort_comments = JRequest::getString('sort_comment','');
if($sort_comments == "date"){
	$order = ' ORDER BY `vote_date` ASC';
}else if($sort_comments == "helpful"){
        $order=' ORDER BY `vote_useful` DESC, `vote_date` ASC';
}
After the lines:
if($vote_comment_sort == "date"){
	$order = ' ORDER BY `vote_date` ASC';
}

And edit the view "vote / listing" in the frontend to add a single dropdown which display the 2 possibilities and reload the page when the user select one of these option and set the variable $sort_comments to "date" or "helpful".

Please Log in or Create an account to join the conversation.

  • Posts: 50
  • Thank you received: 1
12 years 1 month ago #67829

Hi Xavier,

I've added the lines to the view.html.php as you suggested.

As for adding the code in "vote / listing" to display the dropdown with the two options, will you be able help to provide some guidance on the coding? As I'm not too familiar with the codes. Thank you so much!

Please Log in or Create an account to join the conversation.

  • Posts: 82863
  • Thank you received: 13372
  • MODERATOR
12 years 1 month ago #67930

You can add such HMTL at the top of that file :

<select name="sort_comment" onchange="this.form.submit();">
<option value="date">Latest Comment</option>
<option value="helpful">Most helpful</option>
</select>

Please Log in or Create an account to join the conversation.

  • Posts: 50
  • Thank you received: 1
12 years 1 month ago #69838

Hi nicolas,

I tried your method. In a way, it did work, but another issue came up.

Each time I select the option, it will refresh the page. However, if my shopping cart has 1 of item X before the page refreshes, it would duplicate the item X after the page refreshes. Meaning, after the page is refreshed, now my cart has 2 of items X, even though I didn't add to cart the item X.

Any solution for this?

Thanks.

Please Log in or Create an account to join the conversation.

  • Posts: 82863
  • Thank you received: 13372
  • MODERATOR
12 years 1 month ago #70023

Hi,

Instead of the line:
<select name="sort_comment" onchange="this.form.submit();">

you should use something like that:
<select name="sort_comment" onchange="var ids = document.getElementsByName('product_id'); ids[0].value=0; this.form.submit();">

That should avoid the product from being added to the cart.

Please Log in or Create an account to join the conversation.

  • Posts: 50
  • Thank you received: 1
12 years 1 month ago #70211

Thanks Nicolas for the workaround. The page refresh no longer adds to cart.

There's another issue about the Select Option button. The default value is always "Latest Comment". Two things happen here:

  1. Even if you click "Most Helpful", after the page refresh it returns to "Latest Comment" again.
  2. Since that's the case, you have no way of selecting "Latest Comment" because it always appears there by default.


Any solution to this? Thanks.

Please Log in or Create an account to join the conversation.

  • Posts: 13201
  • Thank you received: 2322
12 years 1 month ago #70289

Hi,

Try this code in the view "vote / listing":

<?php
	$current_url = hikashop_currentURL();
	$set = JRequest::getString('sort_comment','');
	if(!empty($set))
		$current_url = preg_replace('/\/sort_comment-'.$set.'/','',$current_url); // If using SEF
		$current_url = preg_replace('/&sort_comment='.$set.'/','',$current_url); // If not using SEF
?>
<select name="sort_comment" onchange="document.location.href='<?php echo $current_url; ?>/sort_comment-'+this.value+''"> <!-- using SEF -->
<select name="sort_comment" onchange="document.location.href='<?php echo $current_url; ?>&sort_comment='+this.value+''"> <!-- not using SEF -->

<option <?php if($set == 'date')echo "selected"; ?> value="date">Latest Comment</option>
<option <?php if($set == 'helpful')echo "selected"; ?> value="helpful">Most helpful</option>
</select>

Where the comments are presented, choose one or the other method, not both.

Last edit: 12 years 1 month ago by Xavier.

Please Log in or Create an account to join the conversation.

Time to create page: 0.078 seconds
Powered by Kunena Forum