You are here

function bpc_display_create_node in Commerce Bulk Product Creation 7.2

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 bpc_display_create_node()
bpc_display_commerce_bpc_post_create in modules/bpc_display/bpc_display.module
Implements hook_commerc_bpc_post_create().

File

modules/bpc_display/bpc_display.module, line 246
Allows automatic display node creation for Commerce bulk product creation.

Code

function bpc_display_create_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 = _bpc_display_get_reference_field($node_type);
  foreach ($product_ids as $id) {
    $node->{$ref_field_name}[LANGUAGE_NONE][] = array(
      'product_id' => $id,
    );
  }
  drupal_alter('bpc_display_node', $node);
  node_save($node);
  return $node;
}