diff --git a/CRM/Utils/DeprecatedUtils.php b/CRM/Utils/DeprecatedUtils.php index 934a175d1f9e..d720fb1ffec9 100644 --- a/CRM/Utils/DeprecatedUtils.php +++ b/CRM/Utils/DeprecatedUtils.php @@ -484,7 +484,9 @@ function _civicrm_api3_deprecated_check_contact_dedupe($params) { if ($field == NULL || $field === '') { continue; } - if (is_array($field)) { + // CRM-17040, Considering only primary contact when importing contributions. So contribution inserts into primary contact + // instead of soft credit contact. + if (is_array($field) && $key != "soft_credit") { foreach ($field as $value) { $break = FALSE; if (is_array($value)) { diff --git a/tests/phpunit/CRM/Contribute/Import/Parser/ContributionTest.php b/tests/phpunit/CRM/Contribute/Import/Parser/ContributionTest.php new file mode 100644 index 000000000000..303bdd11138e --- /dev/null +++ b/tests/phpunit/CRM/Contribute/Import/Parser/ContributionTest.php @@ -0,0 +1,85 @@ + 'Contact', + 'last_name' => 'One', + 'external_identifier' => 'ext-1', + 'contact_type' => 'Individual', + ); + $contact2Params = array( + 'first_name' => 'Contact', + 'last_name' => 'Two', + 'external_identifier' => 'ext-2', + 'contact_type' => 'Individual', + ); + $contact1Id = $this->individualCreate($contact1Params); + $contact2Id = $this->individualCreate($contact2Params); + $values = array( + "total_amount" => 10, + "financial_type" => "Donation", + "external_identifier" => "ext-1", + "soft_credit" => "ext-2", + ); + $mapperSoftCredit = array(NULL, NULL, NULL, "external_identifier"); + $mapperSoftCreditType = array(NULL, NULL, NULL, "1"); + $this->runImport($values, CRM_Import_Parser::DUPLICATE_UPDATE, CRM_Contribute_Import_Parser::SOFT_CREDIT, $mapperSoftCredit, NULL, $mapperSoftCreditType); + $params = array( + "contact_id" => $contact1Id, + ); + $values = array(); + $contributionsOfMainContact = CRM_Contribute_BAO_Contribution::retrieve($params, $values, $values); + $params["contact_id"] = $contact2Id; + $contributionsOfSoftContact = CRM_Contribute_BAO_ContributionSoft::retrieve($params, $values); + $this->assertEquals(1, count($contributionsOfMainContact), 'Contribution not added for primary contact'); + $this->assertEquals(1, count($contributionsOfSoftContact), 'Soft Contribution not added for secondary contact'); + } + /** + * Run the import parser. + * + * @param array $originalValues + * + * @param int $onDuplicateAction + * @param int $expectedResult + * @param array|null $mapperSoftCredit + * @param array|null $mapperPhoneType + * @param array|null $mapperSoftCreditType + * @param array|null $fields + * Array of field names. Will be calculated from $originalValues if not passed in. + */ + protected function runImport($originalValues, $onDuplicateAction, $expectedResult, $mapperSoftCredit = NULL, $mapperPhoneType = NULL, $mapperSoftCreditType = NULL, $fields = NULL) { + if (!$fields) { + $fields = array_keys($originalValues); + } + $values = array_values($originalValues); + $parser = new CRM_Contribute_Import_Parser_Contribution($fields, $mapperSoftCredit, $mapperPhoneType, $mapperSoftCreditType); + $parser->_contactType = 'Individual'; + $parser->init(); + $this->assertEquals($expectedResult, $parser->import($onDuplicateAction, $values), 'Return code from parser import was not as expected'); + } + +}