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) »
  • Developer Discussion (Moderator: Donald Lobo) »
  • Why are membership not supported with prices sets?
Pages: [1] 2 3 ... 6

Author Topic: Why are membership not supported with prices sets?  (Read 34175 times)

jalama

  • I post frequently
  • ***
  • Posts: 176
  • Karma: 22
    • Rooty Hollow LLC
  • CiviCRM version: 3.3.5
  • CMS version: Drupal 6 and 7
  • MySQL version: 5.1
  • PHP version: 5.2.5 and 5.3
Why are membership not supported with prices sets?
June 21, 2010, 12:26:39 pm
in http://forum.civicrm.org/index.php/topic,11725.0.html

Yoshida states that Memberships are not support with Price Sets in 3.1, I'm curious as to why that decision was made.
http://www.rootyhollow.com

Donald Lobo

  • Administrator
  • I’m (like) Lobo ;)
  • *****
  • Posts: 15963
  • Karma: 470
    • CiviCRM site
  • CiviCRM version: 4.2+
  • CMS version: Drupal 7, Joomla 2.5+
  • MySQL version: 5.5.x
  • PHP version: 5.4.x
Re: Why are membership not supported with prices sets?
June 21, 2010, 07:20:05 pm

i suspect the folks who originally funded it did not incorporate that in their request

i'm just guessing here

lobo

p.s> its yashodha :)
A new CiviCRM Q&A resource needs YOUR help to get started. Visit our StackExchange proposed site, sign up and vote on 5 questions

jalama

  • I post frequently
  • ***
  • Posts: 176
  • Karma: 22
    • Rooty Hollow LLC
  • CiviCRM version: 3.3.5
  • CMS version: Drupal 6 and 7
  • MySQL version: 5.1
  • PHP version: 5.2.5 and 5.3
Re: Why are membership not supported with prices sets?
June 22, 2010, 08:54:27 am
Just checking, there wasn't some sort of architectural/data storage reason not to?
http://www.rootyhollow.com

Donald Lobo

  • Administrator
  • I’m (like) Lobo ;)
  • *****
  • Posts: 15963
  • Karma: 470
    • CiviCRM site
  • CiviCRM version: 4.2+
  • CMS version: Drupal 7, Joomla 2.5+
  • MySQL version: 5.5.x
  • PHP version: 5.4.x
Re: Why are membership not supported with prices sets?
June 22, 2010, 01:38:41 pm

i dont think so. I think it was more to do with state of the code and what we could reasonably fit into 3.1

lobo
A new CiviCRM Q&A resource needs YOUR help to get started. Visit our StackExchange proposed site, sign up and vote on 5 questions

jalama

  • I post frequently
  • ***
  • Posts: 176
  • Karma: 22
    • Rooty Hollow LLC
  • CiviCRM version: 3.3.5
  • CMS version: Drupal 6 and 7
  • MySQL version: 5.1
  • PHP version: 5.2.5 and 5.3
Re: Why are membership not supported with prices sets?
June 22, 2010, 03:08:47 pm
Hey look I just changed to "I post frequently" lucky me :)
http://www.rootyhollow.com

petednz

  • Forum Godess / God
  • I’m (like) Lobo ;)
  • *****
  • Posts: 4899
  • Karma: 193
    • Fuzion
  • CiviCRM version: 3.x - 4.x
  • CMS version: Drupal 6 and 7
Re: Why are membership not supported with prices sets?
July 25, 2010, 07:59:01 pm
not frequently enough though :P

did you dig any deeper in to the question of price sets and membership?
Sign up to StackExchange and get free expert advice: https://civicrm.org/blogs/colemanw/get-exclusive-access-free-expert-help

pete davis : www.fuzion.co.nz : connect + campaign + communicate

jalama

  • I post frequently
  • ***
  • Posts: 176
  • Karma: 22
    • Rooty Hollow LLC
  • CiviCRM version: 3.3.5
  • CMS version: Drupal 6 and 7
  • MySQL version: 5.1
  • PHP version: 5.2.5 and 5.3
Re: Why are membership not supported with prices sets?
July 27, 2010, 09:09:54 am
Yea haven't been able to get my head above water lately. :(

