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) »
  • Get PriceSet for an Event
Pages: [1]

Author Topic: Get PriceSet for an Event  (Read 631 times)

elcongrio

  • I’m new here
  • *
  • Posts: 26
  • Karma: 0
  • CiviCRM version: 3.6.1
  • CMS version: Wordpress
  • MySQL version: 5.3
  • PHP version: 5.3.3
Get PriceSet for an Event
May 07, 2014, 09:41:59 am
Hi:

I need to get the PriceSet for an Event.
If I call the PriceSet API, I get something like this:

{
   "is_error":0,
   "version":3,
   "count":5,
   "values":[{
      "id":"1",
      "name":"default_contribution_amount",
      "title":"Contribution Amount",
      "is_active":"1",
      "extends":"2",
      "is_quick_config":"1",
      "is_reserved":"1",
      "entity":{
         "civicrm_contribution":["2"]
      }
   },
   {
      "id":"5",
      "name":"prueba_pagos",
      "title":"Prueba Pagos",
      "is_active":"1",
      "extends":"1",
      "financial_type_id":"4",
      "is_quick_config":"1",
      "is_reserved":"0",
      "entity":{
         "civicrm_event":["7"]
      }
   }]
}

What I need to know is how can I filter this call to get only the second record. I think it maybe something like:

civicrm_api('PriceSet','Get', array(
                                                        'version' => '3',
                                                        'field' => 'event_type',
                                                        'related_entity' => array('civicrm_event' => 5)
                                                        ));

But I can't get this to work.
Thanks in advance

misterpy

  • I’m new here
  • *
  • Posts: 2
  • Karma: 0
Re: Get PriceSet for an Event
June 29, 2016, 01:09:59 am
Hi there! I am also trying to find a way go get the Event Id from Price Set id.

Did you get this to work or have you found another solution?

I really appreciate more information regarding this. I've been searching about this for more than 2 days already but no avail.

Please do help!

misterpy

  • I’m new here
  • *
  • Posts: 2
  • Karma: 0
Re: Get PriceSet for an Event
July 09, 2016, 10:22:37 am
Maybe this might help somebody. I have managed to do this by using the core functionality of CiviCRM.

First would be to get the event_id and then the magic happens below:

Code: [Select]
$discountId = CRM_Core_BAO_Discount::findSet($params['event_id'], 'civicrm_event');
if ($discountId) {
$priceSetId = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_Discount', $discountId, 'price_set_id');
}
else {
$priceSetId = CRM_Price_BAO_PriceSet::getFor('civicrm_event', $params['event_id']);
}

// get price set options, - CRM-5209
if ($priceSetId) {
$setDetails = CRM_Price_BAO_PriceSet::getSetDetail($priceSetId, TRUE, TRUE);

$lowestAmount = 1000000;
foreach($setDetails as $val1) {
  foreach ($val1['fields'] as $price) {
  foreach ($price['options'] as $priceSet) {
  if($priceSet['amount'] < $lowestAmount){
  $lowestAmount = $priceSet['amount'];
  }
  }
  }
}

$params['lowest_price'] = $lowestAmount;

return civicrm_api3_create_success($params);
}else{
$params['no_priceset'] = 1;
return $params;
}

For me, this code is used to get the lowest ticket price available for an event.

Hope this helps.

Pages: [1]
  • CiviCRM Community Forums (archive) »
  • Old sections (read-only, deprecated) »
  • Developer Discussion »
  • APIs and Hooks (Moderator: Donald Lobo) »
  • Get PriceSet for an Event

This forum was archived on 2017-11-26.