Purchase Right to Publish a Node

Posts: 37
Joined: 11/28/2007

After a couple of days of trying to configure e-commerce, I am really impressed with Ubercart's great UI.

I am trying to figure out the best way to do the following using Ubercart.

1. A customer comes to the site and creates a node as a draft. (Example: a job posting)
2. The customer clicks a "purchase listing" button after saving their posting and goes to the Ubercart checkout screen. (I plan to use cart links to create a purchase listing button).
3. After paying, the node is upgraded to "published" status. After a certain period of days, the node will be downgraded to draft status again.

I installed workflow-ng but didn't see a way to change the published status of a node after a completed purchase.

Thanks in advance for any help you can offer.

Posts: 4256
Joined: 08/07/2007
AdministratorHead Code Monkey - I eat bugs.

Well, the main problem here is that the event that gets fired when someone completes checkout takes the order and the user as arguments. The action for publishing a node requires a node object to be passed to it, so it's not available for the completed checkout event. With a little bit of code mojo you can create your own action that will find the referenced node and publish it.

Posts: 203
Joined: 09/06/2007

Do it like this: You split the ordering from the node. I assume here that all nodes to buy have the same price, so you pay for the url so to speak Cool

It is like a giftcertificate in a way..

Ok, I buy a job posting product. All this needs to know which url to a certain jon posting you do mean during this shopping session. (Attributes!!)

Under your created job posting which is published only to be seen by author and role "view special job postingS".. unchecked yet: After the ordering procress all folks with this role, the shopper guest in genereal can then see it as well..

You change the flag after the order has gone thru!!!

So, all you need to do is to alter the uc_attributes function by adding an if statement so that only attributes are shown for porduct type job posting that are made by the current viewer.. Goal: Only one current attribute offered..

Ok, all we need is a module offering a link under your job posting nodes created and only seen by you the author prior to order complete status. this then writes a new attribute into the attributes table (I think what we could even do is to use attribute option adjustments and do it like author id + job posting url = sku)

Done.

Posts: 4256
Joined: 08/07/2007
AdministratorHead Code Monkey - I eat bugs.

@oslinux - I don't see how that is a simpler solution than I posted, and I really don't see how that would work. The task will take some custom code, but the simplest thing will probably be a custom workflow action.

Posts: 37
Joined: 11/28/2007

Thanks for the suggestion. I am going to start working on creating a custom action that gets fired when someone checks out. I really appreciate your help.

Posts: 37
Joined: 11/28/2007

I'm running into some problems trying to get Cart Links to work as a redirect. I've set up my site that when a new 'job" node is created, workflow-ng redirects the user to cart/add/e-p4_q1-new_node?destination=cart/checkout

However, when the user clicks on "Submit", they are redirected to the homepage and not the checkout page. In the process, the item is added to their cart.

What do I need to do to get the item added to the cart and also have the user directed to the checkout page?

Thanks in advance,
Julia

Posts: 37
Joined: 11/28/2007

I was entering the URL for redirect to before the ? instead of after it. D'oh! The redirect is working perfectly now. Next stop, figuring out how to carry the nid of the new node throughout the checkout process.

Posts: 46
Joined: 11/22/2007

Did you have a look at http://drupal.org/project/paypernode ? Maybe there's some logic in there which can be ported to ubercart's handling... It would be a nice addition if you ask me Eye-wink

Posts: 12
Joined: 11/30/2007
Bug Finder

Earlier today I finished creating a module which sounds exactly like what your looking for.

What it does is allow you to add a feature to a product which allows you to select the node type and number you would like to create during checkout.

The checkout pane then loads all the node add forms for each content type and stores them into a a serialized array waiting for the order to be completed.. once completed it pulls that information and saves them as nodes created by the user who placed the order.

This works nicely for anonymous customers as well because once ubercart assigns them a userid it updates the temporary node arrays with the new user id.

It does need some finishing touches but I'd be more than happy to post it as a contrib and if anyone else wants to take it over and improve it that would be great.

Let me know...

Posts: 12
Joined: 11/30/2007
Bug Finder

Well it actually serves 2 purposes.
You can specify a feature which allows you to set the number of nodes of a certain type a user can create. This will prevent the user from submitting more nodes than allowed.

The second is the option to actually create these nodes in the checkout form. This is an option when adding the feature.

What I would like to do is when the feature is added to the product ask how the number of nodes the user has should be handled. If the user currently can create 10 story nodes.. and they product they purchase gives the 20 story nodes. Will they get 10 + 20 story nodes or just get the result of the new purchase. I would also like to allow the number of nodes to show in checkout and not just if they show in checkout or not.

Posts: 37
Joined: 11/28/2007

Thanks for the suggestion. I've looked at pay-per-node before and it seems like a nifty module.

One problem I see with pay-per-node is that the user first pays and then is able to create content. It seems like it would make more sense to first create content, then pay, then have the node published.

I'm trying to create a system for job listings, and after looking at other job sites, it seems like the model of creating content and then paying for it is somewhat standard.

