You are here

public function CommerceCouponEntityController::delete in Commerce Coupon 7

Deletes multiple coupons by ID.

Parameters

$coupon_ids: An array of coupon IDs to delete.

$transaction: An optional transaction object.

Return value

TRUE on success, FALSE otherwise.

Overrides DrupalCommerceEntityController::delete

File

classes/commerce_coupon.inc, line 73
Coupon controller class.

Class

CommerceCouponEntityController
@file Coupon controller class.

Code

public function delete($coupon_ids, DatabaseTransaction $transaction = NULL) {
  if (!empty($coupon_ids)) {
    $coupons = $this
      ->load($coupon_ids, array());

    // Ensure the coupons can actually be deleted.
    foreach ((array) $coupons as $coupon_id => $coupon) {
      if (!commerce_coupon_can_delete($coupon)) {
        unset($coupons[$coupon_id]);
      }
    }

    // If none of the specified coupons can be deleted, return FALSE.
    if (empty($coupons)) {
      return FALSE;
    }
    parent::delete(array_keys($coupons), $transaction);
    return TRUE;
  }
  else {
    return FALSE;
  }
}