You are here

function commerce_addressbook_set_default_profile in Commerce Addressbook 7.2

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

Find an existing default for a given user, for a given profile type and update it to a new profile, or set it if a default is not already set.

5 calls to commerce_addressbook_set_default_profile()
commerce_addressbook_commerce_customer_profile_delete in ./commerce_addressbook.module
Implements hook_commerce_customer_profile_delete().
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 490
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($customer_profile) {
  db_merge('commerce_addressbook_defaults')
    ->key(array(
    'uid' => $customer_profile->uid,
    'type' => $customer_profile->type,
  ))
    ->fields(array(
    'profile_id' => $customer_profile->profile_id,
  ))
    ->execute();

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