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) »
  • Using API to create or copy Paid Events
Pages: [1]

Author Topic: Using API to create or copy Paid Events  (Read 539 times)

edburton

  • I’m new here
  • *
  • Posts: 3
  • Karma: 0
Using API to create or copy Paid Events
February 01, 2012, 09:17:02 am
I've been using the API to create copies of an event and am dismayed to find that neither Price Sets nor Fees survive the copy :'(. Wading into the codebase I'm woefully out of my depth so me patching the API would be a long way off. Hence I'm fishing the forum to see if anyone has suggestions, ideas, code snippets etc for copying or creating Paid Events. This is on a go-live critical path so any helping hands or hacks will be gratefully received 8)

Eileen

  • Forum Godess / God
  • I’m (like) Lobo ;)
  • *****
  • Posts: 4195
  • Karma: 218
    • Fuzion
Re: Using API to create or copy Paid Events
February 01, 2012, 12:17:20 pm
Yes, this is a weakness. I think the plan is that in the medium term prices will only be stored in price sets.

However, for now, here is an example of creating an event with option group based prices. You need an option group for each event (a weakness of the fee based system)

Code: [Select]
   /*
    * Create test event
    */
   public function createTestEvent($endDate){
    $result = civicrm_api('Event','Create',array('check_permissions' => 0,
    'is_online_registration' => 1,
    'registration_start_date' => '20110101',
    'registration_end_date' => '20120101',
    'registration_link_text'=> 'register',
    'version' => 3, 'title' =>
    'test_event',
    'event_type_id' => 24,
    'contribution_type_id' => 4,
    'is_monetary' => 1,
    'start_date' => $this->eventStartDate,
    'end_date' => $endDate,
    'is_active' => 1,'payment_processor_id' => 3,
                                                 'created_id' => $this->ids['contact_id']));
    $event_id = $result['id'];
    $this->assertEqual('0',$result['is_error'],"Event Created : <pre></pre>" );
   
    $result = civicrm_api('OptionGroup','create', array('version' => 3,
    'sequential' => 1,
    'name' => 'civicrm_event.amount.' . $event_id,
    'is_reserved' => 1,
    'is_active' => 1,
    'api.OptionValue.create' => array('label' => 'workshop',
    'value'=> 35,
    'is_default' => 1,
    'is_active' => 1,
    'format.only_id' => 1)));
    civicrm_api('Event', 'Create', array('version' => 3, 'id' => $event_id, 'default_fee_id' => $result['values'][0]['api.OptionValue.create']));
    return $event_id;
    }
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]
  • CiviCRM Community Forums (archive) »
  • Old sections (read-only, deprecated) »
  • Developer Discussion »
  • APIs and Hooks (Moderator: Donald Lobo) »
  • Using API to create or copy Paid Events

This forum was archived on 2017-11-26.