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) »
  • civicrm, renewMember & ubercart
Pages: [1]

Author Topic: civicrm, renewMember & ubercart  (Read 1584 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
civicrm, renewMember & ubercart
May 18, 2011, 11:11:38 am
I have been working on extending the uc_civicrm_module so that one could purchase multiple memberships and make donations from one signup page via an ubercart product views.

To handle renewals I would like to call the CRM/Member/BAO/Membership::renewMember function so that any membership renewal that is done via ubercart is carried out the same way as with a civiContribute signup/renewal page.

The fourth argument of the function is a form.    How can I make a new form (of the right class?)  and populate it with my arguments  to call the renewMembership function?  (I am trying to get up to speed with php,  but need some help here working with objects :-)

I have tested the module now with a modfied version of the renewMembership code commenting out the references to $form and it does update memberships the same as with the front end,  and link them properly to the contact records.   As there are still some issues with membership upsell I do not want to maintain a standalone function that duplicates the effort in core. 

Just to clarify I do not want to expose the form object to the user for input, but want to just treat it as an argument so that I may re-use the existing code. 

best,
Merlise
« Last Edit: May 18, 2011, 06:12:35 pm by mclyde »
Merlise Clyde

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: civicrm, renewMember & ubercart
May 18, 2011, 07:14:29 pm
if I use the following:
Code: [Select]

$cid = 20;  // existing contribution page
require_once 'CRM/Contribute/BAO/ContributionPage.php';
$civiform =  CRM_Contribute_BAO_ContributionPage::copy($cid);
  _civicrm_object_to_array(CRM_Member_BAO_Membership::renewMembership($contact_id,  $membershipTypeID, $is_test, $civiform, date('YmdHis'), null,null ),  $membership);

everything works!

However if I try to use the following code to create a new page
Code: [Select]
$formparams = array('membership_source' => 'Ubercart Order',); // add other params too
$civiform = CRM_Contribute_BAO_ContributionPage::create($formparams);
THen I end up with a DB error "Constraint Violation"   any suggestions about what I am doing wrong here? 
Merlise Clyde

xavier

  • Forum Godess / God
  • I’m (like) Lobo ;)
  • *****
  • Posts: 4453
  • Karma: 161
    • Tech To The People
  • CiviCRM version: yes probably
  • CMS version: drupal
Re: civicrm, renewMember & ubercart
May 19, 2011, 02:18:16 am
Hi,

I think membership api does offer the function (and definitely you should use the api instead of using the classes directly)

X+
-Hackathon and data journalism about the European parliament 24-26 jan. Watch out the result

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: civicrm, renewMember & ubercart
May 19, 2011, 07:42:20 am
Thanks

That was my first approach --
but the problem that I was having with strictly using the api to update existing membership records is that  I need to re-code all the logic that went into the renewMembership function -- i.e. get all membership records  and if there are existing membership records determine whether this a strict renewal (easy) or upsell (change membership type within an organization)  versus creating a new record  if the membershiptype is in a different organization, handling expired memberships,  and updating  membership dates.  While the renewMembership function still doesn't have it all right (and is pretty complex with all the cases)  I wanted to make sure the ubercart extension used the same  rules for updating as the current version of civi. 

Since in principle I am now convinced that renewing multiple memberships will work though ubercart,  I'll try to rethink  renew/upsell using the api calls if that is preferable.

best,
Merlise
Merlise Clyde

xavier

  • Forum Godess / God
  • I’m (like) Lobo ;)
  • *****
  • Posts: 4453
  • Karma: 161
    • Tech To The People
  • CiviCRM version: yes probably
  • CMS version: drupal
Re: civicrm, renewMember & ubercart
May 19, 2011, 08:39:55 am
If you get an issue with not enough features on the functions exposed through the api, please start a thread on the api forum, based on your needs we might identify missing features and improve the api accordingly.

Good luck

X+
-Hackathon and data journalism about the European parliament 24-26 jan. Watch out the result

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: civicrm, renewMember & ubercart
May 24, 2011, 08:25:22 pm
I rewrote the function to create/renew/upgrade/downgrade using mostly api calls  (and added a request that perhaps it could be part of the api) 

Can some one please tell me what actions should take place with membership creation/update (beyond linking the contribution and membership records)?

Do I need to create an activity for all cases (new membership/ renewal )  or should that be added with the civicrm_memberhip_create ?  (it's not, so  I am not sure if that is a calling/params issue or a separate call is needed (I expect the latter)

Are membership log entries created with the  create function or is thate a separate function that does that?

Ditto for contributions...

Thanks in advance!
m
Merlise Clyde

Eileen

  • Forum Godess / God
  • I’m (like) Lobo ;)
  • *****
  • Posts: 4195
  • Karma: 218
    • Fuzion
Re: civicrm, renewMember & ubercart
May 24, 2011, 10:57:14 pm
Hi,

Membership log and activity entries should be created by the core code. If you are using the api & the appropriate entries aren't being created it might be a gap in the api we should look at.


NB - take a look at the new api membership feature
http://wiki.civicrm.org/confluence/display/CRMDOC40/CiviCRM+Public+APIs#CiviCRMPublicAPIs-Nested/Chainedcalls

it means you can create a contact & a membership (for example) in the same api call
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

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: civicrm, renewMember & ubercart
May 25, 2011, 06:32:48 am
Wonderful!  that sounds perfect for new contacts with the ubercart module -- I think it currently assumes that there is a contact associated with the  Drupal user

Will that allow me to  create a membership and its contriubtion in one call too?  (rather than three calls now (create membershi, create contribution, link membership + contribution)

I spent yesterday getting my production site up to 3.4.1 from 2.2.9 so will get back to the ubercart module later to see if the api calls are creating the  activities.  I also need to switch to v3 probably (the original code base was using v2, so  just started with that)

Thanks!
Merlise
Merlise Clyde

Pages: [1]
  • CiviCRM Community Forums (archive) »
  • Old sections (read-only, deprecated) »
  • Developer Discussion (Moderator: Donald Lobo) »
  • civicrm, renewMember & ubercart

This forum was archived on 2017-11-26.