We ended up using hook_civicrm_formBuild to re-build the forms with both the memberships and the price sets.  Code pasted below, you will need to edit it for your purposes.

note these lines mean we are depending on a price set field with an id of 8 in the civicrm_price_field table "$index = $form->_elementIndex['price_8'];" and "$data['values']['Main']['price_8'] = $membership_type[$selectMembership]['minimum_fee'];"

Code: [Select]
/**
  4  * Implementation of hook_civicrm_buildForm().
  5  */
  6 function modulename_civicrm_buildForm($formName, &$form) {
  7   // CRM_Contribute_Form_Contribution_Main is the contribution page form.
  8   if ($formName == 'CRM_Contribute_Form_Contribution_Main') {
  9     // The membership placeholder line item needs to have a default value set
 10     // that is greater than or equal to the largest membership fee.
 11     $maxPrice = 0;
 12
 13     require_once drupal_get_path('module', 'civicrm') .'/../api/Membership.php';
 14
 15     // Membership type IDs are stashed in membership block as comma separated
 16     // string.
 17     $types = explode(',', $form->_membershipBlock['membership_types']);
 18     $prices = array();
 19     foreach ($types as $type) {
 20
 21       // Get the membership type.
 22       $membership_type = crm_get_membership_types(array('id' => $type));
 23       if (!is_a($membership_type, 'CRM_Core_Error')) {
 24
 25         // Stash the price by Membership type ID.
 26         $prices[$type] = $membership_type[$type]['minimum_fee'];
 27
 28         // Keep track of the largest price in the membership block.
 29         if ($maxPrice < $membership_type[$type]['minimum_fee']) {
 30           $maxPrice = $membership_type[$type]['minimum_fee'];
 31         }
 32       }
 33     }
 34
 35     // _elementIndex keys are recognizeable names while the value is an integer
 36     // that is the index of the actual _elements array in the form object.
 37     $index = $form->_elementIndex['selectMembership'];
 38     $selectMembership = $form->_elements[$index];
 39
 40     // TODO: This loop could me merged with the previous loop because the number
 41     // of types in the membership block should be the same as the number of
 42     // elements in the selectMembership group in the form.
 43     foreach ($selectMembership->_elements as &$element) {
 44
 45       // Nothing in the input element refers to the membership type except for
 46       // the value attribute of the HTML element.
 47       $membership_type = $element->getAttribute('value');
 48       $element->setAttribute('price', json_encode(array($membership_type, $prices[$membership_type])));
 49     }
 50
 51     // Set the membership placeholder to an always valid value, the most
 52     // expensive membership in the block.
 53     $index = $form->_elementIndex['price_8'];
 54     $element =& $form->_elements[$index];
 55     $element->setAttribute('value', (int) $maxPrice);
 56
 57     // Removing the price attribute causes the script to ignore the field's
 58     // value when calculating the JS UI total.
 59     $element->removeAttribute('price');
 60   }
 61 }

 63 /**
 64  * Implementation of hook_civicrm_validate().
 65  */
 66 function modulename_civicrm_validate($formName, &$fields, &$files, &$form) {
 67   if ($formName == 'CRM_Contribute_Form_Contribution_Main') {
 68
 69     // Grab the membership type the user selected.
 70     // TODO: Handle no input. I suspect if the user chooses nothing, the largest
 71     // membership price will be in the total.
 72     $selectMembership = $fields['selectMembership'];
 73     $membership_type = crm_get_membership_types(array('id' => $selectMembership));
 74
 75     // See matt2000: http://pastebin.com/cY4ywrUL
 76     $data =& $form->controller->container();
 77     $data['values']['Main']['price_8'] = $membership_type[$selectMembership]['minimum_fee'];
 78   }
 79 }


http://www.rootyhollow.com

petednz

  • Forum Godess / God
  • I’m (like) Lobo ;)
  • *****
  • Posts: 4899
  • Karma: 193
    • Fuzion
  • CiviCRM version: 3.x - 4.x
  • CMS version: Drupal 6 and 7
Re: Why are membership not supported with prices sets?
July 27, 2010, 12:48:26 pm
'Head above water' - now there is a novel concept  ::)

