You are here

public function UcAddressesAddressBook::setAddressAsDefault in Ubercart Addresses 7

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

Set an address as a default address.

@access public

Parameters

UcAddressesAddress $address: The address to set as default.

string $type: The address type to set (shipping, billing).

Return value

boolean TRUE if the address was set as default. FALSE otherwise.

File

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

Class

UcAddressesAddressBook
The address book class

Code

public function setAddressAsDefault($address, $type = 'billing') {

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

    // Address is not owned, so it can't be set as default
    // in this stage.
    return FALSE;
  }

  // Check to make sure this is one of our addresses.
  if ($address
    ->getAddressBook() !== $this) {
    return FALSE;
  }

  // Make sure the previous default address is loaded.
  $this
    ->getDefaultAddress($type);

  // Loop through all addresses to make sure no other
  // addresses are marked as default.
  foreach ($this->addresses as $aid => $addr) {
    if ($address !== $addr && $addr
      ->isDefault($type)) {
      $addr
        ->privSetUcAddressField($type, FALSE);
    }
  }

  // Set given address as the default.
  $address
    ->privSetUcAddressField($type, TRUE);
  $this->defaultAddresses[$type] = $address;
  return TRUE;
}