public function UcAddressesAddressBook::updateAddress in Ubercart Addresses 6.2
Same name and namespace in other branches
- 7 class/UcAddressesAddressBook.class.php \UcAddressesAddressBook::updateAddress()
Updates address ID in the address book.
Called by method save() in UcAddressesAddress when the address gets an ID.
@access public
Parameters
UcAddressesAddress $address: The address to reindex.
Return value
void
Throws
UcAddressesInvalidParameterException
File
- class/
UcAddressesAddressBook.class.php, line 328 - Contains the UcAddressesAddressBook class.
Class
- UcAddressesAddressBook
- The address book class
Code
public function updateAddress(UcAddressesAddress $address) {
// Check if address belongs to this address book.
if ($address
->getAddressBook() !== $this) {
throw new UcAddressesInvalidParameterException(t('Tried to update an address from an other address book'));
}
// Loop through all addresses to find out what temporary ID
// the address is known under.
foreach ($this->addresses as $aid => $addressBookAddress) {
if ($address === $addressBookAddress) {
// Update address ID.
unset($this->addresses[$aid]);
$this->addresses[$address
->getId()] = $address;
return;
}
}
// The address should have been found in the address book.
// However, sometimes it can happen that there are two address
// objects with the same ID. This can happen when serializing
// and unserializing address objects.
$this->addresses[$address
->getId()] = $address;
}