You are here

function commerce_userpoints_currencies_form_submit in Commerce userpoints 7

Form submit callback, saves a new currency.

File

./commerce_userpoints.admin.inc, line 160
Administration page callbacks for the commerce_userpoints module.

Code

function commerce_userpoints_currencies_form_submit($form, &$form_state) {
  $userpoints_currencies = commerce_userpoints_currencies();
  form_state_values_clean($form_state);

  // Save the new or updated currency.
  $userpoints_currencies[$form_state['values']['code']] = $form_state['values'];
  variable_set('commerce_userpoints_currencies', $userpoints_currencies);

  // Automatically enable this currency.
  $enabled_currencies = variable_get('commerce_enabled_currencies', array(
    'USD' => 'USD',
  ));
  $enabled_currencies[$form_state['values']['code']] = $form_state['values']['code'];
  variable_set('commerce_enabled_currencies', $enabled_currencies);
  $form_state['redirect'] = 'admin/commerce/config/currency/userpoints';
  drupal_set_message(t('!Points currency saved and enabled.', userpoints_translation()));

  // Flush out commerce's currency cache.
  cache_clear_all('commerce_currencies:', 'cache', TRUE);
}