How to publish a node after purchase

mrthumpz - February 18, 2009 - 17:42
Project:UC Node Checkout
Version:6.x-2.0-beta3
Component:Documentation
Category:support request
Priority:normal
Assigned:Unassigned
Status:active
Description

In 5.x, I could use workflow-ng to publish a node after a person checks out.

I started looking at this in 6.x, and am having difficulty finding the best way to do this, and was not able to find any documentation on it.

workflow-ng is replaced by Rules http://drupal.org/project/rules
Is the UC integrated with the Rules module? I noticed there is Conditional Actions in UC, but there is no way to publish a node, or to execute custom PHP code.

Is this possible yet, and if so, how do I do about configuring this?

#1

carlosdavis - February 23, 2009 - 06:38

I would suggest something like the following, as I have this working fine right now:

<?php
function my_module_order($op, $arg1, $arg2) {
    if (
$op == 'update' && $arg2 == "payment_received") {   
        foreach (
$arg1->products as $product) {
           
$node_id = $product->data['node_checkout_nid'];
           
           
$node = node_load($node_id);
           
$node->status = 1; // publish the node       
           
node_save($node);
        }
    }
}
?>

Anyone see any problems with this?

#2

mrthumpz - February 23, 2009 - 17:43

It worked for me without Revision Moderation enabled, but I also need this module, so I had to go around node_save.

<?php
/**
* Implementation of hook_order()
*/
function mymodule_order($op, $arg1, $arg2) {
   
//Because we also use Revision Moderation we have to do directly to the DB and not use node_save().
   
if ($op == 'update' && $arg2 == "payment_received") {    
        foreach (
$arg1->products as $product) {
           
$node_id = $product->data['node_checkout_nid'];
           
//Publish the node
           
db_query("UPDATE {node} SET status = %d WHERE nid = %d", 1, $node_id);
        }
    }
}
?>

#3

hamaldus - March 16, 2009 - 17:19
Status:active» fixed

There seems to be a module in the works that takes care of this issue:

http://drupal.org/project/uc_node_published

#4

System Message - March 30, 2009 - 17:20
Status:fixed» closed

Automatically closed -- issue fixed for 2 weeks with no activity.

#5

fletch11 - August 31, 2009 - 07:52

UC Node Published doesn't seem to be working and appears abandoned. Does a anyone else have ideas for this?

#6

stevebab - September 11, 2009 - 18:41

Using Ubercart's Conditional Actions at /admin/store/ca , I was able to get the node to publish after sucessful checkout. Here's how:

1. Add a new predicate and give it a descriptive name
2. Make sure Trigger is set to "Customer completes checkout"
3. Add an action to "Execute custom PHP code"

Here's the code:

foreach ($order->products as $product) {
            $node_id = $product->data['node_checkout_nid'];
            $node = node_load($node_id);
            $node->status = 1; // publish the node       
            node_save($node);
        }

Save it and it should work like a champ.

#7

fletch11 - September 28, 2009 - 20:22

This doesn't work for me. Anyone else have any luck with this?

#8

fletch11 - October 8, 2009 - 09:46
Status:closed» active

Sorry to open again, but anyone get this?

#9

neillodwyer - October 12, 2009 - 15:30

I'm currently working on a classified ads site and I got it to work by using a combination of the code supplied in this wonderful tutorial:
http://drupaleasy.com/blogs/ultimike/2009/03/event-registration-ubercart

and the line: $node->status = 1; // publish the node
from stevebab's code above.

Hope this helps.

#10

fletch11 - October 18, 2009 - 13:34

I'm still having trouble with this. For background, I'm setting the default workflow for my classified content type as unpublished, since otherwise it will be published at creation and not payment (but maybe this is the problem). I'm following the Drupal Easy instructions and the conditional action, per stevebab's advice. I'm still not getting it published at checkout though. Are you suggesting to put the line ($node->status = 1; // publish the node) elsewhere or are you following stevebab's instructions and got it to work as well? Could someone let me know which conditional actions are set up to get this working also?

Thanks a lot for the help.

#11

fletch11 - October 29, 2009 - 15:04

Nevermind - one of my other conditional actions was faulty.

The tip above works - and the line: $node->status = 1; // publish the node

to the code in the conditional action, as referenced in the drupaleasy.com tutorial

#12

samkat12 - October 31, 2009 - 03:39

can you please prvide a brief work through how you got your nodes to publish?

#13

fletch11 - November 1, 2009 - 10:01

all I did was follow the drupal easy tutorial and include the line of php referenced above to the conditional actions snippet of php cited in the tutorial

 
 

Drupal is a registered trademark of Dries Buytaert.