This is a blatant, unashamed edit of uc_roles, with my thanks for the fine module to rip apart. The intent of the edit was to handle node publication in exactly the same manner as role asignment. Node poduct and node expiry tables are created, and the module syncs with the scheduler module. Not sure if this is necessary, but most who deal with node expiry seem to be using it.

This module appears to be working, but it needs EXTENSIVE testing. Please do not rely on it yet. The code is in rough shape, and I upload it so other, more experienced eyes can tell me where I have gone wrong.

Like uc_roles, thi module adds a node publication feature for a product which should work the same as role assignment in uc_roles.

uc_nodes-5.x-1.0-alpha.tar.gz11.96 KB
Ryan's picture
Joined: 08/07/2007
Juice: 15476
Re: uc_nodes

Excellent idea! Thanks for posting. I'll remember this if I ever need this kind of feature. Smiling

triskelion's picture
Joined: 06/30/2008
Juice: 25
RyanThanks for noticing the


Thanks for noticing the upload.

I want to make it abundantly clear that this module is at the 'plaything' stage of development. There is still a lot of uc_roles code in it that will break its function, and I am still labouring with the 'Now I see what he was doing' impediment that comes with trying to rework someone elses code.

The main problem is linking the node to be published with Ubercart. I am experimenting with an orphan attribute, node_id, to be picked up from ->data['node_id'], relying on Cart Links to create the order item. Right now I am using a CCK computed field in the content type to be published to create the link, but I would really like to see a 'Publish Now' button that could be placed in a view, and which did not have to be attached to the node. (I anxiously await computed fields for Views.)

One of the major problems I have run into is that 'Order Status Gets Updated' appears to be flaky with non-shippable items (is this a bug?), so I have to rely on module code. Probably a good idea in any event to have as much of the function self-contained as possible. I also have to ask why 'is shippable' is even an option with uc_roles. I am toying with the idea here of forcing it to false.

Anyway, if anyone has any time to play, I would appreciate any suggestions, and snippets if you have them:-)

Lyle's picture
Joined: 08/07/2007
Juice: -40968
Re: RyanThanks for noticing the

It probably be wouldn't used very much, but I can see someone selling a physical token to represent the user's role on the website. A badge or some kind of certificate.

The shippable checkbox is a generic product feature...feature. It makes more sense for file downloads, but it would take more work to turn it off for roles.

triskelion's picture
Joined: 06/30/2008
Juice: 25

This is my first attempt to put together a module, and I am posting copies here to see if anyone has any suggestions. The previous code worked in harness, but was a long way from integration. I put it up as a concept to see if there were any ideas on how to approach the function. Since then I have made some decisions and changes, and it is mostly integrated into Ubercart.

Unlike uc_roles, which can take advantage of the $user array for the current user, uc_nodes must be passed the nid of the node to be published. A number of module dependencies arise because of this.

Computed Field (CCK) is used to attach a Cart Links link to Ubercart.
Cart Links.
Node Reference (CCK) is used to link a specific content type (to be published) to the required product type.

This module breaks new ground with Attributes. It uses an attribute as part of the Order, not the Product. The new attribute, node_id, is used to pass the $node->nid of the node to be published into the order process. It should not be attached to a Product, as its value is undefined until the order is placed. I would suggest that a new field be added to the attribute table, attribute type (boolean OK) to keep Order attributes out of the drop down list for Products. When module designers realize that they can define attributes at the time of the Order without having to pre-declare them in the Product definition, we will probably see more module-specific attributes of this type.

I have also scrapped most of the cron code from uc_roles. The scheduler module handles node publication very well, and there is no sense in re-inventing the wheel. So I have extended the scheduler module, adding a $node->notified property, and a field, uc_nodes_notified, to the scheduler table. uc_nodes_cron() only handles the email notifications.

To use:

  1. Install and activate the module and its dependencies. This will create the tables, and will create the orphan attribute called node_id. (Do NOT attach this attribute to any product!) Cart Links will use it for the product order without confusing your users with an empty text box.
  2. Create a Product, and give it a Node Publication feature.
  3. Create a Content Type to be published. Activate scheduler, and add two fields to this Content Type:
    1. Name: product (field_product)
      Type: CCK nodereference
      Node type: Product
      Single value
      Display: radio or select list
    2. Name: cartlink (field_cartlink)
      Type: computed
      Single value
      Display raw
      Database yes varchar 125 not null

    Label, Teaser and Full display formats for both fields should all be <hidden>.

  4. Select the Product (created in step 2) that will be used for publication of this content type (field_product). Multiple products can be defined to publish multiple content types (eg. Classified Ads, Event Announcements, etc).
  5. Enter the following in the Computed Code box for field_cartlink, without the php tags:

// Create nid if this is a new node.
if (!$node->nid) node_save($node);

// Check if node is published
if (!$node->status) {
$node_field[0]['value'] = l(
// Link Title
'Publish ' . $node->type . ': ' . $node->title . ' now.' ,
// uri
'cart/add/e-p' . $node->field_product[0]['nid'] . '_q1_a' . uc_nodes_nid_attribute() . 'o' . $node->nid '-i' $node->type . '?destination=cart'
else {
// Already published. Show expiry date.
$node_field[0]['value'] = 'Expires on ' . date("Y:m:d",$node->unpublish_on);


  • Create a view, with Node Title, whatever other fields you wish, and field_cartlink.
  • Play to your hearts content, and let me know where it breaks. (Please, the usual THIS IS NOT PRODUCTION READY, but it appears to be working fine in the PayPal sandbox.)
  • AttachmentSize
    uc_nodes-5.x-1.0-alpha.tar.gz 19.96 KB
    glenn's picture
    Joined: 08/28/2008
    Juice: 10
    This is very interesting

    I wonder if it could be applied to a subscription site I am putting together:

    It will work something like an online training site: every new subscriber (no matter when they subscribe) will first receive lesson #1, then lesson #2 two weeks later, then lesson #3 two weeks after lesson #2, and so on. Then at the end of the course the subscription expires.

    I have a solution which I described here: http://www.ubercart.org/forum/ideas_and_suggestions/4815/online_training.... However, I'm hoping there's a much neater solution, which doesn't involve so many roles, and which would allow subscribers to gain access to an additional node at a configurable timed interval.

    Can your module do this? If not, could you adapt it to do this? I might be prepared to sponsor such a module (depending on the cost involved).