In our usage most of the discount codes will be for 100% discounts - the user will have already paid for the full membership. So there needs to be a usable way to hide the billing requirements if they are going to enter a code. The quickest way to this end (but maybe not the best) is to use the "Pay later" checkbox in CiviCRM and rewrite the option as "Already Paid or will Pay Later" or something like that. It hides the billing nicely.
The drawback is that it doesn't enforce the requirement of the discount code. So it would still allow someone to defer payment and not enter the discount.
To some extent this would require some javascript on the contribution form so I'm not sure how much could be done in this module. But at least myself or others could post solutions here.
Comments
Comment #1
dharmatech CreditAttribution: dharmatech commentedNubeli,
Yes it requires some jquery magic to hide the billing fields. We blogged about it and submitted an issue and patch a couple of months ago to address membership and billing info
w/discounts. Not much we can do about it from the module side unless the showHideBilling() jquery function gets added to core templates.Comment #2
dharmatech CreditAttribution: dharmatech commentedAn additional problem is the validation of the code and processing of the price happens in the next screen via the hook_civicrm_buildAmount().
Comment #3
nubeli CreditAttribution: nubeli commentedRight, that is a problem too. I'm looking into how the "pay later" option prevents that. I am playing with adding a checkbox to show the discount code box and hide the billing info. So I could add a check for that checkbox when building the amount.
Comment #4
nubeli CreditAttribution: nubeli commentedSo here's the approach we are taking to allow the by-pass of the billing information with a 100% discount (which means zero dollars charged). I added a checkbox to civievent_discount_civicrm_buildForm():
I could have figured out how to add the element in a custom module but it would have been a bit of a bother. So for now it's in civievent_discount.
I also created a custom module to do some validation based on the values of the "skipbilling" checkbox I added. It doesn't need to be separate, but figured I'd put it separate as I work on it. When the skipbilling checkbox is checked then it won't require the billing information fields, but will require the discount code field. It will only work if a discount code is set for 100% otherwise it requires the billing information and sends an error.
The problem that arose was that it was now possible to get a membership for free if someone just entered a wrong discount code! So I ended up moving the validation from civievent_discount_civicrm_membershipTypeValues() to civievent_discount_civicrm_validate(). It worked at least in CiviCRM 3.3.5:
I had also added some jquery to a custom template for the contribution form (this is optional) to hide the billing fields when the skipbilling checkbox is checked. (I originally hid the discount field too but then it won't work for less 100% discounts.) So at CRM/Contribute/Form/Contribution/Main.tpl (make a copy of the default template and put in your own custom template) and added the not-so-elegant javascript:
I'm not going to add my copy of civievent_discount.module file since I think there are some other things in it that aren't in the current dev version. Hopefully that's enough info to figure this out. If you want to roll it into the dev version feel free and I won't have to maintain a custom module. This would be useful for anyone who is giving out 100% discounts and the user knows they've paid for the full amount already so don't want to bother with filling in the billing information for no reason.
Comment #5
nubeli CreditAttribution: nubeli commentedI decided to merge my changes into the May2, 2011 dev version. The civievent_discount_civicrm_membershipTypeValues() is still minimized as the validation is moved to hook_validate. Now it also checks that the code submitted matches the chosen membership level, in addition to checking for invalid/expired codes. Sorry for not providing proper patches.
And I improved my custom validation so that it only checks if the discount is 100%:
Comment #6
nubeli CreditAttribution: nubeli commentedA much easier way to include the js seems obvious now that I've seen it done. Include the js in civievent_discount_civicrm_buildForm() like this:
drupal_add_js(drupal_get_path('module','civievent_discount') . '/skipbilling.js');
Comment #7
dharmatech CreditAttribution: dharmatech commentedCleaning up old tickets. Marking as "closed (won't fix)" since it requires editing the templates. I'll add it to the project page under Theming.