function commerce_addressbook_commerce_customer_profile_delete in Commerce Addressbook 7.2
Same name and namespace in other branches
- 7.3 commerce_addressbook.module \commerce_addressbook_commerce_customer_profile_delete()
Implements hook_commerce_customer_profile_delete().
Delete the customer profile entry from commerce_addressbook_defaults table, set a new default customer profile for this type.
File
- ./
commerce_addressbook.module, line 265 - Defines addressbook functionality for customer profiles, allowing them to be reused and managed on a per-user basis.
Code
function commerce_addressbook_commerce_customer_profile_delete($profile) {
$default_profile = commerce_addressbook_get_default_profile_id($profile->uid, $profile->type);
if ($default_profile == $profile->profile_id) {
db_delete('commerce_addressbook_defaults')
->condition('profile_id', $profile->profile_id)
->execute();
$query = new EntityFieldQuery();
$query
->entityCondition('entity_type', 'commerce_customer_profile')
->propertyCondition('status', 1)
->propertyCondition('type', $profile->type)
->propertyOrderBy('profile_id', 'DESC')
->range(0, 1);
$results = $query
->execute();
if (!empty($results['commerce_customer_profile'])) {
commerce_addressbook_set_default_profile(commerce_customer_profile_load(key($results['commerce_customer_profile'])));
}
}
}