Method responsible for saving (or adding) an address.
If the ID field is set, the method assums we are saving
an address.

If the ID field is not set, we assume a new address is being
created.
181378
public function doSaveAddress($data, $form)
    {
        if (!$data["ID"]) {
            $new = true;
            $address = ContactLocation::create();
        } else {
            $new = false;
            $address = ContactLocation::get()->byID($data["ID"]);
        }

        if ($address) {
            $form->saveInto($address);
            $address->write();
            $form->sessionMessage(
                _t("SilverCommerce\ContactAdmin.AddressSaved", "Address Saved"),
                ValidationResult::TYPE_GOOD
            );
        } else {
            $form->sessionMessage(
                _t("SilverCommerce\ContactAdmin.Error", "There was an error"),
                ValidationResult::TYPE_ERROR
            );
        }

        // If a new record, redirect to base, else redirect back to the edit form
        if ($new && !empty($address)) {
            return $this
                ->getOwner()
                ->redirect(
                    Controller::join_links(
                        $this->getOwner()->Link("editaddress"),
                        $address->ID
                    )
                );
        } else {
            return $this
                ->getOwner()
                ->redirectBack();
        }
    }
1025742
public synchronized void handleNodeLost(Address address) {
    Preconditions.checkNotNull(address, "address should not be null");
    mLostNodes.add(address);
    for (Runnable function : mChangeListeners) {
      function.run();
    }
  }
751429
def _store_account_address(self, address):
        
        address_key = address_prefix + utils.sha3(address)
        self.wb.put(address_key, address)
886043
def save
      response = service.send(:"#{method_prefix}_update", self.attrs)

      if response.at_xpath('//status').attr('code') == 'ok'
        # Load the ID if this was a creation
        self.id = response.at_xpath("//#{ac_obj_node_name}").attr("#{ac_obj_type}-id") if self.id.nil?
        true
      else
        save_errors(response)
        false
      end
    end
1296352
def save
      # If we have an id, just update our fields.
      return update! if id

      from_response client.post("/webhooks", {
        description: description,
        idModel: id_model,
        callbackURL: callback_url
      })
    end
1079520
function(event, address) {
        var columnModel = this.columnModel.getColumnModel(address.columnName);
        var eventType, editOptions, handler;

        if (!columnModel) {
            return;
        }

        eventType = event.type;
        editOptions = columnModel.editOptions || {};
        handler = editOptions[getEventHandlerName(eventType)];

        if (_.isFunction(handler)) {
            handler.call(event.target, event, address);
        }
    }
888043
protected function submitAddAddress()
    {
        $this->setSubmitted(null, $this->getParam());
        $this->setSubmittedJson('data');
        $this->validateComponent('address');
        $this->addAddress();
    }
902993
@UiHandler("m_addressField")
    void onAddressSelection(SelectionEvent<SuggestOracle.Suggestion> event) {

        m_controller.onAddressChange(event.getSelectedItem());
    }
1299426
function (identifier, field, values) {
            var self = this;
            return this.needByIdentifier(identifier).then(function (record) {
                return self.addFieldIfNotExistById(record.id, field, values);
            });
        }
