CRM-20297 Fatal error viewing a contribution having a line item with no price field

    Details

    • Type: Bug
    • Status: Done/Fixed
    • Priority: Critical
    • Resolution: Fixed/Completed
    • Affects Version/s: 4.7.16
    • Fix Version/s: 4.7.20
    • Component/s: CiviContribute
    • Labels:
    • Versioning Impact:
      Patch (backwards-compatible bug fixes)
    • Documentation Required?:
      None
    • Funding Source:
      Contributed Code
    • Verified?:
      Yes

      Description

      To replicate:
      Using the API, create a contribution with `skipLineItem` = 1, and let's say it creates contribution ID 12345. Next, create a line item with the following basic params:

      $result = civicrm_api3('LineItem', 'create', array(
        'entity_id' => 12345,
        'qty' => 1,
        'unit_price' => 100,
        'line_total' => 100,
        'entity_table' => "civicrm_contribution",
        'financial_type_id' => "Donation",
      ));
      

      Everything should go great. However, when you try to view the contribution on the web, you'll get a fatal error:

      Sorry but we are not able to provide this at the moment.
      Expected one PriceSet but found 9

      Return to home page.

      The page mistakenly assumes that the line item should have a price set ID, so it attempts a PriceSet.getsingle API call without specifying the ID, yielding the error.

        Attachments

          Activity

          [CRM-20297] Fatal error viewing a contribution having a line item with no price field
          Andrew Hunt added a comment -

          Is it gauche to verify my own issue? I'm assuming not.

          Andrew Hunt added a comment -

          (Tim Otten I'm not sure where to assign things like this, so reassign as needed.)

          Working on the assumption that the API spec is correct and you aren't required to have a price field on a line item, this change dodges the error by not trying to get a price set if there is none.

          https://github.com/civicrm/civicrm-core/pull/10012

          While I was at it, I noticed that the display of the line item had the price field preceding it, separated by a hyphen. I fixed that to be an en dash and to only display when there is a price field. I then got carried away and replaced all of this sort of incorrect hyphen usage in the templates/CRM/Contribute directory.

          Alan Dixon added a comment -

          Related issue in webform civicrm is here:

          https://www.drupal.org/node/2840851

          I think this issue and PR can proceed independently.

            People

            • Assignee:
              Tim Otten
              Reporter:
              Andrew Hunt

              Dates

              • Created:
                Updated:
                Resolved: