You are here

function commerce_coupon_delete_form_submit in Commerce Coupon 7.2

Submit callback for commerce_coupon_delete_form().

1 string reference to 'commerce_coupon_delete_form_submit'
commerce_coupon_delete_form in includes/commerce_coupon.admin.inc
Form callback: coupon delete confirmation form.

File

includes/commerce_coupon.admin.inc, line 203
Administrative forms and callbacks for Commerce Coupon.

Code

function commerce_coupon_delete_form_submit($form, &$form_state) {
  $coupon = $form_state['commerce_coupon'];
  $code = $coupon->code;
  $discounts = array();

  // Collect the discount to rebuild.
  if (!empty($coupon->commerce_discount_reference)) {
    $coupon_wrapper = entity_metadata_wrapper('commerce_coupon', $coupon);
    $discounts = $coupon_wrapper->commerce_discount_reference
      ->value();
  }
  if (commerce_coupon_delete($coupon->coupon_id)) {

    // Rebuild the Rules for the referenced discounts.
    if ($discounts) {
      _commerce_discount_rebuild_rules_config($discounts);
    }
    drupal_set_message(t('%code has been deleted.', array(
      '%code' => $code,
    )));
    watchdog('commerce_coupon', 'Deleted coupon %code.', array(
      '%code' => $code,
    ), WATCHDOG_NOTICE);
  }
  else {
    drupal_set_message(t('%code could not be deleted.', array(
      '%code' => $code,
    )), 'error');
  }
  $form_state['redirect'] = 'admin/commerce/coupons';
}