'contact_id',
'is_billing',
'display',
- 'master_id',
])) {
continue;
}
* Fix the shared address if address is already shared
* or if address will be shared with itself.
*
+ * Add in the details from the master address.
+ *
* @param array $params
* Associated array of address params.
*/
$params['master_id'] = NULL;
CRM_Core_Session::setStatus(ts("You can't connect an address to itself"), '', 'warning');
}
+ if ($params['master_id']) {
+ $masterAddressParams = Address::get(FALSE)
+ ->addWhere('id', '=', $params['master_id'])->execute()->first();
+ unset($masterAddressParams['id'], $masterAddressParams['is_primary'], $masterAddressParams['is_billing'], $masterAddressParams['contact_id']);
+ $params += $masterAddressParams;
+ }
}
/**
$this->assertEquals(['Parent'], $contact['contact_sub_type']);
}
+ /**
+ * @throws \CRM_Core_Exception
+ */
+ public function testImportMasterAddress(): void {
+ $this->individualCreate(['external_identifier' => 'billy', 'first_name' => 'William'], 'billy-the-kid');
+ $address = $this->callAPISuccess('Address', 'create', ['street_address' => 'out yonder', 'contact_id' => $this->ids['Contact']['billy-the-kid']]);
+ $this->individualCreate(['external_identifier' => '', 'first_name' => 'Daddy Bill'], 'billy-the-dad');
+ $this->runImport([
+ 'id' => $this->ids['Contact']['billy-the-dad'],
+ 'master_id' => $address['id'],
+ ], CRM_Import_Parser::DUPLICATE_UPDATE, CRM_Import_Parser::VALID);
+ $newAddress = $this->callAPISuccessGetSingle('Address', ['contact_id' => $this->ids['Contact']['billy-the-dad']]);
+ $this->assertEquals($address['id'], $newAddress['master_id']);
+ $this->assertEquals('out yonder', $newAddress['street_address']);
+ }
+
/**
* Test updating an existing contact with external_identifier match but
* subtype mismatch.