function commerce_node_checkout_add_node in Commerce Node Checkout 7
Adds a node to a line item in the user's cart
Parameters
$node: The node object to be associated with the line item.
$product: The product chosen by the user.
Return value
The line item object that was created when the node was added to the cart, or FALSE, if an error occurred.
2 calls to commerce_node_checkout_add_node()
- commerce_node_checkout_expire_relist_form_submit in commerce_node_checkout_expire/
commerce_node_checkout_expire.module - Submit handler for the node relist form.
- commerce_node_checkout_node_form_submit in ./
commerce_node_checkout.module - Form submission handler that executes only when a new node that contains the product selection widget is saved.
File
- ./
commerce_node_checkout.module, line 255 - Provides core hooks and the like for the module
Code
function commerce_node_checkout_add_node($node, $product) {
global $user;
// Create our new line item.
if ($line_item = commerce_product_line_item_new($product, 1, 0, array(), 'commerce_node_checkout')) {
// Set the reference field value.
$line_item->commerce_node_checkout_node[LANGUAGE_NONE][0]['target_id'] = $node->nid;
// Let other modules alter the line item before it's added to the cart.
drupal_alter('commerce_node_checkout_line_item', $line_item, $product, $node);
// Add to cart.
if ($line_item = commerce_cart_product_add($user->uid, $line_item, FALSE)) {
return $line_item;
}
}
return FALSE;
}