You are here

public function CommerceCustomerProfileEntityController::delete in Commerce Core 7

Deletes multiple customer profiles by ID.

Parameters

$profile_ids: An array of customer profile IDs to delete.

$transaction: An optional transaction object.

$entity_context: An optional entity context array that specifies the entity throgh whose customer profile reference field the given profiles are being deleted:

  • entity_type: the type of entity
  • entity_id: the unique ID of the entity

Return value

TRUE on success, FALSE otherwise.

Overrides DrupalCommerceEntityController::delete

File

modules/customer/includes/commerce_customer_profile.controller.inc, line 145
The controller for the customer profile entity containing the CRUD operations.

Class

CommerceCustomerProfileEntityController
The controller class for customer profiles contains methods for the profile CRUD operations. The load method is inherited from the default controller.

Code

public function delete($profile_ids, DatabaseTransaction $transaction = NULL, $entity_context = array()) {
  if (!empty($profile_ids)) {
    $profiles = $this
      ->load($profile_ids, array());
    $profile_ids_to_remove = array();

    // Ensure the customer profiles can actually be deleted.
    foreach ((array) $profiles as $profile_id => $profile) {

      // If we received an entity context for this profile, add it now.
      if (!empty($entity_context)) {
        $profile->entity_context = $entity_context;
      }

      // If the profile cannot be deleted, remove it from the profiles array.
      if (!commerce_customer_profile_can_delete($profile)) {
        unset($profiles[$profile_id]);
        $profile_ids_to_remove[] = $profile_id;
      }
    }

    // If none of the specified profiles can be deleted, return FALSE.
    if (empty($profiles)) {
      return FALSE;
    }
    $profile_ids = array_diff($profile_ids, $profile_ids_to_remove);
    parent::delete($profile_ids, $transaction);
    return TRUE;
  }
  else {
    return FALSE;
  }
}