I don't have commit access and you're probably asleep, so here's a patch and some explanation.
We discussed today the problem of charging for created nodes.
The requirement is to have a line item per created node (with the correct start and end dates), not one line item per all created nodes like the gauge usage group does.
Our initial idea was to make usage records into entities, supply a new usage record bundle, supply a new usage group plugin. That was to be quite a bit of work and even added complexity.
Luckily I managed to catch DamZ online and we discussed this and other related problems for quite a while, and his idea was to establish the best practice saying "if you want a line item per usage record, you actually want to use a sublicense". This is similar to what Platform is doing for the user licenses, and in this case means creating a license for each published node (and revoking it when the node gets unpublished).
So the rule of thumb is the same as for regular line items, if you're charging for one thing, have one line item.
If you're charging for different things, have different line items (and matching licenses).
Also, it makes sense to tie the node creation privilege to some kind of a main membership license type.
Currently the only one we have is "role" (we might want a generic one in the future that does nothing, but it's handy to have a matching role assigned to check against), so I've added a "role_node" license type that extends the role license type with the ability to track node creation via usage.
Of course, this usage mustn't result in a line item, since the sublicenses will get a line item each.
So I've pushed a commit to commerce_license_billing
that allows you to have non-charged usage (just for tracking purposes).
I've also added a "node" license type to serve as the sublicense.
It takes advantage of the "no ui" option I just committed to commerce_license that allows it to not show up in the UI (the license type selector).
I've also made some misc fixes along the way (for instance, prefixing the fields with cl_ instead of commerce_license to get around the 32 character field name limit you were hitting).
TODO:
1) Make this work for license types that extend role_node. There are todos in the code for places that need changing.
2) Add a form alter (and matching IEF form alter) that hides the "published" option (and defaults it to FALSE) for non-admins without a master license creating licensable node types.
3) Implement a pricing rule that makes the first $quota sublicenses free.
4) Do a lot of testing :)
| Comment | File | Size | Author |
|---|---|---|---|
| #1 | 2157885-initial-code.patch | 16.95 KB | bojanz |
Comments
Comment #1
bojanz commentedCompletely untested.
Comment #2
bojanz commentedAlso, this needs a hook_node_insert() for nodes created & published right away.
Comment #3
dwkitchen commentedHad to make some slight changes, but as expected for and untested patch.
Now working on initial creation and testing the billing.
http://drupalcode.org/project/commerce_license_node.git/commit/c815097
Comment #4
dwkitchen commentedAnd now with the node_insert hook
http://drupalcode.org/project/commerce_license_node.git/commit/aad327a