Commit 6a58120a authored by parvez's avatar parvez
Browse files

Merge pull request #10 from rajeshrhino/master

Postcode anywhere fix for House number and county
parents a055900f 91a9a2d0
......@@ -107,6 +107,10 @@ class CRM_Civicrmpostcodelookup_Page_PostcodeAnywhere extends CRM_Core_Page {
}
private static function getAddressByMoniker($moniker) {
// Get state/county
$states = CRM_Core_PseudoConstant::stateProvince();
$querystring = self::getPostcodeAnywhereCredentials(2);
$querystring = $querystring . "&Id=" . urlencode($moniker);
......@@ -116,19 +120,26 @@ class CRM_Civicrmpostcodelookup_Page_PostcodeAnywhere extends CRM_Core_Page {
$address = array('id' => $moniker);
$addressItemRow = (array) $simpleXMLData->Rows;
$addressItem = (array) $addressItemRow['Row'];
$addressLineArray[] = $addressItem['@attributes']['Company'];
$addressLineArray[] = $addressItem['@attributes']['DeliveryPointSuffix'];
$addressLineArray[] = $addressItem['@attributes']['BuildingNumber'];
$addressLineArray[] = $addressItem['@attributes']['PrimaryStreet'];
$addressLineArray = array_filter($addressLineArray);
$address["street"] = @implode(', ', $addressLineArray);
$address["street_address"] = @implode(', ', $addressLineArray);
$address["locality"] = $addressItem['@attributes']['SecondaryStreet'];
$address["supplemental_address_1"] = $addressItem['@attributes']['SecondaryStreet'];
$address["supplemental_address_2"] = $addressItem['@attributes']['DependentLocality'];
$address["town"] = $addressItem['@attributes']['PostTown'];
$address["postcode"] = $addressItem['@attributes']['Postcode'];
$address["state_province_id"] = '';
if ($stateId = array_search($addressItem['@attributes']['County'], $states)) {
$address["state_province_id"] = $stateId;
}
return $address;
}
}
......@@ -181,6 +181,7 @@ function setAddressFields(address, blockNo, blockPrefix) {
var AddstreetAddressElement = '#' + blockPrefix + 'supplemental_address_1-'+ blockNo;
var AddstreetAddressElement1 = '#' + blockPrefix + 'supplemental_address_2-'+ blockNo;
var cityElement = '#' + blockPrefix + 'city-'+ blockNo;
var countyElement = '#address_'+ blockNo +'_state_province_id';
var allFields = {
postcode: postcodeElement,
......@@ -206,12 +207,16 @@ function setAddressFields(address, blockNo, blockPrefix) {
cj(AddstreetAddressElement1).val('');
cj(cityElement).val('');
cj(postcodeElement).val('');
cj(countyElement).val('');
cj(streetAddressElement).val(address.street_address);
cj(AddstreetAddressElement).val(address.supplemental_address_1);
cj(AddstreetAddressElement1).val(address.supplemental_address_2);
cj(cityElement).val(address.town);
cj(postcodeElement).val(address.postcode);
if(typeof(address.state_province_id) != "undefined" && address.state_province_id !== null) {
cj(countyElement).val(address.state_province_id).trigger("change");
}
}
}
</script>
......
......@@ -139,6 +139,7 @@ function setAddressFields(address, blockNo) {
var AddstreetAddressElement = '#address_'+ blockNo +'_supplemental_address_1';
var AddstreetAddressElement1 = '#address_'+ blockNo +'_supplemental_address_2';
var cityElement = '#address_'+ blockNo +'_city';
var countyElement = '#address_'+ blockNo +'_state_province_id';
var allFields = {
postcode: postcodeElement,
......@@ -164,12 +165,16 @@ function setAddressFields(address, blockNo) {
cj(AddstreetAddressElement1).val('');
cj(cityElement).val('');
cj(postcodeElement).val('');
cj(countyElement).val('');
cj(streetAddressElement).val(address.street_address);
cj(AddstreetAddressElement).val(address.supplemental_address_1);
cj(AddstreetAddressElement1).val(address.supplemental_address_2);
cj(cityElement).val(address.town);
cj(postcodeElement).val(address.postcode);
if(typeof(address.state_province_id) != "undefined" && address.state_province_id !== null) {
cj(countyElement).val(address.state_province_id).trigger("change");
}
}
}
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment