Take the 2-minute tour ×
Drupal Answers is a question and answer site for Drupal developers and administrators. It's 100% free, no registration required.

I have a view with a list of product displays, and I would like to hide all the products that are already purchased by the current user. This would allow purchasing products only once per user.

I've tried to modify the view and add a relationship with the order, but I can't find the relationship "Order". As explained in the similar issue http://drupal.org/node/1221372 , I also tried to create a view of "Commerce Order". I think this would work for displaying a list of purchased products, but not for displaying a list of non-purchased products, because a view of 'Commerce Order' displays results with orders, not results without orders.

Can anyone help me? :)

share|improve this question
    
Why you are restricting the purchase, suppose if the client want to add more quantity what will you do?, i know we can do it in cart itself, but appearing in the view is the easiest navigation. –  Bala Feb 21 '13 at 6:11
    
Some of the products we want to sell should not be bought more than once per customer –  Pere Feb 21 '13 at 7:47
    
"This would allow purchasing products only once per user." This is certainly not true, just because it's not listed, it would not mean that they could not A) Access it directly B) Even if A is covered, without any actual code to check if they have not bought it before, they could still purchase it if they sent a specially crafted POST request to add it to their cart. –  Phizes Feb 22 '13 at 14:30
    
Sorry I was not clear enough. My products are virtual, I just want to save me time refunding the money to the customers who accidentally buy products multiple times. For me it's OK if some superuser wants to pay for something he already has :) –  Pere Feb 22 '13 at 15:17
add comment

1 Answer 1

up vote 1 down vote accepted
+50

I would use Content Access to restrict access to nodes by role, then I would make a special role that is required for viewing this product. Then I would create a Rule where buying that product triggers that role being removed from the user.

share|improve this answer
    
But this means creating a role and a rule for every product right? –  Pere Feb 21 '13 at 7:50
    
Yes. This solution isn't scalable to large sets of products. For that you'd want a custom module that examines the user's purchase history and hides previously purchased items. –  betherwisser Feb 21 '13 at 14:02
    
You would want Node Access User Reference or Content Access plus ACL –  betherwisser Feb 21 '13 at 14:26
    
I already knew that Content Access + ACL can grant access to specific nodes per user. But would be great if I could restrict the access to it, not only grant it, through a rule. –  Pere Feb 21 '13 at 20:34
    
I would look at hook_node_grants() –  betherwisser Feb 22 '13 at 0:37
show 3 more comments

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.