$params[$entity][$this->getFieldMetadata($mappedField['name'])['name']] = $this->getTransformedFieldValue($mappedField['name'], $fieldValue);
}
}
- return $params;
+ return $this->removeEmptyValues($params);
+ }
+
+ protected function removeEmptyValues($array) {
+ foreach ($array as $key => $value) {
+ if (is_array($value)) {
+ $array[$key] = $this->removeEmptyValues($value);
+ }
+ elseif ($value === '') {
+ unset($array[$key]);
+ }
+ }
+ return $array;
}
/**
['name' => ''],
['name' => 'trxn_id'],
['name' => 'contribution_campaign_id'],
+ ['name' => 'contribution_contact_id'],
];
// First we try to create without total_amount mapped.
// It will fail in create mode as total_amount is required for create.
$this->importCSV('contributions.csv', $fieldMappings, ['onDuplicate' => CRM_Import_Parser::DUPLICATE_SKIP]);
$row = $this->getDataSource()->getRows()[0];
- $this->assertEquals('IMPORTED', $row[10]);
+ $this->assertEquals('IMPORTED', $row[11]);
$contribution = Contribution::get()->addSelect('source', 'id')->execute()->first();
$this->assertEmpty($contribution['source']);
$this->importCSV('contributions.csv', $fieldMappings, ['onDuplicate' => CRM_Import_Parser::DUPLICATE_UPDATE]);
$row = $this->getDataSource()->getRows()[0];
- $this->assertEquals('IMPORTED', $row[10]);
+ $this->assertEquals('IMPORTED', $row[11]);
$contribution = Contribution::get()->addSelect('source', 'id')->execute()->first();
$this->assertEquals('Call him back', $contribution['source']);
}
-External Identifier,Total Amount,Receive Date,Financial Type,Soft Credit to,Source,Note,Transaction ID,Campaign ID
-bob,65,2008-09-20,Donation,mum@example.com,Word of mouth,Call him back,999,1
+External Identifier,Total Amount,Receive Date,Financial Type,Soft Credit to,Source,Note,Transaction ID,Campaign ID,Blank column
+bob,65,2008-09-20,Donation,mum@example.com,Word of mouth,Call him back,999,1,