Details
-
Type:
Bug
-
Status: Done/Fixed
-
Priority:
Minor
-
Resolution: Fixed/Completed
-
Affects Version/s: 4.2.2
-
Fix Version/s: 4.5
-
Component/s: CiviContribute
-
Labels:None
Description
When importing contributions, any contribution with total amount $0 gives an error, "Mandatory key(s) missing from params array: total_amount".
Yet entering an contribution amount of $0 is allowed when manually entering contributions.
The function that throws this error is civicrm/api/v3/utils.php in function civicrm_api3_verify_mandatory(), about line 125, where it uses the php function empty() to evaluate whether the key exists or not.
PHP empty() returns true when the value =
I don't know how civicrm_api3_verify_mandatory() is used, but generally for numerical and money fields, a field with value zero is not considered empty. Particularly for contributions, a $0 contribution may be entered for a wide variety of reasons and it is perfectly valid.
So I don't know if it is best to address the problem civicrm_api3_verify_mandatory() (my suggestion is to add || (empty($params[$key]) && $params[$key]!=0)) in line 125 and similarly for the similar line involving $subkey at about line 112) or to back up to the import routine itself and not use civicrm_api3_verify_mandatory for the total amount field.
Either way, it should be possible to import a contribution with total amount set to $0.