4 replies [Last post]
SamSound's picture
Offline
Joined: 10/10/2009
Juice: 3
Was this information Helpful?

As this forums/modules been up for a few years i though Id come here first as theres probably somebody whos wanted this same feature.

Im using voting api and im wondering is there a way I can set a restriction that only enables users to vote on a product once theyve purchased it.

As this is a similar system to ebays rating system, im certain this would have came up before, which makes me feel that this would take something serious.

I dont mind doing the leg work, but I have no idea what im doing.

Any helps and advice is appreciated.

Thanks

ledom's picture
Offline
Joined: 10/08/2008
Juice: 83
Same request here! Fivestar

Same request here!
Fivestar is fine but allow everybody to vote...

May be an idea:
Read only fivestar on products page and products list
Create a vote-allowed role and a buyer role

I someone make an order, then when the order status is terminated, his role change from buyer to vote-allowed
Then he can go to his order page, where he can vote with a write enable fivestar.

drupaldave's picture
Offline
Joined: 07/18/2012
Juice: 6
Possible solution with fivestar

Found some snippets on the internet I put together on Drupal 6. I'm using Ubercart and Ubercart marketplace though should work with just Ubercart alone in theory. (Has not been thoroughly tested yet but seems to work)

Change the fivestar.module file to be this (the main change is that user_purchased call) and add the user_purchased function below:

function fivestar_fivestar_access($type, $id, $uid) {
if ($type == 'node' && $node = node_load($id)) {
if (variable_get('fivestar_'. $node->type, 0)) {
if (user_purchased($id))
{
return TRUE;
}
}
}
}

/**
* Implementation of user_purchased().
*
* This function checks if the user has purchased this product already
*
*
* @return true, false
* true if user purchased, false otherwise
*
*
*/
function user_purchased($nid){
global $user;
$sql = "SELECT uop.nid FROM {uc_order_products} uop
LEFT JOIN {uc_orders} uo ON uo.order_id = uop.order_id
WHERE uo.uid = %d AND uop.nid = %d AND uo.order_status in ('completed', 'payment_received')";
$rs = db_query($sql, array($user->uid, $nid));
$row = db_fetch_object($rs);
return $row->nid;
}

Bruiseviolet's picture
Offline
Joined: 10/22/2010
Juice: 231
Re: voting on products only if user has purchased that product

Would love to find this as well- because we are getting a lot of "spammers" leaving spam posts on our 5 star rating product comments. ARG.

Mom. Entrepreneur. Awesome. www.frequencyapps.com

drupaldave's picture
Offline
Joined: 07/18/2012
Juice: 6
see the post above for code with fivestar that should work

Take a look at the two functions posted above. if you modify fivestars fivestar.module file with those it should work. Replace the access function with the new one. Add the second function there. Give it a try...