Linkable Reviews Count on Product Page

UPDATE: See Post 14 for instructions for version 2.0.10 and higher:



For 1.3.5 SP4:

So I used some of the code from mdekok3000 posted in another thread. His code displayed the review count on the review tab itself. I wanted the count next to the stars with the words Customer reviews in front of the stars, a link saying “Read reviews” right before the count which opens the reviews tab and moves the page down to that tab content. The code below will accomplish this task. I updated code below to make this mod SEO friendly.



In addons/discussion/include/customer/products.php



ADD the code below just above the ?>


function fn_get_review_count($object_id,$object_type)
{
global $db_tables;

$discussion = fn_get_discussion($object_id, $object_type);

if (empty($discussion)) {
return false;
}
return db_get_field("SELECT COUNT(b.post_id) as val FROM $db_tables[discussion_rating] as a LEFT JOIN $db_tables[discussion_posts] as b ON a.post_id=b.post_id WHERE a.thread_id='$discussion[thread_id]' and b.avail='Y'"); ;
}


THEN in your_skin/customer/addons/discussion/average_rating.tpl



ADD:

{assign var="rev_count" value=$object_id|fn_get_review_count:$object_type}

BELOW

{assign var="average_rating" value=$object_id|fn_get_average_rating:$object_type}



and then MODIFY:

{include file="addons/discussion/stars.tpl" stars=$average_rating|fn_get_discussion_rating}



TO


Customer reviews: {include file="addons/discussion/stars.tpl" stars=$average_rating|fn_get_discussion_rating} {$average_rating|number_format:1} Read reviews ({$rev_count})





Lastly in /your_skin/customer/products_pages/product_details.tpl

BELOW

```php {*************** /configurator ****************}

```

ADD

```php ```

reviews.jpg

Thanks for your kindly help ! Why the #tab_anchor link to my homepage ?



How to display this on categories page and listmanian ?



Thanks again !

Thats an anchor name to go with the href=“#tab_anchor”



in the line :

Customer reviews: {include file=“addons/discussion/stars.tpl” stars=$average_rating|fn_get_discussion_rating} {$average_rating|number_format:1} Read reviews ({$rev_count})



which takes the user,when they clicked the Read reviews (n) link, to the tab area of a product detail page so the page scrolls down for the user so they know the tab changed . I have a lot of content before my tab area so my users wouldn’t even see the tab area change, so I anchor them down. Also without the anchor you will not get the pretty finger pointing at the link since there would be no href only an onclick event. This mod was specifically designed for product reviews on the product detail page.

[quote name=‘whiplash13’]Thats an anchor name to go with the href=“#tab_anchor”



in the line :

Customer reviews: {include file=“addons/discussion/stars.tpl” stars=$average_rating|fn_get_discussion_rating} {$average_rating|number_format:1} Read reviews ({$rev_count})



which takes the user,when they clicked the Read reviews (n) link, to the tab area of a product detail page so the page scrolls down for the user so they know the tab changed . I have a lot of content before my tab area so my users wouldn’t even see the tab area change, so I anchor them down. Also without the anchor you will not get the pretty finger pointing at the link since there would be no href only an onclick event. This mod was specifically designed for product reviews on the product detail page.[/QUOTE]

Yes, I got what you mean and did as what you said, but it will links to [url]
http://www.mysite.com/#tab_anchor[/url] and then redirect to my homepage, not redirect to Reviews section.



Please tell me how to resolve this, thanks so much !

So you are on a product detail page and you click on Read reviews and it takes you to the homepage with the anchor at the end of the url?



The url should look something like www.mysite.com/store/index.php?target=products&product_id=29780#tab_anchor if you click on the Read Reviews link.



If this is the case then I don’t think you have the href set up correctly if you are going to the homepage. Check your quotes maybe.



Again I only tested this with reviews on a product page so if you are calling a review from the homepage or a testimonial I haven’t coded for or tested that.



Please post your average_rating.tpl.

[quote name=‘whiplash13’]So you are on a product detail page and you click on Read reviews and it takes you to the homepage with the anchor at the end of the url?



The url should look something like www.mysite.com/store/index.php?target=products&product_id=29780#tab_anchor if you click on the Read Reviews link.



If this is the case then I don’t think you have the href set up correctly if you are going to the homepage. Check your quotes maybe.



Again I only tested this with reviews on a product page so if you are calling a review from the homepage or a testimonial I haven’t coded for or tested that.



Please post your average_rating.tpl.[/QUOTE]


[QUOTE]{assign var=“average_rating” value=$object_id|fn_get_average_rating:$object_type}

{assign var=“rev_count” value=$object_id|fn_get_review_count:$object_type}

{if $average_rating}

{include file=“addons/discussion/stars.tpl” stars=$average_rating|fn_get_discussion_rating} {$average_rating|number_format:1} Read reviews ({$rev_count})

{/if}[/QUOTE]

Please check above. I use SEO url, so, it should be like as www.mysite.com/product-url#tab_anchor, right ?



Thanks so much !

[quote name=‘michael’]Please check above. I use SEO url, so, it should be like as www.mysite.com/product-url#tab_anchor, right ?



Thanks so much ![/QUOTE]



