Tags/topics: 
1
Answers
Vote up!
0
Vote down!

Selling Content

Here is what I would like to do. I have a bunch of stuff I have written that I believe is sellable. My goal is to setup a Drupal View that displays this content (this part I know how to do) with the title and a short summary. When the user (anonymous or logged in) clicks on the Read More link they see a small snippet of the content along with a Purchase Now button to get access to the entire page.

I'm sure this is possible but I have no idea how to implement it. Any ideas?

Asked by: jlrobinson2171
on December 16, 2013

1 Answer

Vote up!
1
Vote down!

Here is what I understood. You have a view which lists a bunch of products. When a user clicks on any row, he is taken to another page where he can only see the title, teaser and add to cart button (unless he has already purchased the product). If the user has already purchased this product, then he should be able to see the full content of that page. I am also assuming that when the user has bought any product, his role will change to "Customer". As a Customer, he can access any product (this is generally valid for subscription sites). If this is correct, then read the next paragraph. On the other hand, if the user gets access to only the resource that he bought, then read the paragraph after that.

Subscription site - Customer has access to all the products

The easiest way to accomplish this will be to use field permissions module (https://drupal.org/project/field_permissions). By default, Drupal offers one body field in a content type. This body field can also have a summary. Unfortunately there is no way to restrict the visibility of summary and full body independently of each other. So create a separate field called teaser. Put the short summary that you want to show to people who have not bought the product in this teaser field. Put the full document in the body field. Now use field permissions so that only the people with customer role (and admin + staff) can view the body field. People with customer role should not be able to see the teaser field. On the other hand, all the other roles should only be able to see the teaser field and not the body field.

Product site - Customer has access to only the product that he bought

This is more complicated since the access does not depend on the role only. We need to check whether the user actually bought the product that he is viewing. Using hook_menu(), create a new path such as "node-teaser/%node". Define a custom access callback for this menu item. In this callback, check whether the current user has bought the product attached to this display node. If yes, then use drupal_goto to redirect the user to "node/%node". If not, just show the title, teaser and add to cart form using a custom view mode that can be created via hook_entity_info_alter() or Display Suite module. You will also need to use hook_node_access() to restrict the visibility of the node/%node path based on whether the user has bought that product or not.

Feel free to email me at [email protected] if you have more question regarding this.

Regards,
Neerav Mehta.
The Drupal Experts

Answer by: neeravbm
Posted: Dec 17, 2013

Comments

The second paragraph is more of what I am looking for but that is a bit beyond my experience level. There isn't a simpler way to do it? An existing module perhaps?

- jlrobinson2171 on December 19, 2013

If you don't want to create view mode, you could also use preprocess function to show/hide fields depending on the user. But even that will require some coding.

- neeravbm on January 2, 2014