- Posts: 50
- Thank you received: 1
Sort comments on frontend product page
- hawkeyentjc
-
Topic Author
- Offline
Less
More
14 years 1 week ago #66771
by hawkeyentjc
Sort comments on frontend product page was created by hawkeyentjc
Is there any way to add an front-end option for users to sort the vote/comments on product page according to 3 things?
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.
- 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.
14 years 5 days ago #66972
by Xavier
Replied by Xavier on topic Re: Sort comments on frontend product page
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:
After the lines:
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".
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:
Code:
$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';
}
Code:
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.
- hawkeyentjc
-
Topic Author
- Offline
Less
More
- Posts: 50
- Thank you received: 1
14 years 1 day ago #67829
by hawkeyentjc
Replied by hawkeyentjc on topic Re: Sort comments on frontend product page
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!
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.
14 years 9 hours ago #67930
by nicolas
Replied by nicolas on topic Re: Sort comments on frontend product page
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>
<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.
- hawkeyentjc
-
Topic Author
- Offline
Less
More
- Posts: 50
- Thank you received: 1
13 years 11 months ago #69838
by hawkeyentjc
Replied by hawkeyentjc on topic Re: Sort comments on frontend product page
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.
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.
13 years 11 months ago #70023
by nicolas
Replied by nicolas on topic Re: Sort comments on frontend product page
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.
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.
- hawkeyentjc
-
Topic Author
- Offline
Less
More
- Posts: 50
- Thank you received: 1
13 years 11 months ago #70211
by hawkeyentjc
Replied by hawkeyentjc on topic Re: Sort comments on frontend product page
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:
Any solution to this? Thanks.
There's another issue about the Select Option button. The default value is always "Latest Comment". Two things happen here:
- Even if you click "Most Helpful", after the page refresh it returns to "Latest Comment" again.
- 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.
13 years 11 months ago - 13 years 11 months ago #70289
by Xavier
Replied by Xavier on topic Re: Sort comments on frontend product page
Hi,
Try this code in the view "vote / listing":
Where the comments are presented, choose one or the other method, not both.
Try this code in the view "vote / listing":
Code:
<?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: 13 years 11 months ago by Xavier.
Please Log in or Create an account to join the conversation.
Time to create page: 0.221 seconds