CiviCRM Community Forums (archive)

*

News:

Have a question about CiviCRM?
Get it answered quickly at the new
CiviCRM Stack Exchange Q+A site

This forum was archived on 25 November 2017. Learn more.
How to get involved.
What to do if you think you've found a bug.



  • CiviCRM Community Forums (archive) »
  • Old sections (read-only, deprecated) »
  • Discussion (deprecated) »
  • Feature Requests and Suggestions (Moderator: Dave Greenberg) »
  • Variable amounts for memberships dues in member pricesets
Pages: [1]

Author Topic: Variable amounts for memberships dues in member pricesets  (Read 2254 times)

mclyde

  • I post frequently
  • ***
  • Posts: 171
  • Karma: 3
    • International Society for Bayesian Analysis
  • CiviCRM version: 4.2.7
  • CMS version: Drupal 6.x
  • MySQL version: 5.136
  • PHP version: 5.2.16
Variable amounts for memberships dues in member pricesets
October 13, 2011, 01:22:11 pm
For lifetime members, I would like to offer a variable amount membership based on age

Add a custom field to profile in the membership form  to get  age

amount for lifetime = (15  + max(0, 50 - age) )* (annualdues)

Is this feasible with member pricesets?  can the amount field have  php code that returns a value?  can the age variable be accessed in the current form? or would a hook be needed?


Related to variable amounts is it possible to have units or quantities as an input (with customizable label)?  If so current age could be entered in the field for quantity, and as long as there is a min fee that would (reg dues * 15) this would work.

The variable quantity would also be useful for donations  (increments of base amount), although having an other field with a variable amount would be best there!

cheers,
Merlise

Merlise Clyde

Dave Greenberg

  • Administrator
  • I’m (like) Lobo ;)
  • *****
  • Posts: 5760
  • Karma: 226
    • My CiviCRM Blog
Re: Variable amounts for memberships dues in member pricesets
October 13, 2011, 04:58:07 pm
You cannot currently link a membership type to a price set field of where HTML type is "text". However, you might be able to use a text "quantity" price set field to add a "discount" based on age. Rough example - value of this additional fields is "-3", and user enters age as 50.  If the "base" lifetime membership costs $500, their total would be changed to 500 - (3 x 50) = $350.

If you can't make a formula like that work, I think you'll need to investigate the buildAmount hook. However, not sure if you can use it to modify fees on Confirm page (after you have the "age" or core birth date value established). ???
Protect your investment in CiviCRM by  becoming a Member!

mclyde

  • I post frequently
  • ***
  • Posts: 171
  • Karma: 3
    • International Society for Bayesian Analysis
  • CiviCRM version: 4.2.7
  • CMS version: Drupal 6.x
  • MySQL version: 5.136
  • PHP version: 5.2.16
Re: Variable amounts for memberships dues in member pricesets
October 14, 2011, 11:04:24 am
OK - current field type is monetary so php snippet won't work...

Will there be support for a quantity price set field for discounts with membership pricesets?  (cna't remember if they are already available for events)?

Since memberprice set amounts are not linked (I am now convinced that is a good feature :-) to  the membershiptype amount will the hook_civicrm_buildAmount( $pageType, &$form, &$amount ) work  now ? (earlier docs said no)

(I am new to building hooks so don't want to invest too much time if anyone knows that it won;t work  :-)


Merlise Clyde

TwoMice

  • I post frequently
  • ***
  • Posts: 214
  • Karma: 16
    • Emphanos
  • CiviCRM version: Always current stable version
  • CMS version: Drupal 7
Re: Variable amounts for memberships dues in member pricesets
October 14, 2011, 11:44:33 am
Hi Merlise,

We recently did something similar for a client using mostly JavaScript on the front end.  The basic idea was to use "allow other amounts" for the membership fee, and then use JavaScript to set the correct amount based on user input.  With JS you can hide the "other amount" field, and just present the user with the age field, calculate the amount on the spot, and submit that in the "other amount" field. 

This also required a couple of extra steps to be complete:
  • use hook_civicrm_validate to ensure the "other amount" calculation wasn't tinkered with on the front end
  • use hook_civicrm_buildForm (and/or some JavaScript) to to adjust the content of the confirmation page, so it fits what the user is expecting

I would expect something like this would work very well in your situation.

All the best,
Allen
Please consider contributing to help improve CiviCRM with the Make it Happen! initiative.

Dave Greenberg

  • Administrator
  • I’m (like) Lobo ;)
  • *****
  • Posts: 5760
  • Karma: 226
    • My CiviCRM Blog
Re: Variable amounts for memberships dues in member pricesets
October 14, 2011, 03:07:25 pm
Merlise - I think the price set form fields are "hookable" - that was part of the spec (but I haven't tried it). Might wanna check w/ Eileen on IRC since she needed that.

Regarding my 1st idea, I only realized when I tried to do it that we had unintentionally blocked use of the Text / Numeric Quantity price field type for memberships. The intent was to not allow them to be used to purchase memberships (since we didn't want to worry about what it means to buy > 1 membership). However, they are useful and should be allowed for additional contributions (variable amount) and for discounts. So I filed an issue and fixed this for 3.4.7 / 4.0.7 due out next week:

http://issues.civicrm.org/jira/browse/CRM-9038

The change is simple if you want to try it right away. comment out this line (around line 213) in CRM/Price/Form/Field.php:

Code: [Select]
unset( $htmlTypes['Text'] );
I'm not sure if you can now make this approach work since the decrementing would apply to any selected membership type (unless you put Lifetime memberships on their own page). Maybe you can add jquery to hide this age discounting field by default and unhide if user selects a Lifetime membership ???

Protect your investment in CiviCRM by  becoming a Member!

mclyde

  • I post frequently
  • ***
  • Posts: 171
  • Karma: 3
    • International Society for Bayesian Analysis
  • CiviCRM version: 4.2.7
  • CMS version: Drupal 6.x
  • MySQL version: 5.136
  • PHP version: 5.2.16
Re: Variable amounts for memberships dues in member pricesets
October 15, 2011, 10:13:11 pm
OK - I see how that works as a (non discount) to life memberhships; set base rate for life membership, then add a field for  number of years until turn 50, with amount that is the reg dues rate.     If it were optional, then the member could be instructed to ignore if they are not purchasing a life memberships.

(I am not up on jquery yet  - any examples in the forums as a starting point? )

Thanks!
Merlise
Merlise Clyde

Dave Greenberg

  • Administrator
  • I’m (like) Lobo ;)
  • *****
  • Posts: 5760
  • Karma: 226
    • My CiviCRM Blog
Re: Variable amounts for memberships dues in member pricesets
October 16, 2011, 09:57:50 am
Check this blog post:
http://civicrm.org/blogs/hershel/how-customize-civicrm-pages-jquery

.. and I think there's more in the new developer guide
http://en.flossmanuals.net/civicrm-developer-guide/
Protect your investment in CiviCRM by  becoming a Member!

Pages: [1]
  • CiviCRM Community Forums (archive) »
  • Old sections (read-only, deprecated) »
  • Discussion (deprecated) »
  • Feature Requests and Suggestions (Moderator: Dave Greenberg) »
  • Variable amounts for memberships dues in member pricesets

This forum was archived on 2017-11-26.