Deleting a discount code that has already been used leaves orphan tracks visible on the contact page.

If a discount code has already been used, perhaps the user shouldn't be able to delete the discount code unless they know it will wipe all history and be able to delete the discount_track as well.

I changed the civievent_discount_delete() function to:

function civievent_discount_delete() {
  $cid = arg(4);
  $cid = db_fetch_object(db_query(_sql_get_code(), $cid));
  if ($cid) {
    if ($cid->count_use == 0) {
      $form['code'] = array('#type' => 'hidden', '#value' => $cid->code);
      $form['cid'] = array('#type' => 'hidden', '#value' => $cid->cid);

      return confirm_form($form, t('Are you sure you want to delete the discount code %code?', array('%code' =>
$cid->code)), 'admin/settings/civievent_discount', NULL, t('Delete'), t('Cancel'));
    } else {
      drupal_set_message(t('Cannot delete discount code (%code) since it has already been redeemed at least once.',
array('%code' => $cid->code)), $type='warning');
      drupal_goto('admin/settings/civievent_discount');
    }
  } else {
    drupal_set_message(t('Cowardly refusing to delete nonexistent discount code (%id).', array('%id' => arg(4))), $type='w$
    drupal_goto('admin/settings/civievent_discount');
  }
}

Perhaps better would be to disable/remove the delete link on used discount codes.

Comments

dharmatech’s picture

nubeli, thanks for the suggestion. How about this:

  1. change the action to 'disable' if it's been redeemed
  2. offer the ability to hide disabled codes
  3. change the action to 'enable' if the code is currently disabled
  4. add validation to verify code is enabled when attempting to redeem

Want to take a crack at that and submit a patch? :)

nubeli’s picture

1. I wonder what the disable/enable link would do? Would likely need to add a 'status' field.
2. Probably better to enable filtering for code status than hide. In our case we'll need access to an "archive" of codes that have expired that are separate from the active codes and maybe also list disabled codes separately.

Even better would be to expose the codes to Views so people can make arbitrary reports.

4. So if a code is expired, exceeded # of uses, or is disabled then don't use in validation.

I'm looking into it and might submit a patch but can't promise it will be elegant.

dharmatech’s picture

Status: Active » Postponed