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 »
  • APIs and Hooks (Moderator: Donald Lobo) »
  • Error with API MembershipType Create and civicrm_price_field tables
Pages: [1]

Author Topic: Error with API MembershipType Create and civicrm_price_field tables  (Read 940 times)

Luciano S.

  • I post occasionally
  • **
  • Posts: 83
  • Karma: 2
  • iXiam Team Leader
  • CiviCRM version: 4.2+ / 4.3+ / 4.4+
  • CMS version: Drupal
  • MySQL version: 5.1+ / 5.5+
  • PHP version: 5.3+ / 5.4+
Error with API MembershipType Create and civicrm_price_field tables
September 06, 2012, 08:44:22 am
Hi guys,

I'm using the API v4.2 to create a MembershipType like this:

Code: [Select]
$result = civicrm_api( "MembershipType",
"create",
array ( 'version' =>'3',
'domain_id' =>'1',
'name' =>'New Membership Type',
'description' =>'New Membership Type',
'member_of_contact_id' => 1
'contribution_type_id' => 1
'period_type' =>'rolling',
'visibility' =>'Public',
'is_active' =>'1',
'duration_unit' =>'lifetime',
'duration_interval' =>'1',
'weight' => 1)
);

This works ok, and the Membership Type is created.

Then when I go to create a new membership of this Membership Type, I got these errors:

- Warning: key() expects parameter 1 to be array, null given in CRM_Member_BAO_Membership::createLineItems() (line 2806 of {drupal_path}/sites/all/modules/civicrm/CRM/Member/BAO/Membership.php).
- Notice: Undefined index: id in CRM_Member_BAO_Membership::createLineItems() (line 2807 of {drupal_path}/sites/all/modules/civicrm/CRM/Member/BAO/Membership.php).
- Warning: Invalid argument supplied for foreach() in CRM_Price_BAO_Set::processAmount() (line 595 of {drupal_path}/sites/all/modules/civicrm/CRM/Price/BAO/Set.php).
- Warning: Invalid argument supplied for foreach() in CRM_Member_Form_Membership->postProcess() (line 1498 of {drupal_path}/sites/all/modules/civicrm/CRM/Member/Form/Membership.php).


A workaround to solve this issue it's go to edit form of the Membership Type created by the API, and save it again without changing anything. The Warnings disspears after that for the Membership creation
So something it's wrong when the Membership Type is created by the API, I guessed

I've checked the source code and I realized that was something related with price sets (I'm not very familiar with Price Sets, never used them so far).
So looking at the tables related with price sets I saw that 2 records are not inserted when the MType is created by the API and are created after Saving the same Mtype in the form. Maybe this is the problem, but I'm not sure what the tables civicrm_price_field and civicrm_price_field_value are used for.
These are the records (in SQL Syntax) those are not created by the api but by the Edit Form

Code: [Select]
INSERT INTO `civicrm_price_field` (`id`, `price_set_id`, `name`, `label`, `html_type`, `is_enter_qty`, `help_pre`, `help_post`, `weight`, `is_display_amounts`, `options_per_line`, `is_active`, `is_required`, `active_on`, `expire_on`, `javascript`, `visibility_id`) VALUES
(2, 2, '3', 'Membership Amount', 'Radio', 0, NULL, NULL, 1, 0, 1, 1, 0, NULL, NULL, NULL, 1);

INSERT INTO `civicrm_price_field_value` (`id`, `price_field_id`, `name`, `label`, `description`, `amount`, `count`, `max_value`, `weight`, `membership_type_id`, `is_default`, `is_active`) VALUES
(2, 2, 'New Membership Type', 'New Membership Type', NULL, '0.00', NULL, NULL, 1, 1, 0, 1);

Any ideas are welcome
Thanks in advance!!!

Luciano S.

  • I post occasionally
  • **
  • Posts: 83
  • Karma: 2
  • iXiam Team Leader
  • CiviCRM version: 4.2+ / 4.3+ / 4.4+
  • CMS version: Drupal
  • MySQL version: 5.1+ / 5.5+
  • PHP version: 5.3+ / 5.4+
Re: Error with API MembershipType Create and civicrm_price_field tables
September 10, 2012, 09:11:10 am
I've reproduced the error in sandbox as well.
I created the Membership Type using API in ajax/doc (I paste the REST URL used to create it):

/civicrm/ajax/rest?json=1&sequential=1&debug=1&&entity=MembershipType&action=create&domain_id=1&name=New Membership Type&description=New Membership Type&member_of_contact_id=1&contribution_type_id=1&period_type=rolling&visibility=Public&is_active=1&duration_unit=lifetime&duration_interval=1&weight=1

and then when I create the Membership I got this error:

Warning: Invalid argument supplied for foreach() in CRM_Member_Form_Membership->postProcess() (line 1498 of /var/www/drupal7.civicrm.org/svn/civicrm42/CRM/Member/Form/Membership.php).

I created a bug in JIRA for this as well.
http://issues.civicrm.org/jira/browse/CRM-10796

cheers!

Pages: [1]
  • CiviCRM Community Forums (archive) »
  • Old sections (read-only, deprecated) »
  • Developer Discussion »
  • APIs and Hooks (Moderator: Donald Lobo) »
  • Error with API MembershipType Create and civicrm_price_field tables

This forum was archived on 2017-11-26.