I'm a recent convert from the Money Scripts Pay to Publish module, so after ripping that out of my site, i'm trying to re-create some of the functionality that was present in that module. Notably the ability to skip the checkout process if the user chooses a 'free' option. Currently there is a free listing and a premium listing that a user can choose on the site. Ideally I would like the user to skip the 'add to cart' precess if the node is 'free'.

Any pointers greatly appreciated.

Comments

comradebeck’s picture

Hi,

You can do this with rules. Select after adding a product to the cart event and select {Nodes from an order} and {Publish a node} actions. You can also add {remove all products from cart} action.

Cheers

gateway69’s picture

Hmm, thanks for the reply, im trying to decipher how to do this.

I have a pay per node, and a price of 0.0 for a basic package aka free. Im not sure what rules section I need to adjust, ideally though when the node is submitted it doesnt pull up the cart anymore and goes to something like thank you for submitting your free listing..

any help would be greatly appreciated.

bsherwood’s picture

I am also trying to do this as well. But I am having difficulty in creating the proper rule.

Event:
Before adding a product to the cart

Conditions:
Entity is of bundle (Since we only want Node Checkout nodes, not other products)
Parameter: Entity: [commerce-product], Entity type: Commerce Product, Entity bundle: Pay to publish

Price comparison
Parameter: First Price: [commerce-product:commerce..., Second Price: $0.00

Actions:
Nodes from an order
Parameter: The completed order: [commerce-order]
Provides variables: Associated Line items (line_items), Associated Nodes (nodes)

Remove all products from an order
Parameter: Order to empty: [commerce_order]

Publish content
Parameter: Content: [nodes:0]

It appears that this rule should work, but no matter what I do, I am still greeted with a shopping cart page after I click "save" on the node creation page.

Would it be possible to ship Commerce Node Checkout with a rule that takes care of these issues? Even if it was disabled by default.

Thanks

jackdaniel9’s picture

RULES

After adding a product to the cart

Order contains a particular product (SKU FREE PRODUCT PAY TO PUBLISH)

Nodes from an order
Loop
--Publish content
Remove all products from an order
Page redirect

See image

jackdaniel9’s picture

pinkonomy’s picture

@jackdaniel9
Thank you for the rule.It works,however is too slow :(

I have tried to do this with code but it didn't work for me

function custom_node_submit(&$form, &$form_state) {
global $user;
if (in_array('administrator', $user->roles)) {
$form_state['values']['commerce_node_checkout_skip'] = True;
}

$form_state['values']['status'] = 1;

Could you please help me?
http://cgit.drupalcode.org/commerce_node_checkout/tree/commerce_node_checkout.module?h=7.x-1.x#n57

pinkonomy’s picture

Never mind,this is fine,however I am interested in redirecting to "node/nid" instead of the front page.
What path shall I give to the redirect action?
Because if redirects by default to /cart where it shows the message " Your product has been added to the cart" ,which I don't want to appear.
Any help would be greafull,thanks

EDIT:The redirect rule makes adding node very slow so it would be better to do this with code,see previous comment

pinkonomy’s picture

I finally solved this,here is the code :

function custom_node_submit($node, $form, &$form_state) {
 global $user;

 if (in_array('administrator', $user->roles)) {
  $form_state['values']['commerce_node_checkout_skip'] = True;
  $node->status = 1;
    }

return $form;

 }
hottaco’s picture

#4 worked perfectly. Thank you @jackdaniel9. It saved me hours of headache.

I've got a bit of a corner case in my situation.
After the free item is removed from the cart, I have no way of expiring a node after 30 days using the included module.

Is there a way I can still use "Commerce Node Checkout Expire" for the nodes of the same content type that are free?

I tried Node Expire, but it broke Commerce Node Checkout Expire functionality or I was doing something wrong.

Any guidance is appreciated.

Bijanzn’s picture

i'm trying add my module with codes and i want skip the checkout process and node has bin publish for free produt but my module is not work!!!

Any pointers greatly appreciated

function MYMODULE_node_submit($node, $form, &$form_state) {
 global $user;

 if (in_array('administrator', $user->roles)) {
	 
	 if ($node['field_noeagahi']['und']['0']['value'] = 1) { 
		 
		$form_state['values']['commerce_node_checkout_skip'] = True;
		$node->status = 1;
		}
}
return $form;

 }
freelylw’s picture

after many years of this discussion, I am still looking for the solution which I can publish the node immediately but keep the commece_node_checkout expire date function. any suggestion ? Thanks

spacemuon’s picture

Here is one way to solve this issue.

Create a custom module.

In the form_alter
$form['actions']['submit']['#submit'][] = 'my_module_form_submit';
//Set #default_value, so all products are not added to the cart.
$form['commerce_node_checkout']['commerce_node_checkout_skip']['#default_value'] = 1;

In the form_submit
// Add condition for the products with value numbers you want to add to the cart.
if ($form_state['values']['commerce_node_checkout_product']['value'] == 'PRODUCT VALUE/s') {
//see commerce_node_checkout.module
$form_state['redirect'] = 'cart';
}