You are here

function uc_taxes_form_submit in Ubercart 7.3

Same name and namespace in other branches
  1. 5 uc_taxes/uc_taxes.module \uc_taxes_form_submit()
  2. 6.2 uc_taxes/uc_taxes.admin.inc \uc_taxes_form_submit()

Form submission handler for uc_taxes_form().

See also

uc_taxes_form()

uc_taxes_form_validate()

File

uc_taxes/uc_taxes.admin.inc, line 169
Taxes administration menu items.

Code

function uc_taxes_form_submit($form, &$form_state) {

  // Determine the decimal rate value.
  if (strpos($form_state['values']['rate'], '%')) {
    $form_state['values']['rate'] = floatval($form_state['values']['rate']) / 100;
  }
  else {
    $form_state['values']['rate'] = floatval($form_state['values']['rate']);
  }

  // Build the rate object based on the form values and save it.
  $rate = (object) array(
    'id' => $form_state['values']['id'],
    'name' => $form_state['values']['name'],
    'rate' => $form_state['values']['rate'],
    'taxed_product_types' => array_filter($form_state['values']['taxed_product_types']),
    'taxed_line_items' => array_filter($form_state['values']['taxed_line_items']),
    'weight' => $form_state['values']['weight'],
    'shippable' => $form_state['values']['shippable'],
    'display_include' => $form_state['values']['display_include'],
    'inclusion_text' => $form_state['values']['inclusion_text'],
  );
  $rate = uc_taxes_rate_save($rate);

  // Update the name of the associated conditions.
  $conditions = rules_config_load('uc_taxes_' . $form_state['values']['id']);
  if ($conditions) {
    $conditions->label = $form_state['values']['name'];
    $conditions
      ->save();
  }

  // Display a message and redirect back to the overview,
  // or the conditions page for new taxes.
  if ($form_state['values']['id']) {
    drupal_set_message(t('Tax rate %name saved.', array(
      '%name' => $form_state['values']['name'],
    )));
    $form_state['redirect'] = 'admin/store/settings/taxes';
  }
  else {
    drupal_set_message(t('Tax rate %name created.', array(
      '%name' => $form_state['values']['name'],
    )));
    $form_state['redirect'] = 'admin/store/settings/taxes/manage/uc_taxes_' . $rate->id;
  }
}