Not sure if this is is the right forum as it is not really a question but an answer / possible solution of sorts. This is in response to the following topics:
Purchase Right to Publish a Node
uc_nodetype:module to purchase right to publish node
Quote for finishing up pay node module
Although slightly different then these posts as they are describing creating a node when you purchase a product.... i.e. purchase and node creation in the same step this method is different in that the users can create all they want but they wont be published until after the purchase that is completely separate.
Question: How can I set up Ubercart to "Pay to publish"? I have a job board with the ability for employers to post jobs for a price. I need them to have a list displaying their jobs in their account page and have them pay to publish a job on the site.
Answer: This can be accomplished using the following modules: Ubercart , workflow_ng, Scheduler along with Cart Links API and some custom php code.
The BASIC Idea:
1. Activate Scheduler for your Node Type that you want published/unpublished
2. Create a Product named "Job Post" and give it an attribute for "Job ID"
3. Using views and some php code in your template.php file create a view that displays all the jobs for that user and add a cart link to "Buy" the product "Job Post" with the attribute "Job ID" set to the node id of the current node.
4. Create a new workflow_ng rule configuration for the event "Order status gets updated" and create a condition for "Check the order status" for order status "Payment received" and add an action for "Execute custom PHP code".
Here is the PHP code that I used.. (note I am not the best PHP coder and this is probably not 100% correct but seems to be working)
DO NOT INCLUDE PHP TAGS
<?php
//-----------------------------------------------------------------------------
// This will get an array of JOB ID's and Quantities from an order
//-----------------------------------------------------------------------------
$result = db_query("SELECT qty, model, data FROM {uc_order_products} WHERE order_id = %d", $order->order_id);
$i = 0;
$orders = array();
while ($row = db_fetch_object($result)) {
$data[] = unserialize($row->data);
if ($row->model == 'job-30'){
$orders[$i]['node'] = $data[$i]["attributes"]["JOB ID"];//CHANGE JOB ID to attribute name i.e. ["AD ID"]
}
else if ($row->model == 'ad-30'){
$orders[$i]['node'] = $data[$i]["attributes"]["AD ID"];//CHANGE JOB ID to attribute name i.e. ["AD ID"]
}
$orders[$i]['qty'] = $row->qty;
$i++;
}
//----------------------------------------------------------------------------
// get the schedule information and adjust based on quantity (30days)
//----------------------------------------------------------------------------
foreach ($orders as $order)
{
// get the schedule info
$result = db_query("SELECT * FROM {scheduler} WHERE nid = %d", $order['node']);
//already scheduled -> update unpublish_on date
if ($row = db_fetch_object($result))
{
//get current unpublish_on date
$unpub = $row->unpublish_on;
//calculate new date
$ndays = $order['qty']*30; //calculate the number of days to unpublish using quantity in order
//timestamp for new unpublish_on date
$unpub = mktime(date("H", $unpub), date("i",$unpub), date("s",$unpub), date("m",$unpub), date("d",$unpub)+$ndays,date("Y",$unpub));
//Update database
$result = db_query("UPDATE {scheduler} SET unpublish_on = %d WHERE nid = %d", $unpub, $order['node']);
//if result publish
if($result){
//publish
$nodes[] = $order['node'];
node_operations_publish($nodes);
// Log Watchdog
$message = "Node: ".$order['node']." has been rescheduled OK. publish_on: ".time()." unpublish_on: ".$unpub;
watchdog("Order", $message, $severity = WATCHDOG_NOTICE, $link = NULL);
}
//Unsuccessfull log into watchdog
else{
$message = "Node: ".$order['node']." has NOT been rescheduled. publish_on: ".date("F j, Y, g:i a",time())." unpublish_on: ".date("F j, Y, g:i a",$unpub);
watchdog("Order", $message, $severity = WATCHDOG_ERROR, $link = NULL);
}
}
//not scheduled -> schedule and publish
else{
//Insert publish data into scheduler table
$ndays = $order['qty']*30; //calculate the number of days to unpublish using quantity in order
//timestamp for unpublish date
$unpub = mktime(date("H", time()), date("i",time()), date("s",time()), date("m",time()), date("d",time())+$ndays,date("Y",time()));
$result = db_query("INSERT INTO {scheduler} (nid, publish_on, unpublish_on) VALUES (%d,%d,%d)",$order['node'], time(), $unpub);
// if successful mark as published
if ($result){
// publish
$nodes[] = $order['node'];
node_operations_publish($nodes);
// Log Watchdog
$message = "Node: ".$order['node']." has been scheduled OK. publish_on: ".time()." unpublish_on: ".$unpub;
watchdog("Order", $message, $severity = WATCHDOG_NOTICE, $link = NULL);
}
// unsuccessful enter in log
else{
$message = "Node: ".$order['node']." has NOT been scheduled. publish_on: ".date("F j, Y, g:i a",time())." unpublish_on: ".date("F j, Y, g:i a",$unpub);
watchdog("Order", $message, $severity = WATCHDOG_ERROR, $link = NULL);
}
}
}
?>Basically the idea is to look up the order, get the node id's from the product attributes and the quantity of each product-attribute then publish each node for the period of 30days*quantity. And log to watchdog.
5. So far that is it. There are bound to be some problems with this code / approach as in : if someone resets the status and then (accidentally) sets it back to payment received it will add another month of posting to the Job. But I am less concerned with that and can always change the scheduler manually for a job that needs the status changed.
6. Other possible extensions would be to use the discount contributed module to add discounts to multiple products. Add a cron to notify users of soon to "unpublish/expire" jobs. Use the same method to pay for advertisements using the Advertisement module.
I hope this helps anyone out there and feel free to let me know if you see any problems with the above code or approach.
Best,
Nathan.





Joined: 02/22/2008