Discussions

Is there a way to sell users the ability to create/post nodes (ex. classifieds)?

Hi. I am currently working on a classifieds D7 site, and I would like to sell users the ability to create/post a classified ad. With D6 + Ubercart this can be done using the UC Node Checkout module (http://drupal.org/project/uc_node_checkout), and following the instructions provided on the Drupal Easy website (http://drupaleasy.com/blogs/ultimike/2009/03/event-registration-ubercart).

Is there any way implement the same functionality with D7 + Drupal Commerce?

Thank you so much

Posted: Jul 12, 2011

Comments

rfay Randy Fay on July 25, 2011

One way to do it might be to create a node owned by them when they complete the transaction for them, and give them a link to it. And let them have "edit own" permission on that node type.

A more complex way would be to use rules to give them a role which had create permissions, then strip that role (using rules) when they used it.

Please report back on what you figure out. You're certainly not the only one who will need this.

EclipseGc on July 25, 2011

You'll need a little code, and need to understand a few concepts, but overall this is pretty easy and not actually commerce related really.

1.) Built a table schema that keeps track of uid, count, type. Uid is obviously the user in question, count is the number of creations they've purchased, and type is the node type (bundle) that they've purchased to create.

2.) Build a ruleset that increments the count and tracks the type accordingly when they purchase a product (I would imagine you could make node type an attribute of the product or something simple like that)

3.) From here you can go a couple ways:
3a.) You can build a custom menu item in hook_menu. It's page callback will be node_add(pass the type as an argument) and you'll create a custom access callback that will check the current user/type and see if they have any unused purchases of this type in the count row (I'd personally do a count query to see how many they have, and then compare that with the record in the database so that you don't have to do any magic after creating the node... i.e. we never give the user a lower number in the count column, we just compare the number of nodes of that type they're the author of to the number in count and determine if they are allowed to make more)

3.b) we essentially do all the same stuff I just said in 3.a except we expose the access callback as a page_manager access plugin instead. This increases our code and setup slightly since we'll need to create a page_manager/context_admin page, but context_admin as a node_add plugin built straight in already so all you HAVE to grok is access plugins. This is a totally optional step, but it's one I'd highly recommend long term. It will make the system a lot more reusable ultimately.

Eclipse

rfay Randy Fay on August 7, 2011

I can understand why you'd post multiple places, but you need to understand that many of us are reading and responding in all those places. That means that for your 3 posts we have to do 3 times as much work.

I do appreciate you following up with the crosslinks.