That is correct. I haven’t enabled SEO yet on my cart but I am seeing the same result as you are now with the anchor. Let me look into this a bit.



UPDATE:

I got it and updated original post. Tested with and without SEO and it worked for me. Try the code below:


Customer reviews: {include file="addons/discussion/stars.tpl" stars=$average_rating|fn_get_discussion_rating} {$average_rating|number_format:1}   Read reviews ({$rev_count})

[quote name=‘whiplash13’]That is correct. I haven’t enabled SEO yet on my cart but I am seeing the same result as you are now with the anchor. Let me look into this a bit.



UPDATE:

I got it and updated original post. Tested with and without SEO and it worked for me. Try the code below:


Customer reviews: {include file="addons/discussion/stars.tpl" stars=$average_rating|fn_get_discussion_rating} {$average_rating|number_format:1} Read reviews ({$rev_count})[/QUOTE]



Thanks so much ! The code works very well !

[quote name=‘michael’]Thanks so much ! The code works very well ![/QUOTE]



No Problem. I never really liked the way the review score looked on a product page but was too lazy to fix it before.

This looks great, a big improvement on what we have currently got.



Has anyone got this working on 2.0.8 - 2.0.10?



Many thanks

I am working on this. I have fixed the php code so it now pulls the correct review score and number of reviews but I do not know how to select the review tab in 2.0.10 since it has changed so much. I have only been working with v2 since this weekend so I am far from an expert with it. I created a thread in hints and mods to hopefully find someone to help.

[quote name=‘whiplash13’]I do not know how to select the review tab in 2.0.10 since it has changed so much.[/QUOTE]



Excellent. Thank you.



I will have a look at the code and see if I can work anything out.



Many thanks

[quote name=‘glyndon’]Excellent. Thank you.



I will have a look at the code and see if I can work anything out.



Many thanks[/QUOTE]



That would be great if you were able to come up with something. There doesn’t seem to be a function like fn_show_section in 2.0.10. I looked in tabs.js and some of the other js methods and couldn’t find anything re-usable.

This is working in version 2.0.10 - 2.0.13 and works for Product of the day and Category pages as well.



The code below was done for the electro skin so you may need to tweek it a bit for a different skin.



In //addons/discussion/controllers/customer/init.post.php

ADD the code below just above the ?>


function fn_get_review_count($object_id,$object_type)
{
global $db_tables;

$discussion = fn_get_discussion($object_id, $object_type);

if (empty($discussion)) {
return false;
}
return db_get_field("SELECT COUNT(b.post_id) as val FROM ?:discussion_rating as a LEFT JOIN ?:discussion_posts as b ON a.post_id = b.post_id WHERE a.thread_id = ?i and b.status = 'A'", $discussion['thread_id']);

}




NEXT in skins/electro/customer/common_templates/scripts.tpl



ADD

{if $smarty.request.show_reviews == "Y"} setTimeout("fn_show_reviews_tab();", 1000); {/if}

AFTER

jQuery.runCart('C');



NEXT in skins/electro/customer/addons/discussion/views/discussion/components/average_rating.tpl

ADD

{assign var="rev_count" value=$object_id|fn_get_review_count:$object_type}


BELOW

{assign var="average_rating" value=$object_id|fn_get_average_rating:$object_type}


THEN

ADD

```php {literal}


{/literal} ```

BELOW

{if $average_rating}

THEN

REPLACE

{include file="addons/discussion/views/discussion/components/stars.tpl" stars=$average_rating|fn_get_discussion_rating}


WITH


{include file="addons/discussion/views/discussion/components/stars.tpl" stars=$average_rating|fn_get_discussion_rating} {$average_rating|number_format:1}

{if $smarty.request.product_id}
Read reviews ({$rev_count})
{else}
Read reviews ({$rev_count})
{/if}



LASTLY

In skins/electro/customer/addons/discussion/views/discussion/components/stars.tpl

REMOVE the

and

tags as they were moved to average_ratings.tpl.

Hello,



Could one of you post a link to your site so I can get a look at what this does. I think I know but not sure of how it will work on my site and do not want to make all those changes until I do.



Thanks so much.

[quote name=‘ywalker’]Hello,



Could one of you post a link to your site so I can get a look at what this does. I think I know but not sure of how it will work on my site and do not want to make all those changes until I do.



Thanks so much.[/QUOTE]



My site is not live so I can’t post a link but here is an image from my local environment with this mod. When the user clicks the Read Reviews (n) the Review tab on the detail page is selected.

12-27-2009 8-32-13 PM.jpg

Thanks, that’s what I thought. I am not live yet either but will definitely make the changes above because right now a shopper would not know if the product has reviews or not unless they click on the tab.



Thanks so much for sharing.

[quote name=‘ywalker’]Thanks, that’s what I thought. I am not live yet either but will definitely make the changes above because right now a shopper would not know if the product has reviews or not unless they click on the tab.



Thanks so much for sharing.[/QUOTE]



FYI. If you are using 2.0.11 there is a bug in the bug tracker that the review stars don’t show on a product detail page so right now this will only work on 2.0.10.

Just an FYI, these changes work fine for 2.0.12 as well

Sorry for my bad english, what you mean with

[quote]

Just an FYI

[/quote]



Also your first post work on 2.0.12 or not?



Thanks!