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) »
  • LineItem in API
Pages: [1]

Author Topic: LineItem in API  (Read 858 times)

Thoudahl

  • I’m new here
  • *
  • Posts: 25
  • Karma: 1
  • CiviCRM version: 4.1.1
  • CMS version: Joomla 1.7.1
  • MySQL version: 5.5.15
  • PHP version: 5.3.8
LineItem in API
June 11, 2012, 08:35:36 am
Hi there!

I am in the process of implementing an extention to CiviCRM there is working with eventregistrations.
I simply can't find anywhere in the API where I can access LineItems for a Participant / Event, and I have not been totally able to figure out how to write my own api extention to give to you guys where I safely access LineItem via BAO/DAO.

Am I missing something, or can I have a hint on how to access a LineItem via BAO/DAO so I can create a robust extention without storing data from the _post hook for LineItem to use when the BuildForm hook is fired for CRM_Event_Form_Registration_ThankYou?

Thanks.

xavier

  • Forum Godess / God
  • I’m (like) Lobo ;)
  • *****
  • Posts: 4453
  • Karma: 161
    • Tech To The People
  • CiviCRM version: yes probably
  • CMS version: drupal
Re: LineItem in API
June 11, 2012, 10:42:29 am
Hi,

It doesn't seem to be implemented yet. If you want to contribute it to the core, it's adding a api/v3/lineItem.php

You can take as an example api/v3/Email.php  for instance. To test it works the way you want, you write tests in tests/phpunit/api/v3 (ou need to install from svn and configure to get the phpunit working)

That would be great if you could write the api & the tests, ask us if you need help or more info.

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

Eileen

  • Forum Godess / God
  • I’m (like) Lobo ;)
  • *****
  • Posts: 4195
  • Karma: 218
    • Fuzion
Re: LineItem in API
June 11, 2012, 02:38:11 pm
If you are going to have a go read this first

http://wiki.civicrm.org/confluence/display/CRM/API+Architecture+Standards

NB - I did add a report for pricesets into 4.2 but there is no default report as I think it needs some improvements still
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

Thoudahl

  • I’m new here
  • *
  • Posts: 25
  • Karma: 1
  • CiviCRM version: 4.1.1
  • CMS version: Joomla 1.7.1
  • MySQL version: 5.5.15
  • PHP version: 5.3.8
Re: LineItem in API
July 31, 2012, 07:31:19 am
Hi Eileen & Xavier

Thanks for trying to getting me started.
Unfortunately i'm a bit heavy bottomed on this...

I have copied the api/v3/Email.php and named it LineItem.php
I have created the function

Code: [Select]
function _civicrm_api3_LineItem_get_spec(&$params) {
  // TODO a 'clever' default should be introduced
  $params['is_primary']['api.default'] = 0;
}
In order to ommit creating a test so far (i found somewhere that this is the 'getfields function')

I have ofcause change the require once line to "require_once 'CRM/Price/BAO/LineItem.php';"

But I still get the same result:
"API (LineItem,get) does not exist (join the API team and implement it!)"

It seems to me that I will need to implement price_list aswell in order to start testing.
So far I only need to get the get up and working in order to procees with my work. Can anyone of you help me?

Eileen

  • Forum Godess / God
  • I’m (like) Lobo ;)
  • *****
  • Posts: 4195
  • Karma: 218
    • Fuzion
Re: LineItem in API
July 31, 2012, 12:17:33 pm
So,

If the function you are after is 'get' you will need

function _civicrm_api3_lineitem_get(&$params) {

}

The get_spec tweaks the fields in the get function- it's the places to specific default values for fields & which fields are required & to document 'special' fields
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

Thoudahl

  • I’m new here
  • *
  • Posts: 25
  • Karma: 1
  • CiviCRM version: 4.1.1
  • CMS version: Joomla 1.7.1
  • MySQL version: 5.5.15
  • PHP version: 5.3.8
Re: LineItem in API
August 01, 2012, 04:58:50 am
Hi Eileen,

I got it so far.

I have attached the code i'v made so far. Unfortunately I still get the ""is_error":1,
   "error_message":"API (LineItem,get) does not exist (join the API team and implement it!)""

Can you tell me what i'm doing wrong or what i', missing

Thank you a lot for all your help - it is very appreciated :)

best,
Christian

xavier

  • Forum Godess / God
  • I’m (like) Lobo ;)
  • *****
  • Posts: 4453
  • Karma: 161
    • Tech To The People
  • CiviCRM version: yes probably
  • CMS version: drupal
Re: LineItem in API
August 01, 2012, 05:13:18 am
PHP function names are case insensitive, we did use the _ convention to split words

function _civicrm_api3_line_item_get

check out PledgePayment.php for example

You are almost there!

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

Thoudahl

  • I’m new here
  • *
  • Posts: 25
  • Karma: 1
  • CiviCRM version: 4.1.1
  • CMS version: Joomla 1.7.1
  • MySQL version: 5.5.15
  • PHP version: 5.3.8
Re: LineItem in API
August 01, 2012, 06:06:43 am
You guys are amazing!

I got it to work :) Almost...

I read the retrive documentation that says:

Code: [Select]
   * Takes a bunch of params that are needed to match certain criteria and
   * retrieves the relevant objects.  Typically, the valid params are only
   * price_field_id.  This is the inverse function of create.  It also
   * stores all of the retrieved values in the default array.

But I only get one LineItem when I do this:

Code: [Select]
function civicrm_api3_line_item_get($params) {


  $str = "";
  $dao = CRM_Price_BAO_LineItem::retrieve($params, $str);
  _civicrm_api3_object_to_array($dao, $result[$dao->id]);

  return civicrm_api3_create_success($result, $params, 'line_item', 'get', $dao);
}

params being the standard from the API browser:
Quote
array (version=3','option' =>'com_civicrm', 'task' =>'civicrm/ajax/rest', 'sequential' =>'1')

Any sugestions?

Thoudahl

  • I’m new here
  • *
  • Posts: 25
  • Karma: 1
  • CiviCRM version: 4.1.1
  • CMS version: Joomla 1.7.1
  • MySQL version: 5.5.15
  • PHP version: 5.3.8
Re: LineItem in API
August 01, 2012, 06:54:10 am
Horray!
Got it to work.

As soon as i get some more time I will finish up this but right now I got it to work.
If anyone need it feel free to use it :)

And again X+ & Eileen: Tons of thanks!

Pages: [1]
  • CiviCRM Community Forums (archive) »
  • Old sections (read-only, deprecated) »
  • Developer Discussion »
  • APIs and Hooks (Moderator: Donald Lobo) »
  • LineItem in API

This forum was archived on 2017-11-26.