function commerce_bpc_create_display_node in Commerce Bulk Product Creation 7
Create a display node that links to a set of products.
Parameters
string $node_type: The machine name of the node type of the node to be created.
string $title: The title of the node to be created.
int|array $product_ids: Either a single product ID or an array of product IDs that will be linked from the newly-created node.
1 call to commerce_bpc_create_display_node()
- commerce_bpc_create_bulk_form_create_products_submit in ./
commerce_bpc.forms.inc - Form submission handler for commerce_bpc_create_bulk_form().
File
- ./
commerce_bpc.forms.inc, line 457 - Form generation functions for the Commerce bulk product creation module
Code
function commerce_bpc_create_display_node($node_type, $title, $product_ids) {
if (!is_array($product_ids)) {
$product_ids = array(
$product_ids,
);
}
$node = new stdClass();
$node->type = $node_type;
node_object_prepare($node);
$node->language = LANGUAGE_NONE;
$node->title = $title;
$ref_field_name = _commerce_bpc_get_reference_field_name($node_type);
foreach ($product_ids as $id) {
$node->{$ref_field_name}[LANGUAGE_NONE][] = array(
'product_id' => $id,
);
}
drupal_alter('commerce_bpc_display_node', $node);
node_save($node);
return $node;
}