Posts: 37
Joined: 11/28/2007

@GileS: I'm looking forward to checking it out.

Posts: 46
Joined: 11/22/2007

hmm, on a different, perhaps more simple approach...
You could sell roles ("advertiser") and use views to only show the nodes of which the author has the role "advertiser"...

Posts: 37
Joined: 11/28/2007

@kcoworks: The roles plan sounds like a good fallback.

After thinking about this quite a bit, I have decided that what I really need is some way to make a database association between the nid of the newly created node and the order_id. It seems like I will need to write a module to do this. Then, I can also write a function that loads both the order and the associated node.

I'm a little confused about how to get started on this. I'm thinking that the database record should be created when a user clicks "Submit Order" at cart/checkout/review. But, I'm not sure of the best way to save my nid through the entire checkout process.

Any suggestions?

Posts: 1129
Joined: 08/14/2007
Bug FinderEarly adopter... addicted to alphas.Getting busy with the Ubercode.

I'd say only create the nid at the END of the process - after checkout and post-payment. I would consider using the sequences table and the node_nid value found inside it. Then, upon order update, if balance is 0, yadda yadda, find the next node_nid in the sequence table and assign that value to the purchased node.

Maybe the creation of a uc_temp_purchased_nodes table to store these purchased nodes before the checkout completion process.

Just my thoughts. This sounds somewhat similar to the "user created content available for purchase" system I'll be working on for the next couple months. Let me know if you need anything!

--

"Pain don't hurt." - Dalton

Mike Nelson's RiffTrax! www.rifftrax.com

Posts: 12
Joined: 11/30/2007
Bug Finder

I am still waiting on the email validation to get fixed so I have the permissions to post the code in the contrib section here at ubercart. If anyone would like me to email them the module just send me a pm on here with your email.

Posts: 37
Joined: 11/28/2007

Thanks torgosPizza. I am going to go with GileS solution. But, I started working on your method before getting his code. I thought that it might be risky to use the sequences table and instead grabbed the last node created by the current user. I'm not sure how I would handle it if users were not logged in. Here's how I ended up grabbing the node info.

<?php
/*get last user-created node*/
function uc_nodes_get_contents() {
    global
$user;
    
$userid = $user->uid;
    
$nlimit = 1;
if (
is_numeric($userid)) {
   
$sql = "SELECT n.created, n.title, n.nid, n.changed, n.status, n.type  FROM node n WHERE n.uid = $userid AND n.status = 0 ORDER BY n.created DESC LIMIT $nlimit";
   
$result = db_query($sql);
    while (
$data = db_fetch_object($result)){
       
$_SESSION['purchased_node'] = $data->nid;
    }
       
$nid $_SESSION['purchased_node'];
       
$purchased_node = node_load($nid);
  }
  return
$purchased_node;
}
?>

I'm sure that there's a better way to do this.

Posts: 1129
Joined: 08/14/2007
Bug FinderEarly adopter... addicted to alphas.Getting busy with the Ubercode.

Right, I think your method would good as long as users aren't purchasing multiple nodes - since node numbers are incremental, what happens if the user's last nid is the same as another user's last nid?

I would also not allow an anonymous user to purchase a node. With our site you must be registered & logged in to complete a purchase ... something as risky as selling content to anonymous users is probably not something I'll be implementing Smiling Anyways this is all brainstorming and, I've been wrong in my thoughts before, so if you get a solution working let me know - would love to take a look at it!

Hey GileS, let us know when your Contrib is up - I'm eager to take a look at it too. My feeling is that your code will be able to help me get a jumpstart, but the way our business works I'll probably end up hacking it apart and beefing it up for our particular customized use. Looking forward to it!

--

"Pain don't hurt." - Dalton

Mike Nelson's RiffTrax! www.rifftrax.com

Posts: 37
Joined: 11/28/2007

GileS' code can be found at uc_nodetype: module to purchase right to publish node. Let's move the discussion there.

Posts: 15
Joined: 02/22/2008

JuliaKM wrote:
After a couple of days of trying to configure e-commerce, I am really impressed with Ubercart's great UI.

I am trying to figure out the best way to do the following using Ubercart.

1. A customer comes to the site and creates a node as a draft. (Example: a job posting)
2. The customer clicks a "purchase listing" button after saving their posting and goes to the Ubercart checkout screen. (I plan to use cart links to create a purchase listing button).
3. After paying, the node is upgraded to "published" status. After a certain period of days, the node will be downgraded to draft status again.

I installed workflow-ng but didn't see a way to change the published status of a node after a completed purchase.

Thanks in advance for any help you can offer.

Julia, I know that you are working on the uc_nodetype module but I though I would share an approach that seems to solve your orginal post above. This is how I used workflow_ng to implement "pay to publish" functionality.

Here is the link:
Pay to Publish using workflow_ng

Best,

Nathan

Posts: 3
Joined: 03/22/2008

My problem is...I'm trying to charge for a product post. So, what would I have to do differently?