You are here

function _uc_addresses_db_normalize_address in Ubercart Addresses 5

Same name and namespace in other branches
  1. 5.2 uc_addresses.module \_uc_addresses_db_normalize_address()
  2. 6 uc_addresses.module \_uc_addresses_db_normalize_address()

SQL gets a little weird when comparing nulls. "value = NULL" is always false, even if the value is NULL! You have to write "value IS NULL" to get the "right" answer. Rather than changing the comparisons all over the place, we will make sure no value is null. Because address fields can be disabled, any field could be null.

Parameters

$address The address to normalize (altered in place).:

2 calls to _uc_addresses_db_normalize_address()
_uc_addresses_db_add_address in ./uc_addresses.module
Add a new address to the database table. If the address is already in the database (for this user), it is not added.
_uc_addresses_db_check_address in ./uc_addresses.module
Before adding or updating an address, check it for errors.

File

./uc_addresses.module, line 1455

Code

function _uc_addresses_db_normalize_address(&$address) {

  // Yes, the comparisons are checking for null, '', and 0. This is
  // deliberate--call me paranoid
  if (!$address->first_name) {
    $address->first_name = '';
  }
  if (!$address->last_name) {
    $address->last_name = '';
  }
  if (!$address->phone) {
    $address->phone = '';
  }
  if (!$address->company) {
    $address->company = '';
  }
  if (!$address->street1) {
    $address->street1 = '';
  }
  if (!$address->street2) {
    $address->street2 = '';
  }
  if (!$address->city) {
    $address->city = '';
  }
  if (!$address->zone) {
    $address->zone = 0;
  }
  if (!$address->postal_code) {
    $address->postal_code = '';
  }
  if (!$address->country) {
    $address->country = variable_get('uc_store_country', 840);
  }
  if (!$address->address_name) {
    $address->address_name = '';
  }
}