You are here

function commerce_product_ui_product_type_form_submit in Commerce Core 7

Form submit handler: save a product type.

1 string reference to 'commerce_product_ui_product_type_form_submit'
commerce_product_ui_product_type_form in modules/product/includes/commerce_product_ui.forms.inc
Form callback: create or edit a product type.

File

modules/product/includes/commerce_product_ui.forms.inc, line 146
Forms for creating / editing and deleting products.

Code

function commerce_product_ui_product_type_form_submit($form, &$form_state) {
  $product_type = $form_state['product_type'];
  $updated = !empty($product_type['type']);

  // If a type is set, we should still check to see if a row for the type exists
  // in the database; this is done to accomodate types defined by Features.
  if ($updated) {
    $updated = db_query('SELECT 1 FROM {commerce_product_type} WHERE type = :type', array(
      ':type' => $product_type['type'],
    ))
      ->fetchField();
  }
  foreach ($form_state['values']['product_type'] as $key => $value) {
    $product_type[$key] = $value;
  }

  // Write the product type to the database.
  $product_type['is_new'] = !$updated;
  commerce_product_ui_product_type_save($product_type);

  // Set the multingual value for the product type if entity translation is enabled.
  if (module_exists('entity_translation')) {
    variable_set('language_product_type_' . $product_type['type'], $product_type['multilingual']);
  }

  // Redirect based on the button clicked.
  drupal_set_message(t('Product type saved.'));
  if ($form_state['triggering_element']['#parents'][0] == 'save_continue') {
    $form_state['redirect'] = 'admin/commerce/products/types/' . strtr($product_type['type'], '_', '-') . '/fields';
  }
  else {
    $form_state['redirect'] = 'admin/commerce/products/types';
  }
}