How To: Add Random Star Ratings w/o Reviews

For articles specific to version 6.x
Post Reply
MegaFemaTron2
Confirmed
Confirmed
Posts: 84
Joined: Thu Oct 13, 2011 8:37 pm

How To: Add Random Star Ratings w/o Reviews

Post by MegaFemaTron2 »

If you'd like to play around with adding random star ratings for your products without the need to create reviews as well, I've come up with the following script. I really only wanted to add star ratings (like how many carts will allow customers to just rate the product without forcing a review), but it looked like I was going to have to add bogus reviews as well. After struggling with automating that, I cleared the review table to start over, only to find the star ratings were still there. So I tweaked the script to first add bogus reviews to isc_reviews, add the rating details to isc_products based on what's in isc_reviews and then delete all the records in isc_reviews. So you are just left with ratings for all of your products. You can tweak it to only work on a few products or all of them. I tested it on a db with 7k products (added a rating to all of them).

*It's up to you how you use this. It has a few more uses than adding your own star ratings to a live site.

Code: Select all

<?php

// Make a MySQL Connection
mysql_connect("localhost", "your db username", "your db password") or die(mysql_error());
mysql_select_db("your db name") or die(mysql_error());

//grab some product ids from isc_products <-- you could probably limit how many products here
$result = mysql_query("SELECT productid FROM isc_products WHERE prodvisible = '1'") 
or die(mysql_error());

// for each of those product ids, run the function below
while($row = mysql_fetch_array( $result )) {
$prodid = $row['productid'];
RandomRatings($prodid);
}

// This query runs last and removes everything from isc_reviews
$result4 = mysql_query("DELETE FROM isc_reviews WHERE revdate = '0'")
or die(mysql_error());


// This function inserts sample reviews in isc_reviews with a random rating between 3-5 and already approved. Then it inserts rating data into isc_products
function RandomRatings ($prodid){
$ranrate = rand(3,5);

$result1 = mysql_query("INSERT INTO isc_reviews SET revproductid = '$prodid', revrating = '$ranrate', revstatus = '1'") 
or die(mysql_error());

$result2 = mysql_query("SELECT revrating FROM isc_reviews WHERE revproductid = '$prodid'") 
or die(mysql_error());

while($row2 = mysql_fetch_array( $result2 )) {
$result3 = mysql_query("UPDATE isc_products SET prodnumratings = prodnumratings+1, prodratingtotal = prodratingtotal+'".(int)$row2['revrating']."' WHERE productid = '$prodid'")
or die(mysql_error()); 
}
 }
?>
Last edited by MegaFemaTron2 on Mon Feb 06, 2012 7:58 pm, edited 2 times in total.
ISC 6.1.1 Ultimate Edition
CharlieFoxtrot
Confirmed
Confirmed
Posts: 413
Joined: Sun Aug 09, 2009 1:23 pm

Re: How To: Add Random Star Ratings w/o Reviews

Post by CharlieFoxtrot »

Hmmm... I have mixed feelings about this. Although I understand the strong desire to have customer reviews and ratings-stars... and I realize that this can be a motivator for some buyers... what you're suggesting is a gimmick that misleads customers. ~ If anyone ever finds out that your business fakes the stars, then your reputation will be damaged. (For me, it's not worth the risk.)

My own product reviews are thin. I've got fewer than I'd like to have as well. However, I've found that simply ASKING a customer if they will give a review is often successful.

In addition, I'll occasionally receive an email from a customer letting me know how pleased they are with a specific purchase (or with customer service in general.) ~~ When I'm fortunate enough to receive such a flattering email... I will reply with humble gratitude, AND I'll ask them if I can use their comments as a testimonial on the site.

EVERYONE I've ever asked has always given permission... so I'll use their own words when I manually create review of the item they recently purchased. (Even if it's a "customer service" review and not an actual product review... I'll add their kind words to the product they purchased.)
ISC 4.0.7

"... and let's be honest that whole "by design" thing is getting old too."
MegaFemaTron2
Confirmed
Confirmed
Posts: 84
Joined: Thu Oct 13, 2011 8:37 pm

Re: How To: Add Random Star Ratings w/o Reviews

Post by MegaFemaTron2 »

There are other uses for this, i.e. if you are selling design services or ISC management services, etc. and want to show as much functionality as possible, etc. So if someone wants to do this without having to fill out all the fields then it's here.
ISC 6.1.1 Ultimate Edition
Post Reply