Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
The documented hook to validate if a address should be deleted while modifying a user's address book doesn't validate correctly.
function hook_commerce_customer_profile_can_delete($profile) {
// The default customer profile can not be deleted
if (example_profile_isdefault($profile) == TRUE) {
return FALSE;
}
}
function example_profile_isdefault($profileObj) {
$result = db_select('commerce_addressbook_defaults', 'cad')
->fields('cad')
->condition('uid', $profileObj->uid, '=')
->condition('type', $profileObj->type, '=')
->condition('profile_id', $profileObj->profile_id, '=')
->execute();
if ($result->rowCount() > 0) {
return TRUE;
} else {
return FALSE;
}
}
I return false but the address is deleting anyway.
What am I doing wrong?
Call stack:
- commerce_addressbook
- commerce_customer
- mymodule
Also why is commerce_customer_profile_save() being called even though I'm deleting the profile/address?
I assume this is to make sure past orders don't get orphaned?
Comments
Comment #1
vasikei tried your code and you're doing right.
the Commerce Addressbook disables your default profiles, that's why it's calling the commerce_customer_profile_save() function.
check the comments for the submit handler for addresses deletion
You could see the disabled profiles at Customer profiles page (admin/commerce/customer-profiles).
Comment #2
bojanz CreditAttribution: bojanz commentedConfirming #1.