You are here

function bpc_display_commerce_bpc_destinations_alter in Commerce Bulk Product Creation 7.2

Implements hook_commerce_bpc_destinations_alter().

We use the _alter hook because we terminate redirecting after this hook.

File

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

Code

function bpc_display_commerce_bpc_destinations_alter(&$destinations, &$form_state, $product_ids) {
  $product_type = $form_state['values']['product_type'];
  $data['bulk_data'] = array(
    'product_type' => $product_type,
    'sku_fragment' => $form_state['values']['sku_fragment'],
    'title_fragment' => $form_state['values']['title_fragment'],
  );
  $method = commerce_bpc_setting('display', 'creation_method', $product_type);
  if ($method == 'onetoone' || $method == 'auto') {
    switch (commerce_bpc_setting('display', 'auto_redirect', $product_type)) {
      case 'display node':
        $destinations[] = 'node/' . $form_state['commerce_bpc']['bpc_display']['nid'];
        break;
      case 'custom':
        $destinations[] = commerce_bpc_setting('display', 'auto_redirect_custom', $product_type);
        break;
    }
  }
  else {
    if ($form_state['input']['op'] == 'Create products and Create display') {

      // Save the product IDs in the SESSION
      // Generate a id to make sure different bulk creations do not interfere
      // with each other.
      $id = uniqid();
      $_SESSION['bulk_product_ids'][$id] = $product_ids;
      $title_pattern = commerce_bpc_setting('display', 'auto_node_title_pattern', $product_type);
      $_SESSION['bulk_title'][$id] = token_replace($title_pattern, $data, array(
        'sanitize' => FALSE,
      ));
      $destinations[] = 'admin/commerce/products/add-bulk/' . $product_type . '/display/' . $id;
    }
  }
}