Thanks for posting - will give it a whirl sometime
Sign up to StackExchange and get free expert advice: https://civicrm.org/blogs/colemanw/get-exclusive-access-free-expert-help

pete davis : www.fuzion.co.nz : connect + campaign + communicate

petednz

  • Forum Godess / God
  • I’m (like) Lobo ;)
  • *****
  • Posts: 4899
  • Karma: 193
    • Fuzion
  • CiviCRM version: 3.x - 4.x
  • CMS version: Drupal 6 and 7
Re: Why are membership not supported with prices sets?
July 28, 2010, 08:00:14 pm
Hey Jim - just before I throw myself at this, can you clarify the expected outcomes. So Membership page includes a Price Set that could eg be used for separate donation? and/or buying that cute t-shirt?
A single transaction is sent via Payment Processor?
Two or more Contribution records are created, eg one for the Membership and one for the baseball cap?

Couple of screenshots would be useful too ;-)
Sign up to StackExchange and get free expert advice: https://civicrm.org/blogs/colemanw/get-exclusive-access-free-expert-help

pete davis : www.fuzion.co.nz : connect + campaign + communicate

jalama

  • I post frequently
  • ***
  • Posts: 176
  • Karma: 22
    • Rooty Hollow LLC
  • CiviCRM version: 3.3.5
  • CMS version: Drupal 6 and 7
  • MySQL version: 5.1
  • PHP version: 5.2.5 and 5.3
Re: Why are membership not supported with prices sets?
July 29, 2010, 06:19:17 am
Peter,

It will all be one payment and one transaction with a price set in the transaction

Jim
http://www.rootyhollow.com

petednz

  • Forum Godess / God
  • I’m (like) Lobo ;)
  • *****
  • Posts: 4899
  • Karma: 193
    • Fuzion
  • CiviCRM version: 3.x - 4.x
  • CMS version: Drupal 6 and 7
Re: Why are membership not supported with prices sets?
July 29, 2010, 03:00:21 pm
Thanks so much for clarifying that.
Sign up to StackExchange and get free expert advice: https://civicrm.org/blogs/colemanw/get-exclusive-access-free-expert-help

pete davis : www.fuzion.co.nz : connect + campaign + communicate

DeeFisher

  • I’m new here
  • *
  • Posts: 14
  • Karma: 1
    • New York State Psychological Association
  • CiviCRM version: 4.1.5
  • CMS version: Joomla 2.5.6
  • MySQL version: 5.1.45
  • PHP version: 5.3.10
Re: Why are membership not supported with prices sets?
August 03, 2010, 07:38:46 am
We are trying to implement this for our organization, which has a base membership (15 different levels) and 16 divisional "add-ons" that all have different fee levels.  I'm a novice with php, but am trying to muddle my way through it.  Any help would be greatly appreciated!

I'm using Joomla 1.5 and CiviCRM 3.2.0.  We're getting the following errors on the contribution page (actually on all contribution pages) when the hook file is turned on:

Warning: Invalid argument supplied for foreach() in /home/nyspa/nyspa15/custom_civicrm_code/civicrmHooks.php on line 41
Notice: Undefined index: price_16 in /home/nyspa/nyspa15/custom_civicrm_code/civicrmHooks.php on line 51
Fatal error: Call to a member function setAttribute() on a non-object in /home/nyspa/nyspa15/custom_civicrm_code/civicrmHooks.php on line 53

