You are here

public function UcAddressesAddressBook::setAddressOwner in Ubercart Addresses 7

Same name and namespace in other branches
  1. 6.2 class/UcAddressesAddressBook.class.php \UcAddressesAddressBook::setAddressOwner()

Sets the owner of an address if the owner was previously unknown.

This method is only used to set the owner of the address when it's currently owned by user 0. This is the case when an address is asked at registering or when the user anonymously checked out.

Should only be called by UcAddressesAddress.

@access public

Parameters

UcAddressesAddress $address: The address to change the owner for.

int $uid: The user who should be the owner of the address.

Return value

UcAddressesAddressBook The address book the address was transferred to; Or NULL if the address was already owned.

File

class/UcAddressesAddressBook.class.php, line 571
Contains the UcAddressesAddressBook class.

Class

UcAddressesAddressBook
The address book class

Code

public function setAddressOwner(UcAddressesAddress $address, $uid) {

  // Reasons to skip out early.
  if ($this
    ->isOwned()) {

    // Address is already owned.
    return;
  }
  if ($address
    ->getAddressBook() !== $this) {

    // The address does not belong to this address book.
    return $address
      ->setOwner($uid);
  }

  // Add address to user $uid address book.
  $addressBook = self::get($uid);
  $addressBook
    ->addAddress($address);

  // Remove address from this address book.
  $this
    ->removeAddressFromAddressBook($address);
  return $addressBook;
}