1190447
public function ChangeSelectedAddress()
    {
        $this->SetPreventProcessStepMethodFromExecuting(true);
        // the method only works if the user is logged in
        $oUser = self::getExtranetUserProvider()->getActiveUser();
        if ($oUser->IsLoggedIn()) {
            $sNewShippingAddressId = $this->GetShippingAddressData('selectedAddressId');
            $sNewBillingAddressId = $this->GetBillingAddressData('selectedAddressId');

            if ('1' == $this->GetShipToBillingAddress()) {
                if (0 != strcmp($sNewBillingAddressId, $sNewShippingAddressId)) {
                    if (TdbDataExtranetUserAddress::FORM_DATA_NAME_BILLING == $this->AddressUsedAsPrimaryAddress()) {
                        $sNewShippingAddressId = $sNewBillingAddressId;
                    } else {
                        $sNewBillingAddressId = $sNewShippingAddressId;
                    }
                }
            } else {
                // they were different.. if they are now the same, we should set the new state
                if (0 == strcmp($sNewBillingAddressId, $sNewShippingAddressId)) {
                    $this->SetShipToBillingAddress('1');
                }
            }

            if (!empty($sNewBillingAddressId)) {
                if ('new' != $sNewBillingAddressId) {
                    $oNewBillingAdr = $oUser->SetAddressAsBillingAddress($sNewBillingAddressId);
                    if ($oNewBillingAdr) {
                        $this->SetBillingAddressData($oNewBillingAdr->sqlData);
                    } else {
                        // invalid request...
                        if (false == $this->GetBillingAddressData('selectedAddressId')) {
                            // there was nothing selected... so we get an an alternative
                            $sNewBillingAddressId = $this->GetAnotherAddressFromUser($sNewBillingAddressId, TdbDataExtranetUserAddress::FORM_DATA_NAME_BILLING);
                            $oNewBillingAdr = $oUser->SetAddressAsBillingAddress($sNewBillingAddressId);
                            if ($oNewBillingAdr) {
                                $this->SetBillingAddressData($oNewBillingAdr->sqlData);
                            } else {
                                $this->SetBillingAddressData(array('selectedAddressId' => 'new'));
                            }
                        }
                    }
                } else {
                    $this->SetBillingAddressData(array('selectedAddressId' => 'new'));
                }
            }

            if (!empty($sNewShippingAddressId)) {
                if ('new' != $sNewShippingAddressId) {
                    $oNewShippingAdr = $oUser->SetAddressAsShippingAddress($sNewShippingAddressId);
                    if ($oNewShippingAdr) {
                        $this->SetShippingAddressData($oNewShippingAdr->sqlData);
                    } else {
                        // invalid request...
                        if (false == $this->GetShippingAddressData('selectedAddressId')) {
                            // there was nothing selected... so we get an an alternative
                            $sNewShippingAddressId = $this->GetAnotherAddressFromUser($sNewBillingAddressId, TdbDataExtranetUserAddress::FORM_DATA_NAME_SHIPPING);
                            $oNewShippingAdr = $oUser->SetAddressAsShippingAddress($sNewShippingAddressId);
                            if ($oNewShippingAdr) {
                                $this->SetShippingAddressData($oNewShippingAdr->sqlData);
                            } else {
                                $this->SetShippingAddressData(array('selectedAddressId' => 'new'));
                            }
                        }
                    }
                } else {
                    $this->SetShippingAddressData(array('selectedAddressId' => 'new'));
                }
            }

            // check if shipping != billing AND ShipToBillingAddress() == '1' or the other way around. if that is the case,
            // then we need to adjust ShipToBillingAddress to match the new setting
            if (1 == $this->GetShipToBillingAddress() && $this->GetShippingAddressData('selectedAddressId') != $this->GetBillingAddressData('selectedAddressId')) {
                $this->SetShipToBillingAddress(0);
            } elseif (0 == $this->GetShipToBillingAddress() && $this->GetShippingAddressData('selectedAddressId') == $this->GetBillingAddressData('selectedAddressId')) {
                $this->SetShipToBillingAddress(1);
            }
            TShopBasket::GetInstance()->RecalculateBasket();
        }
    }
1366434
public void putCacheField()
    {
        try {
            Record record = this.getOwner();
            Object objKey = record.getHandle(DBConstants.OBJECT_ID_HANDLE);
            m_hsCache.add(objKey);
        } catch (DBException ex)    {
            ex.printStackTrace();
        }
    }
279512
private static void insertAddressUsingCallable(AddressClient client, String newAddressName)
      throws InterruptedException, ExecutionException {
    // Begin samplegen code for insertAddress().
    ProjectRegionName region = ProjectRegionName.of(PROJECT_NAME, REGION);
    Address address = Address.newBuilder().build();
    InsertAddressHttpRequest request =
        InsertAddressHttpRequest.newBuilder()
            .setRegion(region.toString())
            .setAddressResource(address)
            .build();
    ApiFuture<Operation> future = client.insertAddressCallable().futureCall(request);
    // Do something
    Operation response = future.get();

    // End samplegen code for insertAddress().
    System.out.format("Result of insert: %s\n", response.toString());
  }
