You are here

function commerce_bpc_create_bulk_form in Commerce Bulk Product Creation 7

Same name and namespace in other branches
  1. 7.2 commerce_bpc.forms.inc \commerce_bpc_create_bulk_form()

Form constructor for the bulk creation form.

Paths: admin/commerce/products/add-bulk/PRODUCT_TYPE

See also

commerce_bpc_menu()

commerce_bpc_create_bulk_form_validate()

commerce_bpc_create_bulk_form_submit()

1 string reference to 'commerce_bpc_create_bulk_form'
commerce_bpc_menu in ./commerce_bpc.module
Implements hook_menu().

File

./commerce_bpc.forms.inc, line 17
Form generation functions for the Commerce bulk product creation module

Code

function commerce_bpc_create_bulk_form($form, &$form_state, $product_type) {
  $form['#parents'] = array();

  // Create a temporary product object attach fields.
  $new_product = commerce_product_new($product_type);
  $language = !empty($new_product->language) ? $new_product->language : LANGUAGE_NONE;

  // Store the product type for later use.
  $form['product_type'] = array(
    '#type' => 'value',
    '#value' => $product_type,
  );
  $form['description'] = array(
    '#type' => 'item',
    '#title' => t('Bulk Product Creation Form'),
  );
  $form['product'] = array(
    '#type' => 'fieldset',
    '#title' => t('Product Info'),
    '#collapsible' => TRUE,
    '#collapsed' => FALSE,
  );
  $form['combinations'] = array(
    '#type' => 'fieldset',
    '#title' => t('Combinations'),
    '#description' => t('A product will be created for every possible combination of the values you select here.'),
    '#collapsible' => TRUE,
    '#collapsed' => FALSE,
    '#tree' => TRUE,
  );
  $form['static_values'] = array(
    '#type' => 'fieldset',
    '#title' => t('Static values'),
    '#description' => t('The values of these fields will be shared by all generated products.'),
    '#collapsible' => TRUE,
    '#collapsed' => FALSE,
    '#tree' => TRUE,
    '#parents' => array(
      'static_values',
    ),
  );
  $form['product']['sku_fragment'] = array(
    '#type' => 'textfield',
    '#title' => t('SKU'),
    '#required' => TRUE,
    '#description' => t("The part of the SKU that is common to all products to be generated. The SKU of each individual product will be composed of this value together with values of the selected options."),
    '#size' => 60,
    '#maxlength' => 255,
    '#weight' => 0,
    '#process' => array(
      'commerce_bpc_process_fragment_field',
    ),
  );
  $form['product']['title_fragment'] = array(
    '#type' => 'textfield',
    '#title' => t('Title'),
    '#required' => TRUE,
    '#description' => t("The part of the product title that is common to all products to be generated. The SKU of each individual product will be composed of this value together with values of the selected options."),
    '#size' => 60,
    '#maxlength' => 255,
    '#process' => array(
      'commerce_bpc_process_fragment_field',
    ),
  );

  // We simply attach all fields to the 'static_values' fieldset, and then
  // allow modules to act on each of the fields.
  field_attach_form('commerce_product', $new_product, $form['static_values'], $form_state, $language);
  commerce_bpc_process_field_form_elements($form, $form_state);
  $form['static_values']['status'] = array(
    '#type' => 'radios',
    '#title' => t('Status'),
    '#description' => t('Disabled products cannot be added to shopping carts and may be hidden in administrative product lists.'),
    '#options' => array(
      '1' => t('Active'),
      '0' => t('Disabled'),
    ),
    '#default_value' => 1,
    '#required' => TRUE,
    '#weight' => 200,
  );
  $form['submit'] = array(
    '#type' => 'submit',
    '#value' => t('Create products'),
    '#submit' => array(
      'commerce_bpc_create_bulk_form_create_products_submit',
    ),
    '#validate' => array(
      'commerce_bpc_create_bulk_form_validate',
    ),
  );
  if (commerce_bpc_setting('display', 'creation_method', $product_type) == 'wizard') {

    // Show the Display Node option if applicable.
    $display_nodes = commerce_bpc_get_node_types($product_type);
    if (!empty($display_nodes)) {
      $form['next'] = array(
        '#type' => 'submit',
        '#value' => 'Create products and Create display',
        '#submit' => array(
          'commerce_bpc_create_bulk_form_create_products_submit',
        ),
      );
    }
  }
  return $form;
}