You are here

function commerce_addressbook_set_default_profile in Commerce Addressbook 7.3

Same name and namespace in other branches
  1. 7.2 commerce_addressbook.module \commerce_addressbook_set_default_profile()

Sets the given customer profile as the default one.

Parameters

$profile: The customer profile object.

4 calls to commerce_addressbook_set_default_profile()
commerce_addressbook_commerce_customer_profile_insert in ./commerce_addressbook.module
Implements hook_commerce_customer_profile_insert().
commerce_addressbook_commerce_customer_profile_update in ./commerce_addressbook.module
Implements hook_commerce_customer_profile_update().
commerce_addressbook_customer_profile_form_submit in includes/commerce_addressbook.user.inc
Submit handler for commerce_addressbook_customer_profile_form().
commerce_addressbook_profile_options_default in includes/commerce_addressbook.user.inc
Page callback for setting a customer profile as default. Used for both ajax and non-ajax delivery of the customer profile updates.

File

./commerce_addressbook.module, line 267
Defines addressbook functionality for customer profiles, allowing them to be reused and managed on a per-user basis.

Code

function commerce_addressbook_set_default_profile($profile) {
  if (empty($profile->profile_id) || !$profile->uid) {
    return;
  }
  db_merge('commerce_addressbook_defaults')
    ->key(array(
    'uid' => $profile->uid,
    'type' => $profile->type,
  ))
    ->fields(array(
    'profile_id' => $profile->profile_id,
  ))
    ->execute();

  // Allow modules to react to change in customer profile default change.
  rules_invoke_all('commerce_addressbook_set_default', $profile);
}