351171
private void assignAddress(String addressString) throws ChannelFrameworkException, UnknownHostException {
        if (addressString == null) {
            // No address found in properties. No CFEndPoint can be created.
            throw new ChannelFrameworkException("No address available in properties.");
        }
        if ("*".equals(addressString)) {
            // TODO WAS used the node name
            this.address = InetAddress.getLocalHost();
        } else {
            this.address = InetAddress.getByName(addressString);
        }
    }
658037
public function makeItDefault()
    {
        AddressQuery::create()->filterByCustomerId($this->getCustomerId())
            ->update(array('IsDefault' => '0'));

        $this->setIsDefault(1);
        $this->save();
    }
820821
public function doSaveAddress($data, $form)
    {
        if (!$data["ID"]) {
            $address = MemberAddress::create();
        } else {
            $address = MemberAddress::get()->byID($data["ID"]);
        }

        if ($address) {
            $form->saveInto($address);
            $address->write();

            $this->owner->setSessionMessage(
                "success",
                _t("Checkout.AddressSaved", "Address Saved")
            );
        } else {
            $this->owner->setSessionMessage(
                "error",
                _t("Checkout.Error", "There was an error")
            );
        }

        return $this->owner->redirect($this->owner->Link("addresses"));
    }
374098
private void putId() {
        // note: name and info may be null
        super.put("Provider.id name", String.valueOf(name));
        super.put("Provider.id version", String.valueOf(version));
        super.put("Provider.id info", String.valueOf(info));
        super.put("Provider.id className", this.getClass().getName());
    }
