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 4 ... 6

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

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?
November 15, 2010, 07:36:30 pm

Its a bit more involved than just setting the DB values :) It is not a trivial project (< 10 hours), on the other hand i dont think its super complex either :)

In general functionality like CiviMember gets updated / improved when

a. Someone in the community steps up and pushes development forward by providing patches / code etc
b. Someone in the community sponsors functionality / features to take it to the next level

We have not had this happen with CiviMember as yet. the other components have gotten a lot of a and b above

So if you do want improvements and updates to CiviMember might want to consider doing either / both of the above points. Waiting for things to improve does not improve them :(

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

fry.pan

  • Guest
Re: Why are membership not supported with prices sets?
November 16, 2010, 06:04:32 am
I knew that someone would respond to Speleo with the two default OSS answers (do it or pay someone to do it).  Lobo do you have a document with default answers that you just copy and paste from?   ;)

Eileen

  • Forum Godess / God
  • I’m (like) Lobo ;)
  • *****
  • Posts: 4195
  • Karma: 218
    • Fuzion
Re: Why are membership not supported with prices sets?
December 06, 2010, 11:34:59 am
Lobo

Does this fit in 'small' - 10-20 hours?
Make today the day you step up to support CiviCRM and all the amazing organisations that are using it to improve our world - http://civicrm.org/contribute

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?
December 06, 2010, 01:03:55 pm

nope. it would be at least 50 hours, IMO

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

mdavid

  • I post occasionally
  • **
  • Posts: 31
  • Karma: 0
  • CiviCRM version: 4.2
  • CMS version: Drupal 7.15
  • MySQL version: 5.1.63
  • PHP version: 5.2.17
Re: Why are membership not supported with prices sets?
December 19, 2010, 10:04:18 pm
I've spent the weekend trying to implement the code so generously provided by jalama in note #6 and it's not quite working as expected yet.

Here's what I've done:
  • Created Membership Types in Administer > CiviMember
  • Created a price set and price fields in Contributions > New Price Set
  • Created a module for the hook using the code from jalama
  • Edited jalama's code to use 'price_3' instead of 'price_8' to match my price field ID
  • Created the .info file for the module
  • Uploaded the .module and .info files to /sites/all/modules/feeshook
  • Enabled the module in Drupal
  • Inserted the record into the civicrm_price_set_entity table in MySQL

I expected the following:
  • The Membership Signup and Renewal page would display both the Membership Types and the Price Set
  • The user would select both a Membership Type and a Price Set item
  • The Total Fee(s) would add the two fees together and display the total

Here's what's actually happening:
  • The Membership Signup and Renewal page displays only the Price Set; the Membership Types do not display
  • When an item from the Price Set is selected, the Total Fee(s) remains blank

What am I missing to make the hook work?

Thanks!

flug

  • I post frequently
  • ***
  • Posts: 126
  • Karma: 12
Re: Why are membership not supported with prices sets?
December 31, 2010, 06:38:31 pm
Quote from: speleo on 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?

Lobo estimated it as a 75-100 hour project when we discussed this previously here.

However if the patch mentioned above works maybe it's a bit smaller project--I'd be interested to hear what the developers might have to say.  I would assume there is some reason why they didn't implement the fairly simple solution in the patch in the first places--maybe there are edge cases where it doesn't work, or maybe it would simply take a lot of testing to make sure it really does work & they just didn't have time for that at the time.

At any rate, I'd also be very interested in this feature.

flug

  • I post frequently
  • ***
  • Posts: 126
  • Karma: 12
Re: Why are membership not supported with prices sets?
January 01, 2011, 02:59:11 am
Quote from: mdavid on December 19, 2010, 10:04:18 pm


What am I missing to make the hook work?

Thanks!

After beating my head against the wall for a few hours, I remembered the template files.

It turns out the current logic in the template file for contribution pages is to display EITHER the price set OR the membership options but never both.

