You are here

function commerce_addressbook_customer_profile_form_submit in Commerce Addressbook 7.3

Same name and namespace in other branches
  1. 7.2 includes/commerce_addressbook.user.inc \commerce_addressbook_customer_profile_form_submit()

Submit handler for commerce_addressbook_customer_profile_form().

File

includes/commerce_addressbook.user.inc, line 45
Page callbacks and form callbacks for user addressbook pages.

Code

function commerce_addressbook_customer_profile_form_submit($form, &$form_state) {
  $profile = $form_state['customer_profile'];

  // The profile has been edited and duplicated.
  // Disable the previous one to prevent it from showing up in listings.
  if (!empty($profile->previous_id)) {
    $old_profile = commerce_customer_profile_load($profile->previous_id);
    $old_profile->status = 0;
    commerce_customer_profile_save($old_profile);

    // If the old profile was the default, then we need to set the new one
    // as the default.
    $default_profile_id = commerce_addressbook_get_default_profile_id($profile->uid, $profile->type);
    if ($old_profile->profile_id == $default_profile_id) {
      commerce_addressbook_set_default_profile($profile);
    }
  }
  $form_state['redirect'] = 'user/' . $profile->uid . '/addressbook/' . $profile->type;
}