3

I have three products, A B and C. Anyone can buy products A or B, but only users with the VIP role should be able to buy product C.

How can I make sure users don't see product C if they don't have the VIP role? (It would be best if they could not buy it at all, but I will settle for a solution that simply hides it.) My products are displayed in a view using a Product display content type.

  • Are product nodes? Do I remember that one right? And is it Drupal 7? – Mołot Jul 19 '13 at 14:07
  • @Mołot Yes, D7. Products are not nodes; the Product Display content type has a field reference to products, which are entities (but not nodes). In this case, there is a Product Display node for each product, so it's probably safe to treat them as nodes. – Patrick Kenny Jul 19 '13 at 14:09
  • 1
    Damn, Taxonomy Access Control wasn't converted to entities yet. – Mołot Jul 19 '13 at 14:13
  • 1
    D'oh, yes I see it now. How private does the product C have to be? If you were happy for them to see it, but not buy it, there should be a way of creating a rule for when the product is added to cart, do a data comparison on the product type and the users role, and then remove it if they arent allowed to buy it – Andrew Morris Jul 19 '13 at 14:22
  • 1
    I have read thorough access control modules queues, and found this: >> No. The keyword is "in core". There is a push to generalize D8 node access into entity access, and when that happens, ACL will follow. << It means, if there is no such option in a module that provides and uses given entity, it is not yet possible to do it outside. I also checked available hooks - entities does not have anything like hook_node_access. Only solution I found Is really, really weird. – Mołot Jul 19 '13 at 14:44
3

You should create an additional "VIP ONLY" product display - a node type that aggregates products and effectively shows them in the front-end.

With this new content type you could tap into its permission system using Content Access and limit the "View" permission to the "VIP user role".

When you want to create a VIP product simply create a new "VIP ONLY" node.

Steps:

  1. Create a new node type in admin/structure/types . Call it "VIP ONLY".
  2. Add a product reference field to the node. Use the existing field. It will now be listed in views that list product display types.
  3. Setup the permissions as per above.
  4. Profit.
  • Products are not nodes, see comments under question. – Mołot Jul 19 '13 at 14:47
  • I do know that. However products are displayed in a node that relates them. I was refering to that exactly. Since you cannot easily control product entities, you could fine grain control the node that effectively displays them. – mariomc Jul 19 '13 at 14:50
  • Give that the user wants to hide a full product page and not product variations, this solution works perfectly for the use case. – mariomc Jul 19 '13 at 15:02
  • Given that accidentally purchasing the product is ok, this is by far the cleanest solution without resorting to code. However, I believe phase 3 is traditionally the "Profit" phase - if we're going by standard gnome rules ;) – Clive Jul 19 '13 at 16:30
  • I ended up taking this idea and doing it with content panes and Panels, since I already was using Panels on the site. – Patrick Kenny Jul 19 '13 at 16:34

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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