Once you have made all the changes listed above, you can make a custom template file for CRM/Contribute/Form/Contribution/Main.tpl that makes this change--it's pretty easy.  Once I did that, both the membership & the price set options are definitely displaying.  I haven't done any testing to see if they are working correctly, though!  (And I'm not very sure they will work correctly.)

  • Set up a custom template directory, instructions here: http://wiki.civicrm.org/confluence/display/CRMDOC33/Directories
  • Under that directory, create the subdirectories CRM/Contribute/Form/Contribution
  • Under that subdirectory, copy Main.tpl from l/sites/all/modules/civicrm/templates/CRM/Contribute/Form/Contribution
  • Then edit this copy of Main.tpl to display both the membership & price set blocks (actually neither will display unless those fields are present, so this is a pretty good/safe solution).  Sample code below.

Here is what the relevant part of Main.tpl looks like (starting around like 65):
Code: [Select]
{if $priceSet}
    <div id="priceset">
        <fieldset>
            <legend>{ts}Contribution{/ts}</legend>
            {include file="CRM/Price/Form/PriceSet.tpl"}
        </fieldset>
    </div>
{else}  

{if $form.amount}
   <div class="crm-section {$form.amount.name}-section">
<div class="label">{$form.amount.label}</div>
<div class="content">{$form.amount.html}</div>
<div class="clear"></div>
   </div>
{/if}
{if $is_allow_other_amount}
   <div class="crm-section {$form.amount_other.name}-section">
<div class="label">{$form.amount_other.label}</div>
<div class="content">{$form.amount_other.html|crmMoney}</div>
<div class="clear"></div>
   </div>
{/if}
{if $pledgeBlock}
   {if $is_pledge_payment}
   <div class="crm-section {$form.pledge_amount.name}-section">
<div class="label">{$form.pledge_amount.label}&nbsp;<span class="marker">*</span></div>
<div class="content">{$form.pledge_amount.html}</div>
<div class="clear"></div>
   </div>
   {else}
   <div class="crm-section {$form.is_pledge.name}-section">
<div class="content">
{$form.is_pledge.html}&nbsp;
{if $is_pledge_interval}
{$form.pledge_frequency_interval.html}&nbsp;
{/if}
{$form.pledge_frequency_unit.html}&nbsp;{ts}for{/ts}&nbsp;{$form.pledge_installments.html}&nbsp;{ts}installments.{/ts}
</div>
   </div>
   {/if}
{/if}
{/if}



« Last Edit: January 01, 2011, 03:05:24 am by flug »

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?
January 01, 2011, 02:24:16 pm
Top stuff. Please keep us informed of how it goes as I'm following with a lot of interest.

Cheers, Speleo

flug

  • I post frequently
  • ***
  • Posts: 126
  • Karma: 12
Completely worked out module for contribution forms with membership & price sets
January 02, 2011, 11:24:13 pm
Ok, I've developed this into a module, based on the code provided by jalama, and solved a bunch of problems with the Confirmation, Thank You page, and email/pdf receipting.  From the readme:

Quote
This module and the instructions included in this distribution will allow you to make a CiviCRM contribution form that combines membership payment/renewal with price sets.

It is tested and works with CiviCRM 3.3.1 and should work with 3.3.0.  It probably will not work with lower versions than 3.3.

It is something of a project to get it going and you have to be comfortable installing & editing PHP files, smarty template files, & editing some in your SQL database.

The file includes an extensive readme with detailed instructions for getting it up & running, so please do read it carefully before attempting.

Download the module file here:

  mobikefed.org/files/member_pricesets/membershippricesets_module-3.3-0.2.tar.gz

UPDATE: Moved to ver. 0.2 already.  Version 0.1 had some typos & incorrect files included.
« Last Edit: January 04, 2011, 01:06:18 am by flug »

flug

  • I post frequently
  • ***
  • Posts: 126
  • Karma: 12
Completely worked out module for contribution forms with membership & price sets
January 04, 2011, 12:31:11 am
By the way, if we were to accept jalama's idea as a reasonable way to address this issue of combining membership payments & price sets, then this module has almost all of the implementation worked out.

How this would look if it were integrated into the code (rather than as a module):

 - Every Price Set would have a hidden field which will hold the membership total amount if memberships are included in the contribution page and the user selects one.

 - Change the contribution admin pages so that both memberships & price sets can be selected simultaneously without creating an error.

(The above two are the only two issues that the module or included files doesn't have completely worked out.)

 - selectMembership elements would need a 'price' attribute added, similar to the ones Price Fields have (see member_pricesets.module lines 81-95).

 - After the form has been submitted, copy the membership price to the special Price Field (similar to member_pricesets.module lines 136-146).

 - Update CRM/Contribute/Form/Contribution/Main.tpl to allow both memberships & price sets to be visible (see Main.tpl about line 65).

 - Update CRM/Member/BAO/Membership.php so that memberships and price sets can both be displayed on the receipts (about 4 lines of code, see Membership.php about line 1145).

 - Fix a couple of bugs in CRM/Contribute/Form/Contribution/ThankYou.php (see ThankYou.php about line 131 and line 152).

 - Incorporate the email receipt templates included in this module--they allow for both membership info & Price Sets to be displayed and rearrange things just slightly so that the receipts make sense with either or both of those options displayed.
  
That's pretty much it.
« Last Edit: January 04, 2011, 12:35:13 am by flug »

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?
January 06, 2011, 07:09:27 am
quick question. Is there anything in the hook which is Drupal specific as I'd like to see If I can port this to Joomla.

mdavid

  • I post occasionally
  • **
  • Posts: 31
  • Karma: 0
  • CiviCRM version: 4.2
  • CMS version: Drupal 7.15
  • MySQL version: 5.1.63
  • PHP version: 5.2.17
Re: Why are membership not supported with prices sets?
January 10, 2011, 11:08:12 am
flug,

Thanks for this - what a great help!

I have followed the readme file step by step as well as your directions here in the forum and believe I have everything set up as directed. However, I'm getting an error message I haven't been able to track down and solve.

The error message displays after I have copied the Main.tpl file into the custom templates directory (custom_templates/CRM/Contribute/Form/Contribution/). Before adding the custom Main.tpl file, the Membership Renewal form displays only the price set and not the Membership types (as expected from your earlier note).

I've tried implementing the module three times and get the same result every time so decided it was time to ask for help.

The error message says:
Code: [Select]
Database Error Code: You have an error in your SQL syntax;
check the manual that corresponds to your MySQL server version
for the right syntax to use near ':5:{i:20;N;i:1;N;i:4;N;i:2;N;i:6;N;} )'
at line 3, 1064

Additional Details:

Array
(
    [callback] => Array
        (
            [0] => CRM_Core_Error
            [1] => handle
        )

    [code] => -2
    [message] => DB Error: syntax error
    [mode] => 16
    [debug_info] =>
SELECT *
FROM   civicrm_membership_type
       WHERE id IN ( a:5:{i:20;N;i:1;N;i:4;N;i:2;N;i:6;N;} );
 [nativecode=1064 ** You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ':5:{i:20;N;i:1;N;i:4;N;i:2;N;i:6;N;} )' at line 3]
    [type] => DB_Error
    [user_info] =>
SELECT *
FROM   civicrm_membership_type
       WHERE id IN ( a:5:{i:20;N;i:1;N;i:4;N;i:2;N;i:6;N;} );
 [nativecode=1064 ** You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ':5:{i:20;N;i:1;N;i:4;N;i:2;N;i:6;N;} )' at line 3]
    [to_string] => [db_error: message="DB Error: syntax error" code=-2 mode=callback callback=CRM_Core_Error::handle prefix="" info="
SELECT *
FROM   civicrm_membership_type
       WHERE id IN ( a:5:{i:20;N;i:1;N;i:4;N;i:2;N;i:6;N;} );
 [nativecode=1064 ** You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ':5:{i:20;N;i:1;N;i:4;N;i:2;N;i:6;N;} )' at line 3]"]
)


The "a:5:{i:20;N;..." in the error message is the content of the membership_types field in the civicrm_membership_block table in MySQL. It was created by CiviCRM when I created the membership types and I have not edited the field directly in the database so I don't know why there would be an error.

I don't know what "line 3, 1064" refers to.

Is this really a MySQL error or is it an error in some code that is calling that field in the database? Is there something I was supposed to edit in the Main.tpl file? I'm puzzled as to where to look for the source of the error and how to fix it. Any ideas?

Many thanks to you, jalama, and Brent for the code and instructions! I have high hopes for a successful implementation if I can get over this error message hump.

Thanks,
Michael

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?
January 10, 2011, 12:18:22 pm
Flug,

I got this working with Joomla. More than happy to document the process but I think that we should be building this out in the wiki rather than here. Do you want to flesh out a page first (as the main developer) and I'll document the changes need to get a working Joomla 1.5 setup.

Many thanks, Henry

mdavid

  • I post occasionally
  • **
  • Posts: 31
  • Karma: 0
  • CiviCRM version: 4.2
  • CMS version: Drupal 7.15
  • MySQL version: 5.1.63
  • PHP version: 5.2.17
Re: Why are membership not supported with prices sets?
January 10, 2011, 11:23:28 pm
After lots more testing and adding and removing things one at a time, here's what I found.

The Database Error I received earlier is eliminated when I delete the custom Membership.php that comes with the module.

Without the custom Membership.php, the Membership/Renewal form displays both the Membership types and the Price Set (hooray!) and is fairly functional. I am able to add a new member, select a membership level and a Price Set item, and the correct total displays in the Total Fees field.

When I click "Continue" to confirm the contribution, the Thank you page displays, but I get a warning:
Code: [Select]
warning: in_array() [function.in-array]:
Wrong datatype for second argument in
.../custom_php/CRM/Contribute/Form/Contribution/ThankYou.php
on line 134.

The email receipt is sent and lists both the Membership fee and the Price Set item fee (although the Membership fee says Qty: 100.00, Unit Price: $1.00, Total Price: $100.00).

As soon as I re-upload the custom Membership.php file, I get the Database Error I reported earlier.

Any suggestions on editing the ThanKYou.php and/or Membership.php or doing something else to resolve this? I poked around the code, but didn't dare change anything without further advice.

Thanks!
 Michael

Eileen

  • Forum Godess / God
  • I’m (like) Lobo ;)
  • *****
  • Posts: 4195
  • Karma: 218
    • Fuzion
Re: Why are membership not supported with prices sets?
February 20, 2011, 01:54:27 pm
I have implemented this module with some adjustments because we wanted to change the price set based on the date and we set the membership minimum amount to $0 and managed the pricing entirely through the priceset. However, the solution is not future-proof & I need to discuss it with my client

IF price sets for memberships were to be developed into core is this approach one that seems acceptable to the core team. It essentially involves adding a 'special' field to a priceset which is populated by the membership cost options from the form (if the membership minimum is more than $0).

Alternatively, it could be that pricesets and memberships can ONLY be combined if the membership is set to $0 and pricing is fully managed through the priceset - I suspect this may not cover back end membership entries very well.
Make today the day you step up to support CiviCRM and all the amazing organisations that are using it to improve our world - http://civicrm.org/contribute

Pages: 1 [2] 3 4 ... 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.