435053
function addAddressBookEntry($customer_id, $address_question_arr, $make_default = false) {
    global $db;

    // debug
    $this->zcLog('addAddressBookEntry - 1', 'address to add: ' . "\n" . print_r($address_question_arr, true));

    // if address is blank, don't do any matching
    if ($address_question_arr['street_address'] == '') return false;

    // set some defaults
    $country_id = '223';
    $address_format_id = 2; //2 is the American format

    // first get the zone id's from the 2 digit iso codes
    // country first
    $sql = "SELECT countries_id, address_format_id
                FROM " . TABLE_COUNTRIES . "
                WHERE countries_iso_code_2 = :countryCode:
                OR countries_name = :countryName:
                OR countries_iso_code_2 = :countryName:
                OR countries_name = :countryCode:
                LIMIT 1";
    $sql = $db->bindVars($sql, ':countryCode:', $address_question_arr['country']['iso_code_2'], 'string');
    $sql = $db->bindVars($sql, ':countryName:', $address_question_arr['country']['title'], 'string');
    $country = $db->Execute($sql);

    // see if we found a record, if not default to American format
    if (!$country->EOF) {
      $country_id = $country->fields['countries_id'];
      $address_format_id = (int)$country->fields['address_format_id'];
    } else {
      // if defaulting to US, make sure US is valid
      $sql = "SELECT countries_id FROM " . TABLE_COUNTRIES . " WHERE countries_id = :countryId LIMIT 1";
      $sql = $db->bindVars($sql, ':countryId', $country_id, 'integer');
      $result = $db->Execute($sql);
      if ($result->EOF) {
        $this->notify('NOTIFY_HEADER_ADDRESS_BOOK_ADD_ENTRY_INVALID_ATTEMPT');
        $this->zcLog('addAddressBookEntry - 3', 'Failed to add address due to country restrictions');
        return FALSE;
      }
    }

    // see if the country code has a state
    $sql = "SELECT zone_id
                FROM " . TABLE_ZONES . "
                WHERE zone_country_id = :zoneId
                LIMIT 1";
    $sql = $db->bindVars($sql, ':zoneId', $country_id, 'integer');
    $country_zone_check = $db->Execute($sql);
    $check_zone = $country_zone_check->RecordCount();

    // now try and find the zone_id (state/province code)
    // use the country id above
    if ($check_zone) {
      $sql = "SELECT zone_id
                    FROM " . TABLE_ZONES . "
                    WHERE zone_country_id = :zoneId
                    AND (zone_code = :zoneCode
                    OR zone_name = :zoneCode )
                    LIMIT 1";
      $sql = $db->bindVars($sql, ':zoneId', $country_id, 'integer');
      $sql = $db->bindVars($sql, ':zoneCode', $address_question_arr['state'], 'string');
      $zone = $db->Execute($sql);
      if (!$zone->EOF) {
        // grab the id
        $zone_id = $zone->fields['zone_id'];
      } else {
        $zone_id = 0;
      }
    }

    // now run the insert

    // this isn't the best way to get fname/lname but it will get the majority of cases
    list($fname, $lname) = explode(' ', $address_question_arr['name']);

    $sql_data_array= array(array('fieldName'=>'entry_firstname', 'value'=>$fname, 'type'=>'string'),
                           array('fieldName'=>'entry_lastname', 'value'=>$lname, 'type'=>'string'),
                           array('fieldName'=>'entry_street_address', 'value'=>$address_question_arr['street_address'], 'type'=>'string'),
                           array('fieldName'=>'entry_postcode', 'value'=>$address_question_arr['postcode'], 'type'=>'string'),
                           array('fieldName'=>'entry_city', 'value'=>$address_question_arr['city'], 'type'=>'string'),
                           array('fieldName'=>'entry_country_id', 'value'=>$country_id, 'type'=>'integer'));
    if ($address_question_arr['company'] != '' && $address_question_arr['company'] != $address_question_arr['name']) array('fieldName'=>'entry_company', 'value'=>$address_question_arr['company'], 'type'=>'string');
    $sql_data_array[] = array('fieldName'=>'entry_gender', 'value'=>$address_question_arr['payer_gender'], 'type'=>'enum:m|f');
    $sql_data_array[] = array('fieldName'=>'entry_suburb', 'value'=>$address_question_arr['suburb'], 'type'=>'string');
    if ($zone_id > 0) {
      $sql_data_array[] = array('fieldName'=>'entry_zone_id', 'value'=>$zone_id, 'type'=>'integer');
      $sql_data_array[] = array('fieldName'=>'entry_state', 'value'=>'', 'type'=>'string');
    } else {
      $sql_data_array[] = array('fieldName'=>'entry_zone_id', 'value'=>'0', 'type'=>'integer');
      $sql_data_array[] = array('fieldName'=>'entry_state', 'value'=>$address_question_arr['state'], 'type'=>'string');
    }
    $sql_data_array[] = array('fieldName'=>'customers_id', 'value'=>$customer_id, 'type'=>'integer');
    $db->perform(TABLE_ADDRESS_BOOK, $sql_data_array);

    $new_address_book_id = $db->Insert_ID();

    $this->notify('NOTIFY_HEADER_ADDRESS_BOOK_ADD_ENTRY_DONE');

    // make default if set, update
    if ($make_default) {
      $sql_data_array = array();
      $sql_data_array[] = array('fieldName'=>'customers_default_address_id', 'value'=>$new_address_book_id, 'type'=>'integer');
      $where_clause = "customers_id = :customersID";
      $where_clause = $db->bindVars($where_clause, ':customersID', $customer_id, 'integer');
      $db->perform(TABLE_CUSTOMERS, $sql_data_array, 'update', $where_clause);
      $_SESSION['customer_default_address_id'] = $new_address_book_id;
    }

    // set the sendto
    $_SESSION['sendto'] = $new_address_book_id;

    // debug
    $this->zcLog('addAddressBookEntry - 2', 'added address #' . $new_address_book_id. "\n" . 'SESSION[sendto] is now set to ' . $_SESSION['sendto']);

    // return the address_id
    return $new_address_book_id;
  }