I'm guessing there were further modifications I needed to make, but here is my edited code:
Code: [Select]
function joomla_civicrm_buildForm($formName, &$form) {
   // CRM_Contribute_Form_Contribution_Main is the contribution page form.
   if ($formName == 'CRM_Contribute_Form_Contribution_Main') {
     // The membership placeholder line item needs to have a default value set
     // that is greater than or equal to the largest membership fee.
     $maxPrice = 270;
 
     require_once '/home/nyspa/nyspa15/administrator/components/com_civicrm/civicrm/api/Membership.php';

     // Membership type IDs are stashed in membership block as comma separated
     // string.
     $types = explode(',', $form->_membershipBlock['membership_types']);
     $prices = array();
     foreach ($types as $type) {
 
       // Get the membership type.
       $membership_type = crm_get_membership_types(array('id' => $type));
       if (!is_a($membership_type, 'CRM_Core_Error')) {
 
         // Stash the price by Membership type ID.
         $prices[$type] = $membership_type[$type]['minimum_fee'];
 
         // Keep track of the largest price in the membership block.
         if ($maxPrice < $membership_type[$type]['minimum_fee']) {
           $maxPrice = $membership_type[$type]['minimum_fee'];
         }
       }
     }
 
     // _elementIndex keys are recognizeable names while the value is an integer
     // that is the index of the actual _elements array in the form object.
     $index = $form->_elementIndex['selectMembership'];
     $selectMembership = $form->_elements[$index];
 
     // TODO: This loop could me merged with the previous loop because the number
     // of types in the membership block should be the same as the number of
     // elements in the selectMembership group in the form.
     foreach ($selectMembership->_elements as &$element) {
 
       // Nothing in the input element refers to the membership type except for
       // the value attribute of the HTML element.
       $membership_type = $element->getAttribute('value');
       $element->setAttribute('price', json_encode(array($membership_type, $prices[$membership_type])));
     }

     // Set the membership placeholder to an always valid value, the most
     // expensive membership in the block.
     $index = $form->_elementIndex['price_16'];
     $element =& $form->_elements[$index];
     $element->setAttribute('value', (int) $maxPrice);
 
     // Removing the price attribute causes the script to ignore the field's
     // value when calculating the JS UI total.
     $element->removeAttribute('price');
   }
 }

 /**
  * Implementation of hook_civicrm_validate().
  */
 function joomla_civicrm_validate($formName, &$fields, &$files, &$form) {
   if ($formName == 'CRM_Contribute_Form_Contribution_Main') {
 
     // Grab the membership type the user selected.
     // TODO: Handle no input. I suspect if the user chooses nothing, the largest
     // membership price will be in the total.
     $selectMembership = $fields['selectMembership'];
     $membership_type = crm_get_membership_types(array('id' => $selectMembership));
 
     // See matt2000: http://pastebin.com/cY4ywrUL
     $data =& $form->controller->container();
     $data['values']['Main']['price_16'] = $membership_type[$selectMembership]['minimum_fee'];
   }
 }

Is this a lot bigger than I think it is?  Thanks!!

jalama

  • I post frequently
  • ***
  • Posts: 176
  • Karma: 22
    • Rooty Hollow LLC
  • CiviCRM version: 3.3.5
  • CMS version: Drupal 6 and 7
  • MySQL version: 5.1
  • PHP version: 5.2.5 and 5.3
Re: Why are membership not supported with prices sets?
October 01, 2010, 07:27:59 am
Just to make sure, is the price set with the price_16 field enabled on the page, you will have to do that in MYSQL as the contribution page's form validation won't allow you to have both a membership block and a price set enabled.

You will need to insert the record into the civicrm_price_set_entity table.
http://www.rootyhollow.com

fry.pan

  • Guest
Re: Why are membership not supported with prices sets?
November 15, 2010, 10:07:58 am
So this seems like it should be simple yet I think that I am missing one simple part.  What should I set the values in civicrm_price_set_entity table too?  It seems like it should be...

entity_table = civicrm_contribution_page
entity_id      = the ID of the membership sign up page in the civicrm_contribution page
price_set_id = the price set that I want to include

Is that right?  The membership sign up page is displayed but the membership options/prices do not appear.

Thanks!

speleo

  • Ask me questions
  • ****
  • Posts: 396
  • Karma: 28
  • CiviCRM version: 4.3.1
  • CMS version: J! 2.5,9
  • MySQL version: 5.1
  • PHP version: 5.3.24
Re: Why are membership not supported with prices sets?
November 15, 2010, 02:26:22 pm
I really need this functionality but would like it in the stable version.  It feels as if CiviMember hasn't been updated for years and is lacking now. This would be a major step forward for folks managing complex membership levels.

Would it be hard to get this in core?

Pages: [1] 2 3 ... 6
  • CiviCRM Community Forums (archive) »
  • Old sections (read-only, deprecated) »
  • Developer Discussion (Moderator: Donald Lobo) »
  • Why are membership not supported with prices sets?

This forum was archived on 2017-11-26.