3

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? :)

4
  • 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, 2013 at 6:11
  • Some of the products we want to sell should not be bought more than once per customer
    – Pere
    Feb 21, 2013 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, 2013 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, 2013 at 15:17

1 Answer 1

1
+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.

8
  • But this means creating a role and a rule for every product right?
    – Pere
    Feb 21, 2013 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.
    – beth
    Feb 21, 2013 at 14:02
  • You would want Node Access User Reference or Content Access plus ACL
    – beth
    Feb 21, 2013 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, 2013 at 20:34
  • I would look at hook_node_grants()
    – beth
    Feb 22, 2013 at 0:37

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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