You are here

function commerce_ups_settings_form in Commerce UPS 7.2

Same name and namespace in other branches
  1. 7 commerce_ups.admin.inc \commerce_ups_settings_form()

Implements hook_settings_form().

1 string reference to 'commerce_ups_settings_form'
commerce_ups_menu in ./commerce_ups.module
Implements hook_menu().

File

includes/commerce_ups.admin.inc, line 11
Handles admin settings page for Commerce UPS module.

Code

function commerce_ups_settings_form($form, &$form_state) {
  $ups_link = l(t('UPS.com'), 'https://www.ups.com/upsdeveloperkit', array(
    'attributes' => array(
      'target' => '_blank',
    ),
  ));
  $form['api'] = array(
    '#type' => 'fieldset',
    '#title' => t('UPS API credentials'),
    '#collapsible' => TRUE,
    '#description' => t('In order to obtain shipping rate estimates, you must have an account with UPS. You can apply for UPS API credentials at !ups', array(
      '!ups' => $ups_link,
    )),
  );
  $encrypted = variable_get('commerce_ups_encrypt', FALSE);
  $api_vars = commerce_ups_decrypt_vars(FALSE);
  $form['api']['commerce_ups_account_id'] = array(
    '#type' => 'textfield',
    '#title' => t('Account ID'),
    '#default_value' => $api_vars['ups_accountid'],
    '#required' => TRUE,
  );
  $form['api']['commerce_ups_user_id'] = array(
    '#type' => 'textfield',
    '#title' => t('User ID'),
    '#default_value' => $api_vars['ups_userid'],
    '#required' => TRUE,
  );
  $form['api']['commerce_ups_password'] = array(
    '#type' => 'password',
    '#title' => t('Password'),
    '#required' => !variable_get('commerce_ups_password', FALSE),
    '#description' => t('Please leave blank if you do not want to update your password at this time.'),
  );
  $form['api']['commerce_ups_access_key'] = array(
    '#type' => 'textfield',
    '#title' => t('Access Key'),
    '#default_value' => $api_vars['ups_accesskey'],
    '#required' => TRUE,
  );
  $form['api']['encryption'] = array(
    '#type' => 'item',
    '#title' => t('Encryption'),
    'status' => array(
      '#type' => 'item',
      '#title' => FALSE,
    ),
  );
  if (commerce_ups_encryption_available()) {
    $form['api']['encryption']['status']['#markup'] = 'Encryption is available and configured properly.';
    $form['api']['encryption']['commerce_ups_encrypt'] = array(
      '#type' => 'checkbox',
      '#title' => t('Encrypt UPS credentials (HIGHLY RECOMMENDED)'),
      '#description' => t('Note: Enabling this setting automatically will encrypt your password even though you cannot see it. Disabling this checkbox requires that you re-enter a password.'),
      '#default_value' => $encrypted,
    );
  }
  else {
    $aes_link = l(t('Real AES'), 'http://drupal.org/project/real_aes', array(
      'attributes' => array(
        'target' => '_blank',
      ),
    ));
    $form['api']['encryption']['status']['#markup'] = '<span class="error">' . t('!aes is not installed - your UPS login credentials will not be encrypted.', array(
      '!aes' => $aes_link,
    )) . '</span>';
  }
  $form['origin'] = array(
    '#type' => 'fieldset',
    '#title' => t('Ship From Address'),
    '#collapsible' => TRUE,
  );
  $form['origin']['commerce_ups_company_name'] = array(
    '#type' => 'textfield',
    '#title' => t('Company Name'),
    '#default_value' => variable_get('commerce_ups_company_name'),
  );
  $form['origin']['commerce_ups_address_line_1'] = array(
    '#type' => 'textfield',
    '#title' => t('Address'),
    '#default_value' => variable_get('commerce_ups_address_line_1'),
  );
  $form['origin']['commerce_ups_address_line_2'] = array(
    '#type' => 'textfield',
    '#title' => t('Address (Additional)'),
    '#default_value' => variable_get('commerce_ups_address_line_2'),
  );
  $form['origin']['commerce_ups_city'] = array(
    '#type' => 'textfield',
    '#title' => t('City'),
    '#default_value' => variable_get('commerce_ups_city'),
  );
  $form['origin']['commerce_ups_state'] = array(
    '#type' => 'textfield',
    '#title' => t('State or Province'),
    '#description' => t('If shipping from USA or Canada, enter the 2 character abbreviation for the shipping State or Province.'),
    '#default_value' => variable_get('commerce_ups_state'),
    '#size' => 2,
  );
  $form['origin']['commerce_ups_postal_code'] = array(
    '#type' => 'textfield',
    '#title' => t('Postal Code'),
    '#size' => 5,
    '#default_value' => variable_get('commerce_ups_postal_code'),
  );
  if (module_exists('countries')) {
    $countries = countries_get_countries('name', array(
      'enabled' => COUNTRIES_ENABLED,
    ));
  }
  else {
    require_once DRUPAL_ROOT . '/includes/locale.inc';
    $countries = country_get_list();
  }
  $form['origin']['commerce_ups_country_code'] = array(
    '#type' => 'select',
    '#title' => t('Country'),
    '#default_value' => variable_get('commerce_ups_country_code'),
    '#options' => $countries,
  );
  $form['services'] = array(
    '#type' => 'fieldset',
    '#title' => t('Enable UPS Shipping Services'),
    '#collapsible' => TRUE,
  );
  foreach (_commerce_ups_service_list() as $key => $service) {
    $array_options[$key] = $service['title'];
  }
  $form['services']['commerce_ups_services'] = array(
    '#type' => 'checkboxes',
    '#options' => $array_options,
    '#default_value' => variable_get('commerce_ups_services', array()),
  );
  $form['packaging'] = array(
    '#type' => 'fieldset',
    '#title' => t('Enable UPS Packaging Types'),
    '#collapsible' => FALSE,
  );
  $form['packaging']['commerce_ups_packaging_explanation'] = array(
    '#type' => 'markup',
    '#markup' => t('Only "Customer supplied packaging" is currently available. Please enter the package size below.'),
  );
  $form['packaging']['commerce_ups_packaging'] = array(
    '#type' => 'hidden',
    '#value' => '02',
  );

  // Fields for default package size (inches).
  $form['default_package_size'] = array(
    '#type' => 'fieldset',
    '#title' => t('Package size (inches)'),
    '#collapsible' => FALSE,
    '#description' => 'UPS requires a package size when determining estimates.',
  );
  $form['default_package_size']['commerce_ups_default_package_size_length'] = array(
    '#type' => 'textfield',
    '#title' => t('Length'),
    '#size' => 5,
    '#required' => TRUE,
    '#default_value' => variable_get('commerce_ups_default_package_size_length'),
  );
  $form['default_package_size']['commerce_ups_default_package_size_width'] = array(
    '#type' => 'textfield',
    '#title' => t('Width'),
    '#size' => 5,
    '#required' => TRUE,
    '#default_value' => variable_get('commerce_ups_default_package_size_width'),
  );
  $form['default_package_size']['commerce_ups_default_package_size_height'] = array(
    '#type' => 'textfield',
    '#title' => t('Height'),
    '#size' => 5,
    '#required' => TRUE,
    '#default_value' => variable_get('commerce_ups_default_package_size_height'),
  );
  $form['default_package_size']['details'] = array(
    '#markup' => 'The package size is used to determine the number of packages necessary to
      create a UPS shipping cost estimate. <strong>If products do not have physical dimensions and
      weights associated with them, the estimates will not be accurate.</strong> The logic implemented works as:
      <ul>
      <li>Assume each order requires at least one package.</li>
      <li>Use the combined volume of all products in an order to determine the number of packages.</li>
      </ul>
      This is a simple calculation that can get close to actual shipping costs. More
      complex logic involving multiple package sizes, weights, and void space can be implemented via
      custom modules.
      <br/><br/>
      UPS has a ' . l('maximum package size', 'http://www.ups.com/content/us/en/resources/prepare/oversize.html', array(
      'attributes' => array(
        'target' => '_blank',
      ),
    )) . '.',
  );
  $form['advanced_options'] = array(
    '#type' => 'fieldset',
    '#title' => t('Advanced settings'),
    '#collapsible' => TRUE,
    '#collapsed' => TRUE,
  );
  $form['advanced_options']['commerce_ups_pick_up_schedule'] = array(
    '#type' => 'select',
    '#title' => t('Pick-up Schedule'),
    '#options' => _commerce_ups_pickup_types(),
    '#default_value' => variable_get('commerce_ups_pick_up_schedule'),
  );
  $form['advanced_options']['commerce_ups_shipto_residential'] = array(
    '#type' => 'checkbox',
    '#title' => t('Calculate ALL ship to addresses as residential.'),
    '#default_value' => variable_get('commerce_ups_shipto_residential', 0),
  );
  $form['advanced_options']['commerce_ups_show_logo'] = array(
    '#type' => 'checkbox',
    '#title' => t('Show UPS Logo on Shipping Page'),
    '#default_value' => variable_get('commerce_ups_show_logo', 0),
  );
  $form['advanced_options']['commerce_ups_log'] = array(
    '#type' => 'checkboxes',
    '#title' => t('Log the following messages for debugging'),
    '#options' => array(
      'request' => t('API request messages'),
      'response' => t('API response messages'),
    ),
    '#default_value' => variable_get('commerce_ups_log', array()),
  );
  $form['advanced_options']['commerce_ups_negotiated_rates'] = array(
    '#type' => 'checkbox',
    '#title' => t('Use negotiated rates'),
    '#description' => t('(only use if your account is setup for negotiated rates)'),
    '#default_value' => variable_get('commerce_ups_negotiated_rates', 0),
  );
  $form['actions']['submit'] = array(
    '#type' => 'submit',
    '#value' => t('Save configuration'),
  );
  return $form;
}