Uploaded image for project: 'CiviCRM'
  1. CiviCRM
  2. CRM-15636

Using the API to create a price set for both events and contributions.

    Details

    • Type: Bug
    • Status: Done/Fixed
    • Priority: Trivial
    • Resolution: Fixed/Completed
    • Affects Version/s: 4.5.4
    • Fix Version/s: 4.6
    • Component/s: CiviCRM API
    • Labels:
      None
    • Documentation Required?:
      None

      Description

      If you create a price set using the user interface, there is a field 'Used for' that can be 'Event', 'Contribution', 'Membership' or a combination of those values. If you create a price set that is to be used for Event and Contribution, and you request this price set via the API, you get this:

      Array
      (
      [id] => 3
      [name] => Testset
      [title] => Price Set Title
      [is_active] => 1
      [extends] => Array
      (
      [0] => 1
      [1] => 2
      )
      [financial_type_id] => 1
      [is_quick_config] => 0
      [is_reserved] => 0
      [entity] => Array
      (
      )
      )

      Now if you try to create such a price set via the API, you get an error. I wrote a unit test, for which I will create a pull request in a minute. Here is the error message:

      Failure in api call for price_set create: Array to string conversion
      #0 /home/johanv/dev/drupal-7.x-dev/sites/all/modules/civicrm/packages/DB/DataObject.php(1020): PHPUnit_Util_ErrorHandler::handleError(8, 'Array to string...', '/home/johanv/de...', 1020, Array)
      #1 /home/johanv/dev/drupal-7.x-dev/sites/all/modules/civicrm/CRM/Core/DAO.php(458): DB_DataObject->insert()
      #2 /home/johanv/dev/drupal-7.x-dev/sites/all/modules/civicrm/CRM/Price/BAO/PriceSet.php(75): CRM_Core_DAO->save()
      #3 [internal function]: CRM_Price_BAO_PriceSet::create(Array)
      #4 /home/johanv/dev/drupal-7.x-dev/sites/all/modules/civicrm/api/v3/utils.php(1193): call_user_func_array(Array, Array)
      #5 /home/johanv/dev/drupal-7.x-dev/sites/all/modules/civicrm/api/v3/PriceSet.php(50): _civicrm_api3_basic_create('CRM_Price_BAO_P...', Array)
      #6 /home/johanv/dev/drupal-7.x-dev/sites/all/modules/civicrm/Civi/API/Provider/MagicFunctionProvider.php(86): civicrm_api3_price_set_create(Array)
      #7 /home/johanv/dev/drupal-7.x-dev/sites/all/modules/civicrm/Civi/API/Kernel.php(95): Civi\API\Provider\MagicFunctionProvider->invoke(Array)
      #8 /home/johanv/dev/drupal-7.x-dev/sites/all/modules/civicrm/api/api.php(25): Civi\API\Kernel->run('price_set', 'create', Array, NULL)
      #9 /home/johanv/dev/drupal-7.x-dev/sites/all/modules/civicrm/tests/phpunit/CiviTest/CiviUnitTestCase.php(812): civicrm_api('price_set', 'create', Array)
      #10 /home/johanv/dev/drupal-7.x-dev/sites/all/modules/civicrm/tests/phpunit/CiviTest/CiviUnitTestCase.php(844): CiviUnitTestCase->civicrm_api('price_set', 'create', Array)
      #11 /home/johanv/dev/drupal-7.x-dev/sites/all/modules/civicrm/tests/phpunit/CiviTest/CiviUnitTestCase.php(965): CiviUnitTestCase->callAPISuccess('price_set', 'create', Array)
      #12 /home/johanv/dev/drupal-7.x-dev/sites/all/modules/civicrm/tests/phpunit/api/v3/PriceSetTest.php(83): CiviUnitTestCase->callAPIAndDocument('price_set', 'create', Array, 'testCreatePrice...', '/home/johanv/de...')
      #13 [internal function]: api_v3_PriceSetTest->testCreatePriceSetForEventAndContribution()
      #14 /home/johanv/dev/drupal-7.x-dev/sites/all/modules/civicrm/packages/PHPUnit/Framework/TestCase.php(942): ReflectionMethod->invokeArgs(Object(api_v3_PriceSetTest), Array)
      #15 /home/johanv/dev/drupal-7.x-dev/sites/all/modules/civicrm/tests/phpunit/CiviTest/CiviUnitTestCase.php(166): PHPUnit_Framework_TestCase->runTest()
      #16 /home/johanv/dev/drupal-7.x-dev/sites/all/modules/civicrm/packages/PHPUnit/Framework/TestCase.php(804): CiviUnitTestCase->runTest()
      #17 /home/johanv/dev/drupal-7.x-dev/sites/all/modules/civicrm/packages/PHPUnit/Framework/TestResult.php(649): PHPUnit_Framework_TestCase->runBare()
      #18 /home/johanv/dev/drupal-7.x-dev/sites/all/modules/civicrm/packages/PHPUnit/Framework/TestCase.php(751): PHPUnit_Framework_TestResult->run(Object(api_v3_PriceSetTest))
      #19 /home/johanv/dev/drupal-7.x-dev/sites/all/modules/civicrm/packages/PHPUnit/Framework/TestSuite.php(772): PHPUnit_Framework_TestCase->run(Object(PHPUnit_Framework_TestResult))
      #20 /home/johanv/dev/drupal-7.x-dev/sites/all/modules/civicrm/packages/PHPUnit/Framework/TestSuite.php(745): PHPUnit_Framework_TestSuite->runTest(Object(api_v3_PriceSetTest), Object(PHPUnit_Framework_TestResult))
      #21 /home/johanv/dev/drupal-7.x-dev/sites/all/modules/civicrm/packages/PHPUnit/TextUI/TestRunner.php(325): PHPUnit_Framework_TestSuite->run(Object(PHPUnit_Framework_TestResult), '/testCreatePric...', Array, Array, false)
      #22 /home/johanv/dev/drupal-7.x-dev/sites/all/modules/civicrm/packages/PHPUnit/TextUI/Command.php(232): PHPUnit_TextUI_TestRunner->doRun(Object(PHPUnit_Framework_TestSuite), Array)
      #23 /home/johanv/dev/drupal-7.x-dev/sites/all/modules/civicrm/packages/PHPUnit/TextUI/Command.php(139): PHPUnit_TextUI_Command->run(Array, true)
      #24 /home/johanv/dev/drupal-7.x-dev/sites/all/modules/civicrm/tools/scripts/phpunit(80): PHPUnit_TextUI_Command::main()
      #25

      {main}

        Attachments

          Activity

            People

            • Assignee:
              eileen Eileen McNaughton
              Reporter:
              johanv Johan Vervloet
            • Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: