Version Notes
First stable release
Download this release
Release Info
Developer | UberCX |
Extension | UberCX_AVS |
Version | 1.0.1 |
Comparing to | |
See all releases |
Version 1.0.1
- app/code/community/Ubercx/Addressvalidator/Helper/Data.php +46 -0
- app/code/community/Ubercx/Addressvalidator/Model/Observer.php +256 -0
- app/code/community/Ubercx/Addressvalidator/etc/adminhtml.xml +44 -0
- app/code/community/Ubercx/Addressvalidator/etc/config.xml +76 -0
- app/code/community/Ubercx/Addressvalidator/etc/system.xml +73 -0
- app/design/frontend/base/default/layout/ubercx/addressvalidator.xml +29 -0
- app/design/frontend/base/default/template/ubercx/addressvalidator/response.phtml +34 -0
- app/etc/modules/Ubercx_Addressvalidator.xml +30 -0
- package.xml +61 -0
- skin/frontend/base/default/js/ubercx/response_handler.js +224 -0
app/code/community/Ubercx/Addressvalidator/Helper/Data.php
ADDED
@@ -0,0 +1,46 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
/*
|
4 |
+
* Magento
|
5 |
+
*
|
6 |
+
* NOTICE OF LICENSE
|
7 |
+
*
|
8 |
+
* This source file is subject to the GNU General Public License
|
9 |
+
* that is bundled with this package in the file LICENSE.txt.
|
10 |
+
* It is also available through the world-wide-web at this URL:
|
11 |
+
* http://opensource.org/licenses/gpl-license
|
12 |
+
* If you did not receive a copy of the license and are unable to
|
13 |
+
* obtain it through the world-wide-web, please send an email
|
14 |
+
* to license@refersion.com so we can send you a copy immediately.
|
15 |
+
*
|
16 |
+
* @category UBERCX
|
17 |
+
* @package Ubercx_Addressvalidator
|
18 |
+
* @copyright Copyright (c) 2015 Ubercx, Inc.
|
19 |
+
* @author Ubercx Developer <ubercx_nospam@jframeworks.com>
|
20 |
+
* @license http://opensource.org/licenses/gpl-license GNU General Public License
|
21 |
+
*/
|
22 |
+
class Ubercx_Addressvalidator_Helper_Data extends Mage_Core_Helper_Abstract {
|
23 |
+
/**
|
24 |
+
* Check if module is set enabled
|
25 |
+
* @return boolean
|
26 |
+
*/
|
27 |
+
public function isEnable() {
|
28 |
+
return Mage::getStoreConfig('addressvalidator/addressvalidator_settings/addressvalidator_active');
|
29 |
+
}
|
30 |
+
|
31 |
+
/**
|
32 |
+
* get value for api user key
|
33 |
+
* @return string
|
34 |
+
*/
|
35 |
+
public function getApiKey() {
|
36 |
+
Mage::getStoreConfig('addressvalidator/addressvalidator_settings/addressvalidator_user_key');
|
37 |
+
}
|
38 |
+
|
39 |
+
/**
|
40 |
+
* get value for api url
|
41 |
+
* @return string
|
42 |
+
*/
|
43 |
+
public function getApiUrl() {
|
44 |
+
Mage::getStoreConfig('addressvalidator/ubercx_api_url');
|
45 |
+
}
|
46 |
+
}
|
app/code/community/Ubercx/Addressvalidator/Model/Observer.php
ADDED
@@ -0,0 +1,256 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
/*
|
4 |
+
* Magento
|
5 |
+
*
|
6 |
+
* NOTICE OF LICENSE
|
7 |
+
*
|
8 |
+
* This source file is subject to the GNU General Public License
|
9 |
+
* that is bundled with this package in the file LICENSE.txt.
|
10 |
+
* It is also available through the world-wide-web at this URL:
|
11 |
+
* http://opensource.org/licenses/gpl-license
|
12 |
+
* If you did not receive a copy of the license and are unable to
|
13 |
+
* obtain it through the world-wide-web, please send an email
|
14 |
+
* to license@refersion.com so we can send you a copy immediately.
|
15 |
+
*
|
16 |
+
* @category UBERCX
|
17 |
+
* @package Ubercx_Addressvalidator
|
18 |
+
* @copyright Copyright (c) 2015 Ubercx, Inc.
|
19 |
+
* @author Ubercx Developer <ubercx_nospam@jframeworks.com>
|
20 |
+
* @license http://opensource.org/licenses/gpl-license GNU General Public License
|
21 |
+
*/
|
22 |
+
|
23 |
+
class Ubercx_Addressvalidator_Model_Observer extends Mage_Core_Model_Abstract {
|
24 |
+
const UBERCX_ADDR_DOMAIN = 'ubercx-addr-val';
|
25 |
+
/**
|
26 |
+
* Validate address using Ubercx API, rewrite response if suggestions available
|
27 |
+
*
|
28 |
+
* @param Varien_Event_Observer $observer
|
29 |
+
* @return Varien_Event_Observer $observer
|
30 |
+
*/
|
31 |
+
public function validateAddress($observer) {
|
32 |
+
$helper = Mage::helper('addressvalidator');
|
33 |
+
$request = Mage::app()->getRequest();
|
34 |
+
$event = $observer->getEvent();
|
35 |
+
$controller = $event->getControllerAction();
|
36 |
+
$ob_response = $controller->getResponse();
|
37 |
+
$store = Mage::app()->getStore();
|
38 |
+
$storeId = $store->getId();
|
39 |
+
$quote = Mage::getSingleton('checkout/session')->getQuote();
|
40 |
+
$address_type = '';
|
41 |
+
//check if module is actiave to use
|
42 |
+
if(!$helper->isEnable()){
|
43 |
+
return $observer;
|
44 |
+
}
|
45 |
+
|
46 |
+
if ($event->getName() == 'controller_action_postdispatch_checkout_onepage_saveBilling') {
|
47 |
+
$address = $quote->getBillingAddress();
|
48 |
+
} else {
|
49 |
+
$address = $quote->getShippingAddress();
|
50 |
+
}
|
51 |
+
|
52 |
+
if ($address->getAddressType()=='billing'){
|
53 |
+
$billing = $request->getParam('billing');
|
54 |
+
if (!$billing['use_for_shipping']){
|
55 |
+
return $observer;
|
56 |
+
}
|
57 |
+
}
|
58 |
+
|
59 |
+
//ok if we have a 'which_to_use' it means the user has selected one - which means we validated already
|
60 |
+
//Lets see if they have changed any data, if they have we need to revalidate!!!
|
61 |
+
if(isset($_POST['ubercx_which_to_use'])){
|
62 |
+
|
63 |
+
//ok lets see if any of the fields are dirty
|
64 |
+
//which one did they select
|
65 |
+
$selected = $_POST['ubercx_which_to_use'];
|
66 |
+
|
67 |
+
// create the hidden id used in the html so we can check if it is dirty
|
68 |
+
if($selected != 'orig'){
|
69 |
+
$selected = "corrected_" . $selected;
|
70 |
+
}
|
71 |
+
|
72 |
+
if ($address->getAddressType()=='billing'){
|
73 |
+
//collect the fields from the hidden fields in post
|
74 |
+
$post_addr1 = $_POST['ubercx_addr_' . $selected . '_addr1'];
|
75 |
+
$post_addr2 = $_POST['ubercx_addr_' . $selected . '_addr2'];
|
76 |
+
$post_city = $_POST['ubercx_addr_' . $selected . '_city'];
|
77 |
+
$post_state = $_POST['ubercx_addr_' . $selected . '_state'];
|
78 |
+
$post_zip = $_POST['ubercx_addr_' . $selected . '_zip'];
|
79 |
+
}
|
80 |
+
else{
|
81 |
+
//collect the fields from the hidden fields in post
|
82 |
+
$post_addr1 = $_POST['ubercx_ship_addr_' . $selected . '_addr1'];
|
83 |
+
$post_addr2 = $_POST['ubercx_ship_addr_' . $selected . '_addr2'];
|
84 |
+
$post_city = $_POST['ubercx_ship_addr_' . $selected . '_city'];
|
85 |
+
$post_state = $_POST['ubercx_ship_addr_' . $selected . '_state'];
|
86 |
+
$post_zip = $_POST['ubercx_ship_addr_' . $selected . '_zip'];
|
87 |
+
}
|
88 |
+
|
89 |
+
|
90 |
+
|
91 |
+
//Now compare them to the form to see if it is dirty
|
92 |
+
//Billing or shipping addr?
|
93 |
+
$dirty = false;
|
94 |
+
|
95 |
+
($address->getStreet(1) == $post_addr1) ? $dirty=$dirty : $dirty=true;
|
96 |
+
($address->getStreet(2) == $post_addr2) ? $dirty=$dirty : $dirty=true;
|
97 |
+
($address->getCity() == $post_city) ? $dirty=$dirty : $dirty=true;
|
98 |
+
if($selected != 'orig'){
|
99 |
+
$region = Mage::getModel('directory/region')->loadByCode($post_state, 'US');
|
100 |
+
$post_state = $region->getName();
|
101 |
+
}
|
102 |
+
($address->getRegion() == $post_state) ? $dirty=$dirty : $dirty=true;
|
103 |
+
($address->getPostcode() == $post_zip) ? $dirty=$dirty : $dirty=true;
|
104 |
+
($address->getCountry() == 'US') ? $dirty=$dirty : $dirty=true;
|
105 |
+
|
106 |
+
//echo $address->getStreet(1) .'=='. $post_addr1.'<br>'.$address->getStreet(2) .'=='. $post_addr2.'<br>'.$address->getCity() .'=='. $post_city.'<br>'.$address->getRegion() .'=='. $post_state.'<br>'.$address->getPostcode() .'=='. $post_zip.'<br>'.$address->getCountry() .'== US';exit;;
|
107 |
+
//if clean then lets just return the data and we are good to go
|
108 |
+
if(!$dirty){
|
109 |
+
//TODO for now we return nothing so the order doesnt process
|
110 |
+
//faking error on clean!
|
111 |
+
return $observer;
|
112 |
+
}
|
113 |
+
}
|
114 |
+
|
115 |
+
//so either it is dirty or it is the first time thru - either way validate the address!
|
116 |
+
//now check if the user opted to use the corrected addr
|
117 |
+
|
118 |
+
//get the user key
|
119 |
+
$user_key = Mage::getStoreConfig('addressvalidator/addressvalidator_settings/addressvalidator_user_key');;
|
120 |
+
|
121 |
+
$first_name = $address->getFirstname();
|
122 |
+
$last_name = $address->getLastname();
|
123 |
+
$address_1 = $address->getStreet(1);
|
124 |
+
$address_2 = $address->getStreet(2);
|
125 |
+
$city = $address->getCity();
|
126 |
+
$state = $address->getRegion();
|
127 |
+
$zip = $address->getPostcode();
|
128 |
+
$country = $address->getCountry();
|
129 |
+
|
130 |
+
//ok now lets call our API
|
131 |
+
$api_url = Mage::getStoreConfig('addressvalidator/ubercx_api_url');
|
132 |
+
|
133 |
+
$requestId = 'Magento_' . time();
|
134 |
+
|
135 |
+
$url = $api_url.'?request_id='.$requestId.'&street='.urlencode($address_1).'&secondary='.urlencode($address_2).'&state='.urlencode($state).'&city='.urlencode($city).'&zipcode='.urlencode($zip);
|
136 |
+
|
137 |
+
// Start cURL
|
138 |
+
$curl = curl_init();
|
139 |
+
// Headers
|
140 |
+
$headers = array();
|
141 |
+
$headers[] = 'user_key:'.$user_key;
|
142 |
+
//$headers[] = 'Accept: application/json';
|
143 |
+
curl_setopt( $curl, CURLOPT_URL, $url );
|
144 |
+
curl_setopt( $curl, CURLOPT_RETURNTRANSFER, true );
|
145 |
+
curl_setopt( $curl, CURLOPT_FOLLOWLOCATION, true );
|
146 |
+
curl_setopt( $curl, CURLOPT_HTTPHEADER, $headers );
|
147 |
+
curl_setopt( $curl, CURLOPT_SSL_VERIFYPEER, false );
|
148 |
+
curl_setopt( $curl, CURLOPT_HEADER, false);
|
149 |
+
|
150 |
+
// Get response
|
151 |
+
$response = curl_exec($curl);
|
152 |
+
|
153 |
+
// Get HTTP status code
|
154 |
+
$status = curl_getinfo($curl, CURLINFO_HTTP_CODE);
|
155 |
+
//TODO put status check for "200".
|
156 |
+
// Close cURL
|
157 |
+
curl_close($curl);
|
158 |
+
|
159 |
+
// Return response from server
|
160 |
+
if($response!=''){
|
161 |
+
$response = json_decode($response);
|
162 |
+
} else {
|
163 |
+
return $observer;
|
164 |
+
}
|
165 |
+
|
166 |
+
$transient = array();
|
167 |
+
$transient['orig'] = array();
|
168 |
+
$transient['orig']['addr1'] = $address->getStreet(1);
|
169 |
+
$transient['orig']['addr2'] = $address->getStreet(2);
|
170 |
+
$transient['orig']['city'] = $address->getCity();
|
171 |
+
$transient['orig']['state'] = $address->getRegion();
|
172 |
+
$transient['orig']['region_id'] = $address->getRegionId();
|
173 |
+
$transient['orig']['zip'] = $address->getPostcode();
|
174 |
+
|
175 |
+
if(is_object($response) && isset( $response->header) && isset( $response->header->status) && $response->header->status == 'SUCCESS'){
|
176 |
+
if(isset($response->addressRecord[0]) && isset($response->addressRecord[0]->addressSummary) && isset($response->addressRecord[0]->addressSummary->matchCode)){
|
177 |
+
switch($response->addressRecord[0]->addressSummary->matchCode){
|
178 |
+
case 'AVS_01':
|
179 |
+
if( $response->addressRecord[0]->address[0]->zipCode != $zip){
|
180 |
+
//Mage::getSingleton('core/session')->addError('There is a problem with your zip code, please check');
|
181 |
+
//loop thru the matching addrs
|
182 |
+
$transient['corrected'] = array();
|
183 |
+
|
184 |
+
for($i=0; $i<count($response->addressRecord[0]->address); $i++){
|
185 |
+
|
186 |
+
//save on typing store in temp!!!!
|
187 |
+
$temp = $response->addressRecord[0]->address[$i];
|
188 |
+
$region = Mage::getModel('directory/region')->loadByCode($temp->state, 'US');
|
189 |
+
$state_id = $region->getId();
|
190 |
+
$transient['corrected'][$i]['addr1'] = is_null($temp->addressLine1) ? "" : $temp->addressLine1 ;
|
191 |
+
$transient['corrected'][$i]['addr2'] = is_null($temp->addressLine2) ? "" : $temp->addressLine2 ;
|
192 |
+
$transient['corrected'][$i]['city'] = is_null($temp->city) ? "" : $temp->city ;
|
193 |
+
$transient['corrected'][$i]['state'] = is_null($temp->state) ? "" : $temp->state;
|
194 |
+
$transient['corrected'][$i]['region_id'] = is_null($state_id) ? "" : $state_id;
|
195 |
+
$transient['corrected'][$i]['zip'] = is_null($temp->zipCode) ? "" : $temp->zipCode;
|
196 |
+
}
|
197 |
+
$result['validate'] = true;
|
198 |
+
$result['error'] = true;
|
199 |
+
break;
|
200 |
+
}
|
201 |
+
else{
|
202 |
+
return $observer;
|
203 |
+
}
|
204 |
+
break;
|
205 |
+
case 'AVS_02':
|
206 |
+
//OK we should get a bunch of returned addr's - lets
|
207 |
+
//add them to the transient
|
208 |
+
//Mage::getSingleton('core/session')->addError('There appears to be an error in your address');
|
209 |
+
|
210 |
+
//loop thru the matching addrs
|
211 |
+
$transient['corrected'] = array();
|
212 |
+
|
213 |
+
for($i=0; $i<count($response->addressRecord[0]->address); $i++){
|
214 |
+
|
215 |
+
//save on typing store in temp!!!!
|
216 |
+
$temp = $response->addressRecord[0]->address[$i];
|
217 |
+
$region = Mage::getModel('directory/region')->loadByCode($temp->state, 'US');
|
218 |
+
$state_id = $region->getId();
|
219 |
+
$transient['corrected'][$i]['addr1'] = is_null($temp->addressLine1) ? "" : $temp->addressLine1 ;
|
220 |
+
$transient['corrected'][$i]['addr2'] = is_null($temp->addressLine2) ? "" : $temp->addressLine2 ;
|
221 |
+
$transient['corrected'][$i]['city'] = is_null($temp->city) ? "" : $temp->city ;
|
222 |
+
$transient['corrected'][$i]['state'] = is_null($temp->state) ? "" : $temp->state;
|
223 |
+
$transient['corrected'][$i]['region_id'] = is_null($state_id) ? "" : $state_id;
|
224 |
+
$transient['corrected'][$i]['zip'] = is_null($temp->zipCode) ? "" : $temp->zipCode;
|
225 |
+
}
|
226 |
+
$result['validate'] = true;
|
227 |
+
$result['error'] = true;
|
228 |
+
break;
|
229 |
+
case 'AVS_03':
|
230 |
+
//we just show the original
|
231 |
+
//but it is invalid!!!! Need to make sure the user corrects it
|
232 |
+
//Mage::getSingleton('core/session')->addError('There is a problem with your address - please check below');
|
233 |
+
$result['validate'] = true;
|
234 |
+
$result['error'] = true;
|
235 |
+
break;
|
236 |
+
default:
|
237 |
+
$result['validate'] = false;
|
238 |
+
$result['error'] = false;
|
239 |
+
}
|
240 |
+
$result['data'] = $transient;
|
241 |
+
$result['message'] = $response->addressRecord[0]->addressSummary->message;
|
242 |
+
|
243 |
+
$ob_response->setBody(Mage::helper('core')->jsonEncode($result));
|
244 |
+
$observer->setResult($result);
|
245 |
+
return $observer;
|
246 |
+
|
247 |
+
}
|
248 |
+
else{
|
249 |
+
return $observer;
|
250 |
+
}
|
251 |
+
}
|
252 |
+
else{
|
253 |
+
return $observer;
|
254 |
+
}
|
255 |
+
}
|
256 |
+
}
|
app/code/community/Ubercx/Addressvalidator/etc/adminhtml.xml
ADDED
@@ -0,0 +1,44 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?xml version="1.0"?>
|
2 |
+
<!--
|
3 |
+
/*
|
4 |
+
* Magento
|
5 |
+
*
|
6 |
+
* NOTICE OF LICENSE
|
7 |
+
*
|
8 |
+
* This source file is subject to the GNU General Public License
|
9 |
+
* that is bundled with this package in the file LICENSE.txt.
|
10 |
+
* It is also available through the world-wide-web at this URL:
|
11 |
+
* http://opensource.org/licenses/gpl-license
|
12 |
+
* If you did not receive a copy of the license and are unable to
|
13 |
+
* obtain it through the world-wide-web, please send an email
|
14 |
+
* to license@refersion.com so we can send you a copy immediately.
|
15 |
+
*
|
16 |
+
* @category UBERCX
|
17 |
+
* @package Ubercx_Addressvalidator
|
18 |
+
* @copyright Copyright (c) 2015 Ubercx, Inc.
|
19 |
+
* @author Ubercx Developer <ubercx_nospam@jframeworks.com>
|
20 |
+
* @license http://opensource.org/licenses/gpl-license GNU General Public License
|
21 |
+
*/
|
22 |
+
-->
|
23 |
+
<config>
|
24 |
+
<acl>
|
25 |
+
<resources>
|
26 |
+
<admin>
|
27 |
+
<children>
|
28 |
+
<system>
|
29 |
+
<children>
|
30 |
+
<config>
|
31 |
+
<children>
|
32 |
+
<addressvalidator translate="title" module="addressvalidator">
|
33 |
+
<title>Uctracker Settings Section</title>
|
34 |
+
<sort_order>1</sort_order>
|
35 |
+
</addressvalidator>
|
36 |
+
</children>
|
37 |
+
</config>
|
38 |
+
</children>
|
39 |
+
</system>
|
40 |
+
</children>
|
41 |
+
</admin>
|
42 |
+
</resources>
|
43 |
+
</acl>
|
44 |
+
</config>
|
app/code/community/Ubercx/Addressvalidator/etc/config.xml
ADDED
@@ -0,0 +1,76 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?xml version="1.0"?>
|
2 |
+
<!--
|
3 |
+
/*
|
4 |
+
* Magento
|
5 |
+
*
|
6 |
+
* NOTICE OF LICENSE
|
7 |
+
*
|
8 |
+
* This source file is subject to the GNU General Public License
|
9 |
+
* that is bundled with this package in the file LICENSE.txt.
|
10 |
+
* It is also available through the world-wide-web at this URL:
|
11 |
+
* http://opensource.org/licenses/gpl-license
|
12 |
+
* If you did not receive a copy of the license and are unable to
|
13 |
+
* obtain it through the world-wide-web, please send an email
|
14 |
+
* to license@refersion.com so we can send you a copy immediately.
|
15 |
+
*
|
16 |
+
* @category UBERCX
|
17 |
+
* @package Ubercx_Addressvalidator
|
18 |
+
* @copyright Copyright (c) 2015 Ubercx, Inc.
|
19 |
+
* @author Ubercx Developer <ubercx_nospam@jframeworks.com>
|
20 |
+
* @license http://opensource.org/licenses/gpl-license GNU General Public License
|
21 |
+
*/
|
22 |
+
-->
|
23 |
+
<config>
|
24 |
+
<modules>
|
25 |
+
<Ubercx_Addressvalidator>
|
26 |
+
<version>1.0.1</version>
|
27 |
+
</Ubercx_Addressvalidator>
|
28 |
+
</modules>
|
29 |
+
<frontend>
|
30 |
+
<events>
|
31 |
+
<controller_action_postdispatch_checkout_onepage_saveBilling>
|
32 |
+
<observers>
|
33 |
+
<addressvalidator_checkaddress>
|
34 |
+
<class>ubercx_addressvalidator/observer</class>
|
35 |
+
<method>validateAddress</method>
|
36 |
+
</addressvalidator_checkaddress>
|
37 |
+
</observers>
|
38 |
+
</controller_action_postdispatch_checkout_onepage_saveBilling>
|
39 |
+
<controller_action_postdispatch_checkout_onepage_saveShipping>
|
40 |
+
<observers>
|
41 |
+
<addressvalidator_checkaddress>
|
42 |
+
<class>ubercx_addressvalidator/observer</class>
|
43 |
+
<method>validateAddress</method>
|
44 |
+
</addressvalidator_checkaddress>
|
45 |
+
</observers>
|
46 |
+
</controller_action_postdispatch_checkout_onepage_saveShipping>
|
47 |
+
</events>
|
48 |
+
<layout>
|
49 |
+
<updates>
|
50 |
+
<ubercx_addressvalidator>
|
51 |
+
<file>ubercx/addressvalidator.xml</file>
|
52 |
+
</ubercx_addressvalidator>
|
53 |
+
</updates>
|
54 |
+
</layout>
|
55 |
+
</frontend>
|
56 |
+
<global>
|
57 |
+
<models>
|
58 |
+
<ubercx_addressvalidator>
|
59 |
+
<class>Ubercx_Addressvalidator_Model</class>
|
60 |
+
</ubercx_addressvalidator>
|
61 |
+
</models>
|
62 |
+
<helpers>
|
63 |
+
<ubercx_addressvalidator>
|
64 |
+
<class>Ubercx_Addressvalidator_Helper</class>
|
65 |
+
</ubercx_addressvalidator>
|
66 |
+
<addressvalidator>
|
67 |
+
<class>Ubercx_Addressvalidator_Helper</class>
|
68 |
+
</addressvalidator>
|
69 |
+
</helpers>
|
70 |
+
</global>
|
71 |
+
<default>
|
72 |
+
<addressvalidator>
|
73 |
+
<ubercx_api_url><![CDATA[https://api.ubercx.io/avs/v1/validateAddress]]></ubercx_api_url>
|
74 |
+
</addressvalidator>
|
75 |
+
</default>
|
76 |
+
</config>
|
app/code/community/Ubercx/Addressvalidator/etc/system.xml
ADDED
@@ -0,0 +1,73 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?xml version="1.0"?>
|
2 |
+
<!--
|
3 |
+
/*
|
4 |
+
* Magento
|
5 |
+
*
|
6 |
+
* NOTICE OF LICENSE
|
7 |
+
*
|
8 |
+
* This source file is subject to the GNU General Public License
|
9 |
+
* that is bundled with this package in the file LICENSE.txt.
|
10 |
+
* It is also available through the world-wide-web at this URL:
|
11 |
+
* http://opensource.org/licenses/gpl-license
|
12 |
+
* If you did not receive a copy of the license and are unable to
|
13 |
+
* obtain it through the world-wide-web, please send an email
|
14 |
+
* to license@refersion.com so we can send you a copy immediately.
|
15 |
+
*
|
16 |
+
* @category UBERCX
|
17 |
+
* @package Ubercx_Addressvalidator
|
18 |
+
* @copyright Copyright (c) 2015 Ubercx, Inc.
|
19 |
+
* @author Ubercx Developer <ubercx_nospam@jframeworks.com>
|
20 |
+
* @license http://opensource.org/licenses/gpl-license GNU General Public License
|
21 |
+
*/
|
22 |
+
-->
|
23 |
+
<config>
|
24 |
+
<tabs>
|
25 |
+
<ubercx translate="label" module="addressvalidator">
|
26 |
+
<label>UberCX Plugins</label>
|
27 |
+
<sort_order>301</sort_order>
|
28 |
+
</ubercx>
|
29 |
+
</tabs>
|
30 |
+
<sections>
|
31 |
+
<addressvalidator translate="label" module="addressvalidator">
|
32 |
+
<label>Address Validation Settings</label>
|
33 |
+
<tab>ubercx_addressvalidator</tab>
|
34 |
+
<frontend_type>text</frontend_type>
|
35 |
+
<sort_order>2</sort_order>
|
36 |
+
<show_in_default>1</show_in_default>
|
37 |
+
<show_in_website>1</show_in_website>
|
38 |
+
<show_in_store>1</show_in_store>
|
39 |
+
<tab>ubercx</tab>
|
40 |
+
<groups>
|
41 |
+
<addressvalidator_settings translate="label">
|
42 |
+
<label>UberCX Address Validator Settings</label>
|
43 |
+
<frontend_type>text</frontend_type>
|
44 |
+
<sort_order>1</sort_order>
|
45 |
+
<show_in_default>1</show_in_default>
|
46 |
+
<show_in_website>1</show_in_website>
|
47 |
+
<show_in_store>1</show_in_store>
|
48 |
+
<comment><![CDATA[This plugin allows address validation.It connects with ubercx API, which responds in JSON payload. Please visit this <a href="https://ubercx.io/plugins">link</a> to detail documentation about plugins and recipes.]]></comment>
|
49 |
+
<fields>
|
50 |
+
<addressvalidator_user_key translate="label">
|
51 |
+
<label>User Key</label>
|
52 |
+
<frontend_type>text</frontend_type>
|
53 |
+
<sort_order>1</sort_order>
|
54 |
+
<show_in_default>1</show_in_default>
|
55 |
+
<show_in_website>0</show_in_website>
|
56 |
+
<show_in_store>0</show_in_store>
|
57 |
+
<comment><![CDATA[<a href="https://ubercx.io/signup" target="_blank">Get your User Key</a>]]></comment>
|
58 |
+
</addressvalidator_user_key>
|
59 |
+
<addressvalidator_active translate="label">
|
60 |
+
<label>Enabled</label>
|
61 |
+
<frontend_type>select</frontend_type>
|
62 |
+
<source_model>adminhtml/system_config_source_yesno</source_model>
|
63 |
+
<sort_order>3</sort_order>
|
64 |
+
<show_in_default>1</show_in_default>
|
65 |
+
<show_in_website>0</show_in_website>
|
66 |
+
<show_in_store>0</show_in_store>
|
67 |
+
</addressvalidator_active>
|
68 |
+
</fields>
|
69 |
+
</addressvalidator_settings>
|
70 |
+
</groups>
|
71 |
+
</addressvalidator>
|
72 |
+
</sections>
|
73 |
+
</config>
|
app/design/frontend/base/default/layout/ubercx/addressvalidator.xml
ADDED
@@ -0,0 +1,29 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?xml version="1.0"?>
|
2 |
+
<!--
|
3 |
+
/*
|
4 |
+
* Magento
|
5 |
+
*
|
6 |
+
* NOTICE OF LICENSE
|
7 |
+
*
|
8 |
+
* This source file is subject to the GNU General Public License
|
9 |
+
* that is bundled with this package in the file LICENSE.txt.
|
10 |
+
* It is also available through the world-wide-web at this URL:
|
11 |
+
* http://opensource.org/licenses/gpl-license
|
12 |
+
* If you did not receive a copy of the license and are unable to
|
13 |
+
* obtain it through the world-wide-web, please send an email
|
14 |
+
* to license@refersion.com so we can send you a copy immediately.
|
15 |
+
*
|
16 |
+
* @category UBERCX
|
17 |
+
* @package Ubercx_Addressvalidator
|
18 |
+
* @copyright Copyright (c) 2015 Ubercx, Inc.
|
19 |
+
* @author Ubercx Developer <ubercx_nospam@jframeworks.com>
|
20 |
+
* @license http://opensource.org/licenses/gpl-license GNU General Public License
|
21 |
+
*/
|
22 |
+
-->
|
23 |
+
<layout version="0.1.0">
|
24 |
+
<checkout_onepage_index>
|
25 |
+
<reference name="before_body_end">
|
26 |
+
<block type="core/template" name="addressvalidator.response" template ="ubercx/addressvalidator/response.phtml" />
|
27 |
+
</reference>
|
28 |
+
</checkout_onepage_index>
|
29 |
+
</layout>
|
app/design/frontend/base/default/template/ubercx/addressvalidator/response.phtml
ADDED
@@ -0,0 +1,34 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
/*
|
3 |
+
* Magento
|
4 |
+
*
|
5 |
+
* NOTICE OF LICENSE
|
6 |
+
*
|
7 |
+
* This source file is subject to the GNU General Public License
|
8 |
+
* that is bundled with this package in the file LICENSE.txt.
|
9 |
+
* It is also available through the world-wide-web at this URL:
|
10 |
+
* http://opensource.org/licenses/gpl-license
|
11 |
+
* If you did not receive a copy of the license and are unable to
|
12 |
+
* obtain it through the world-wide-web, please send an email
|
13 |
+
* to license@refersion.com so we can send you a copy immediately.
|
14 |
+
*
|
15 |
+
* @category UBERCX
|
16 |
+
* @package Ubercx_Addressvalidator
|
17 |
+
* @copyright Copyright (c) 2015 Ubercx, Inc.
|
18 |
+
* @author Ubercx Developer <ubercx_nospam@jframeworks.com>
|
19 |
+
* @license http://opensource.org/licenses/gpl-license GNU General Public License
|
20 |
+
*/
|
21 |
+
|
22 |
+
$storeId = Mage::app()->getStore()->getId();
|
23 |
+
|
24 |
+
?>
|
25 |
+
<script type="text/javascript" >
|
26 |
+
var html = '<div id="ubercx_addr_correction" class="" style="display: none;"><ul class="messages"><li class="error-msg"><ul><li><span>There appears to be a problem with the address. Please correct or select one below.</span></li></ul></li></ul><div id="ubercx_orig_addr"><div id="ubercx_addr_radio" class="ubercx-addr-radio"></div><div style="display: none;" id="ubercx_orig_placeholder"></div></div></div>';
|
27 |
+
|
28 |
+
var html_ship = '<div id="ubercx_ship_addr_correction" class="" style="display: none;"><ul class="messages"><li class="error-msg"><ul><li><span>There appears to be a problem with the address. Please correct or select one below.</span></li></ul></li></ul><div id="ubercx_ship_orig_addr"><div id="ubercx_ship_addr_radio" class="ubercx-addr-radio"></div><div style="display: none;" id="ubercx_ship_orig_placeholder"></div></div></div>';
|
29 |
+
|
30 |
+
$('co-billing-form').innerHTML = html+$('co-billing-form').innerHTML;
|
31 |
+
$('co-shipping-form').innerHTML = html_ship+$('co-shipping-form').innerHTML;
|
32 |
+
</script>
|
33 |
+
<script src="<?php echo $this->getSkinUrl('js/ubercx/response_handler.js') ?>"></script>
|
34 |
+
|
app/etc/modules/Ubercx_Addressvalidator.xml
ADDED
@@ -0,0 +1,30 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?xml version="1.0"?>
|
2 |
+
<!--
|
3 |
+
/*
|
4 |
+
* Magento
|
5 |
+
*
|
6 |
+
* NOTICE OF LICENSE
|
7 |
+
*
|
8 |
+
* This source file is subject to the GNU General Public License
|
9 |
+
* that is bundled with this package in the file LICENSE.txt.
|
10 |
+
* It is also available through the world-wide-web at this URL:
|
11 |
+
* http://opensource.org/licenses/gpl-license
|
12 |
+
* If you did not receive a copy of the license and are unable to
|
13 |
+
* obtain it through the world-wide-web, please send an email
|
14 |
+
* to license@refersion.com so we can send you a copy immediately.
|
15 |
+
*
|
16 |
+
* @category UBERCX
|
17 |
+
* @package Ubercx_Addressvalidator
|
18 |
+
* @copyright Copyright (c) 2015 Ubercx, Inc.
|
19 |
+
* @author Ubercx Developer <ubercx_nospam@jframeworks.com>
|
20 |
+
* @license http://opensource.org/licenses/gpl-license GNU General Public License
|
21 |
+
*/
|
22 |
+
-->
|
23 |
+
<config>
|
24 |
+
<modules>
|
25 |
+
<Ubercx_Addressvalidator>
|
26 |
+
<active>true</active>
|
27 |
+
<codePool>community</codePool>
|
28 |
+
</Ubercx_Addressvalidator>
|
29 |
+
</modules>
|
30 |
+
</config>
|
package.xml
ADDED
@@ -0,0 +1,61 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?xml version="1.0"?>
|
2 |
+
<package>
|
3 |
+
<name>UberCX_AVS</name>
|
4 |
+
<version>1.0.1</version>
|
5 |
+
<stability>stable</stability>
|
6 |
+
<license uri="http://opensource.org/licenses/gpl-license">GNU General Public License</license>
|
7 |
+
<channel>community</channel>
|
8 |
+
<extends/>
|
9 |
+
<summary>Address validater, validates address from USA</summary>
|
10 |
+
<description>Address validater, validates address from USA, and provide correct address as suggestion. </description>
|
11 |
+
<notes>First stable release</notes>
|
12 |
+
<authors><author><name>UberCX</name><user>UberCX</user><email>support@ubercx.io</email></author></authors>
|
13 |
+
<date>2015-09-16</date>
|
14 |
+
<time>06:14:23</time>
|
15 |
+
<contents>
|
16 |
+
<target name="magecommunity">
|
17 |
+
<dir name="Ubercx">
|
18 |
+
<dir name="Addressvalidator">
|
19 |
+
<dir name="Helper"><file name="Data.php" hash="e2208c32f13bd9d9877e4964bd6286cc"/></dir>
|
20 |
+
<dir name="Model"><file name="Observer.php" hash="0b42264e5e81c3a018bd4abcf3108326"/></dir>
|
21 |
+
<dir name="etc"><file name="adminhtml.xml" hash="4cb243feddb112f72df7b87c4c3cdd74"/>
|
22 |
+
<file name="config.xml" hash="47cfe4b52c6eeb92f5b11a0c69659feb"/>
|
23 |
+
<file name="system.xml" hash="f009266afb65bb05032c1672549e9af8"/>
|
24 |
+
</dir>
|
25 |
+
</dir>
|
26 |
+
</dir>
|
27 |
+
</target>
|
28 |
+
<target name="magedesign">
|
29 |
+
<dir name="frontend">
|
30 |
+
<dir name="base">
|
31 |
+
<dir name="default">
|
32 |
+
<dir name="layout">
|
33 |
+
<dir name="ubercx"><file name="addressvalidator.xml" hash="8b8c2f2e50dcea0ed3dbe3fabe4ca668"/></dir>
|
34 |
+
</dir>
|
35 |
+
<dir name="template">
|
36 |
+
<dir name="ubercx">
|
37 |
+
<dir name="addressvalidator"><file name="response.phtml" hash="3dc79ad5891001ab256c975be62d106c"/></dir>
|
38 |
+
</dir>
|
39 |
+
</dir>
|
40 |
+
</dir>
|
41 |
+
</dir>
|
42 |
+
</dir>
|
43 |
+
</target>
|
44 |
+
<target name="mageskin">
|
45 |
+
<dir name="frontend">
|
46 |
+
<dir name="base">
|
47 |
+
<dir name="default">
|
48 |
+
<dir name="js">
|
49 |
+
<dir name="ubercx"><file name="response_handler.js" hash="44df81791bd93eb4147bff874fef90e4"/></dir>
|
50 |
+
</dir>
|
51 |
+
</dir>
|
52 |
+
</dir>
|
53 |
+
</dir>
|
54 |
+
</target>
|
55 |
+
<target name="mageetc">
|
56 |
+
<dir name="modules"><file name="Ubercx_Addressvalidator.xml" hash="eb8a4036f116f346e5b8bcfc789bebd3"/></dir>
|
57 |
+
</target>
|
58 |
+
</contents>
|
59 |
+
<compatible/>
|
60 |
+
<dependencies><required><php><min>5.2.0</min><max>6.0.0</max></php></required></dependencies>
|
61 |
+
</package>
|
skin/frontend/base/default/js/ubercx/response_handler.js
ADDED
@@ -0,0 +1,224 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
/*
|
2 |
+
* Magento
|
3 |
+
*
|
4 |
+
* NOTICE OF LICENSE
|
5 |
+
*
|
6 |
+
* This source file is subject to the GNU General Public License
|
7 |
+
* that is bundled with this package in the file LICENSE.txt.
|
8 |
+
* It is also available through the world-wide-web at this URL:
|
9 |
+
* http://opensource.org/licenses/gpl-license
|
10 |
+
* If you did not receive a copy of the license and are unable to
|
11 |
+
* obtain it through the world-wide-web, please send an email
|
12 |
+
* to license@refersion.com so we can send you a copy immediately.
|
13 |
+
*
|
14 |
+
* @category UBERCX
|
15 |
+
* @package Ubercx_Addressvalidator
|
16 |
+
* @copyright Copyright (c) 2015 Ubercx, Inc.
|
17 |
+
* @author Ubercx Developer <ubercx_nospam@jframeworks.com>
|
18 |
+
* @license http://opensource.org/licenses/gpl-license GNU General Public License
|
19 |
+
*/
|
20 |
+
if (window.shipping){
|
21 |
+
|
22 |
+
//replace the nextStep method in the Billing prototype
|
23 |
+
var replaceBillingNextStepObj = {
|
24 |
+
nextStep: function (transport) {
|
25 |
+
if (transport && transport.responseText) {
|
26 |
+
try {
|
27 |
+
response = eval('(' + transport.responseText + ')');
|
28 |
+
}
|
29 |
+
catch (e) {
|
30 |
+
response = {};
|
31 |
+
}
|
32 |
+
}
|
33 |
+
if (response && response.validate) {}
|
34 |
+
if (!response.error) {
|
35 |
+
} else {
|
36 |
+
|
37 |
+
//clear out any previous data in our error area
|
38 |
+
$('ubercx_addr_radio').innerHTML = '';
|
39 |
+
//first the original
|
40 |
+
//radio button
|
41 |
+
addr = ((response.data.orig.addr1 =="") ? "" : response.data.orig.addr1 + ", ");
|
42 |
+
addr += ((response.data.orig.addr2 =="") ? "" : response.data.orig.addr2 + ", ");
|
43 |
+
addr += ((response.data.orig.city =="") ? "" : response.data.orig.city + ", ");
|
44 |
+
addr += ((response.data.orig.state =="") ? "" : response.data.orig.state + ", ");
|
45 |
+
addr += ((response.data.orig.zip =="") ? "" : response.data.orig.zip);
|
46 |
+
|
47 |
+
$('ubercx_addr_radio').innerHTML = $('ubercx_addr_radio').innerHTML+'<div class="ubercx-addr-radio"><input type="radio" name="ubercx_which_to_use" id="ubercx_radio_orig" onclick="ubercx_radio_changed(this);" value="orig" checked><label for="ubercx_radio_orig"><b> Use Original: </b>' + addr + '</label></div>';
|
48 |
+
|
49 |
+
//The hidden fields that get posted back to our plugin
|
50 |
+
$('ubercx_addr_radio').innerHTML = $('ubercx_addr_radio').innerHTML+"<div style='display: hidden;'><input type='hidden' name='ubercx_addr_orig_addr1' id='ubercx_addr_orig_addr1' value='" + response.data.orig.addr1 + "'><input type='hidden' name='ubercx_addr_orig_addr2' id='ubercx_addr_orig_addr2' value='" + response.data.orig.addr2 + "'><input type='hidden' name='ubercx_addr_orig_city' id='ubercx_addr_orig_city' value='" + response.data.orig.city + "'><input type='hidden' name='ubercx_addr_orig_state' id='ubercx_addr_orig_state' value='" + response.data.orig.state + "'><input type='hidden' name='ubercx_addr_orig_region_id' id='ubercx_addr_orig_region_id' value='" + response.data.orig.region_id + "'><input type='hidden' name='ubercx_addr_orig_zip' id='ubercx_addr_orig_zip' value='" + response.data.orig.zip + "'></div>";
|
51 |
+
|
52 |
+
//do we have any corrected addresses?
|
53 |
+
if( typeof(response.data.corrected) !== 'undefined' && response.data.corrected.length > 0){
|
54 |
+
for (var i = 0; i < response.data.corrected.length; i++) {
|
55 |
+
|
56 |
+
addr = ((response.data.corrected[i].addr1 =="") ? "" : response.data.corrected[i].addr1 + ", ");
|
57 |
+
addr += ((response.data.corrected[i].addr2 =="") ? "" : response.data.corrected[i].addr2 + ", ");
|
58 |
+
addr += ((response.data.corrected[i].city =="") ? "" : response.data.corrected[i].city + ", ");
|
59 |
+
addr += ((response.data.corrected[i].state =="") ? "" : response.data.corrected[i].state + ", ");
|
60 |
+
addr += ((response.data.corrected[i].zip =="") ? "" : response.data.corrected[i].zip);
|
61 |
+
|
62 |
+
$('ubercx_addr_radio').innerHTML = $('ubercx_addr_radio').innerHTML+'<div class="ubercx-addr-radio"><input type="radio" name="ubercx_which_to_use" id="ubercx_radio_' + i + '" value="' + i + '" onclick="ubercx_radio_changed(this);"><label for="ubercx_radio_' + i + '"><b> Suggestion: </b>' + addr + '</label></div>';
|
63 |
+
|
64 |
+
//The hidden fields that get posted back to our plugin
|
65 |
+
|
66 |
+
$('ubercx_addr_radio').innerHTML = $('ubercx_addr_radio').innerHTML+"<div style='display: hidden;'><input type='hidden' name='ubercx_addr_corrected_" + i + "_addr1' id='ubercx_addr_corrected_" + i + "_addr1' value='" + response.data.corrected[i].addr1 + "'><input type='hidden' name='ubercx_addr_corrected_" + i + "_addr2' id='ubercx_addr_corrected_" + i + "_addr2' value='" + response.data.corrected[i].addr2 + "'><input type='hidden' name='ubercx_addr_corrected_" + i + "_city' id='ubercx_addr_corrected_" + i + "_city' value='" + response.data.corrected[i].city + "'><input type='hidden' name='ubercx_addr_corrected_" + i + "_state' id='ubercx_addr_corrected_" + i + "_state' value='" + response.data.corrected[i].state + "'><input type='hidden' name='ubercx_addr_corrected_" + i + "_region_id' id='ubercx_addr_corrected_" + i + "_region_id' value='" + response.data.corrected[i].region_id + "'><input type='hidden' name='ubercx_addr_corrected_" + i + "_zip' id='ubercx_addr_corrected_" + i + "_zip' value='" + response.data.corrected[i].zip + "'></div>";
|
67 |
+
}
|
68 |
+
}
|
69 |
+
$('ubercx_addr_radio').innerHTML = $('ubercx_addr_radio').innerHTML+'<div style="text-align:right"><a href="javascript:clear_validations(\'\')">Clear Results</a></div>';
|
70 |
+
//alert('test');alert($('ubercx_addr_radio').innerHTML);
|
71 |
+
//un-hide the display
|
72 |
+
$('ubercx_addr_correction').show();
|
73 |
+
$('ubercx_addr_correction').scrollTo();
|
74 |
+
}
|
75 |
+
|
76 |
+
checkout.setStepResponse(response);
|
77 |
+
}
|
78 |
+
};
|
79 |
+
Billing.addMethods(replaceBillingNextStepObj);
|
80 |
+
|
81 |
+
|
82 |
+
//replace the nextStep method in the Shipping prototype
|
83 |
+
var replaceShippingNextStepObj = {
|
84 |
+
nextStep: function (transport) {
|
85 |
+
if (transport && transport.responseText) {
|
86 |
+
try {
|
87 |
+
response = eval('(' + transport.responseText + ')');
|
88 |
+
}
|
89 |
+
catch (e) {
|
90 |
+
response = {};
|
91 |
+
}
|
92 |
+
}
|
93 |
+
if (response && response.validate) {}
|
94 |
+
|
95 |
+
if (!response.error) {
|
96 |
+
/*if (typeof response.data == 'string') {
|
97 |
+
addressValidator.validateAddress('co-shipping-form', response.message, response.data);
|
98 |
+
}*/
|
99 |
+
} else {
|
100 |
+
//clear out any previous data in our error area
|
101 |
+
$('ubercx_ship_addr_radio').innerHTML = '';
|
102 |
+
//first the original
|
103 |
+
//radio button
|
104 |
+
addr = ((response.data.orig.addr1 =="") ? "" : response.data.orig.addr1 + ", ");
|
105 |
+
addr += ((response.data.orig.addr2 =="") ? "" : response.data.orig.addr2 + ", ");
|
106 |
+
addr += ((response.data.orig.city =="") ? "" : response.data.orig.city + ", ");
|
107 |
+
addr += ((response.data.orig.state =="") ? "" : response.data.orig.state + ", ");
|
108 |
+
addr += ((response.data.orig.zip =="") ? "" : response.data.orig.zip);
|
109 |
+
|
110 |
+
$('ubercx_ship_addr_radio').innerHTML = $('ubercx_ship_addr_radio').innerHTML+'<div class="ubercx-addr-radio"><input type="radio" name="ubercx_which_to_use" id="ubercx_ship_radio_orig" onclick="ubercx_radio_ship_changed(this);" value="orig" checked><label for="ubercx_ship_radio_orig"><b> Use Original: </b>' + addr + '</label></div>';
|
111 |
+
|
112 |
+
//The hidden fields that get posted back to our plugin
|
113 |
+
$('ubercx_ship_addr_radio').innerHTML = $('ubercx_ship_addr_radio').innerHTML+"<div style='display: hidden;'><input type='hidden' name='ubercx_ship_addr_orig_addr1' id='ubercx_ship_addr_orig_addr1' value='" + response.data.orig.addr1 + "'><input type='hidden' name='ubercx_ship_addr_orig_addr2' id='ubercx_ship_addr_orig_addr2' value='" + response.data.orig.addr2 + "'><input type='hidden' name='ubercx_ship_addr_orig_city' id='ubercx_ship_addr_orig_city' value='" + response.data.orig.city + "'><input type='hidden' name='ubercx_ship_addr_orig_state' id='ubercx_ship_addr_orig_state' value='" + response.data.orig.state + "'><input type='hidden' name='ubercx_ship_addr_orig_region_id' id='ubercx_ship_addr_orig_region_id' value='" + response.data.orig.region_id + "'><input type='hidden' name='ubercx_ship_addr_orig_zip' id='ubercx_ship_addr_orig_zip' value='" + response.data.orig.zip + "'></div>";
|
114 |
+
|
115 |
+
//do we have any corrected addresses?
|
116 |
+
if( typeof(response.data.corrected) !== 'undefined' && response.data.corrected.length > 0){
|
117 |
+
for (var i = 0; i < response.data.corrected.length; i++) {
|
118 |
+
|
119 |
+
addr = ((response.data.corrected[i].addr1 =="") ? "" : response.data.corrected[i].addr1 + ", ");
|
120 |
+
addr += ((response.data.corrected[i].addr2 =="") ? "" : response.data.corrected[i].addr2 + ", ");
|
121 |
+
addr += ((response.data.corrected[i].city =="") ? "" : response.data.corrected[i].city + ", ");
|
122 |
+
addr += ((response.data.corrected[i].state =="") ? "" : response.data.corrected[i].state + ", ");
|
123 |
+
addr += ((response.data.corrected[i].zip =="") ? "" : response.data.corrected[i].zip);
|
124 |
+
|
125 |
+
$('ubercx_ship_addr_radio').innerHTML = $('ubercx_ship_addr_radio').innerHTML+'<div class="ubercx-addr-radio"><input type="radio" name="ubercx_which_to_use" id="ubercx_ship_radio_' + i + '" value="' + i + '" onclick="ubercx_radio_ship_changed(this);"><label for="ubercx_ship_radio_' + i + '"><b> Suggestion: </b>' + addr + '</label></div>';
|
126 |
+
|
127 |
+
//The hidden fields that get posted back to our plugin
|
128 |
+
|
129 |
+
$('ubercx_ship_addr_radio').innerHTML = $('ubercx_ship_addr_radio').innerHTML+"<div style='display: hidden;'><input type='hidden' name='ubercx_ship_addr_corrected_" + i + "_addr1' id='ubercx_ship_addr_corrected_" + i + "_addr1' value='" + response.data.corrected[i].addr1 + "'><input type='hidden' name='ubercx_ship_addr_corrected_" + i + "_addr2' id='ubercx_ship_addr_corrected_" + i + "_addr2' value='" + response.data.corrected[i].addr2 + "'><input type='hidden' name='ubercx_ship_addr_corrected_" + i + "_city' id='ubercx_ship_addr_corrected_" + i + "_city' value='" + response.data.corrected[i].city + "'><input type='hidden' name='ubercx_ship_addr_corrected_" + i + "_state' id='ubercx_ship_addr_corrected_" + i + "_state' value='" + response.data.corrected[i].state + "'><input type='hidden' name='ubercx_ship_addr_corrected_" + i + "_region_id' id='ubercx_ship_addr_corrected_" + i + "_region_id' value='" + response.data.corrected[i].region_id + "'><input type='hidden' name='ubercx_ship_addr_corrected_" + i + "_zip' id='ubercx_ship_addr_corrected_" + i + "_zip' value='" + response.data.corrected[i].zip + "'></div>";
|
130 |
+
}
|
131 |
+
}
|
132 |
+
$('ubercx_ship_addr_radio').innerHTML = $('ubercx_ship_addr_radio').innerHTML+'<div style="text-align:right"><a href="javascript:clear_validations(\'_ship\')">Clear Results</a></div>';
|
133 |
+
//alert('test');alert($('ubercx_addr_radio').innerHTML);
|
134 |
+
//un-hide the display
|
135 |
+
$('ubercx_ship_addr_correction').show();
|
136 |
+
$('ubercx_ship_addr_correction').scrollTo();
|
137 |
+
}
|
138 |
+
|
139 |
+
checkout.setStepResponse(response);
|
140 |
+
|
141 |
+
}
|
142 |
+
};
|
143 |
+
Shipping.addMethods(replaceShippingNextStepObj);
|
144 |
+
}
|
145 |
+
//Handle the radio button change
|
146 |
+
function ubercx_radio_changed(item){
|
147 |
+
//TODO we need to work out how to select the correct state here....
|
148 |
+
//lets copy the data into the appropriate fields
|
149 |
+
if(item.value=='orig'){
|
150 |
+
//go with orig values
|
151 |
+
addr1 = $('ubercx_addr_orig_addr1').value;
|
152 |
+
addr2 = $('ubercx_addr_orig_addr2').value;
|
153 |
+
city = $('ubercx_addr_orig_city').value;
|
154 |
+
state = $('ubercx_addr_orig_region_id').value;
|
155 |
+
zip = $('ubercx_addr_orig_zip').value;
|
156 |
+
|
157 |
+
} else {
|
158 |
+
//it is one of the corrected fields
|
159 |
+
key = item.value;
|
160 |
+
addr1 = $('ubercx_addr_corrected_' + key + '_addr1').value;
|
161 |
+
addr2 = $('ubercx_addr_corrected_' + key + '_addr2').value;
|
162 |
+
city = $('ubercx_addr_corrected_' + key + '_city').value;
|
163 |
+
state = $('ubercx_addr_corrected_' + key + '_region_id').value;
|
164 |
+
zip = $('ubercx_addr_corrected_' + key + '_zip').value;
|
165 |
+
}
|
166 |
+
|
167 |
+
//OK are we shipping to different addr?
|
168 |
+
|
169 |
+
//shipping to billing
|
170 |
+
$('billing:street1').value =addr1;
|
171 |
+
$('billing:street2').value =addr2;
|
172 |
+
$('billing:city').value =city;
|
173 |
+
$('billing:region_id').value =state;
|
174 |
+
$('billing:postcode').value =zip;
|
175 |
+
|
176 |
+
//always update the ship to in case they select it!
|
177 |
+
if($('billing:use_for_shipping_yes').checked ){
|
178 |
+
$('shipping:street1').value =addr1;
|
179 |
+
$('shipping:street2').value =addr2;
|
180 |
+
$('shipping:city').value =city;
|
181 |
+
$('shipping:region_id').value =state;
|
182 |
+
$('shipping:postcode').value =zip;
|
183 |
+
}
|
184 |
+
|
185 |
+
|
186 |
+
}
|
187 |
+
|
188 |
+
//Handle the radio button change
|
189 |
+
function ubercx_radio_ship_changed(item){
|
190 |
+
//TODO we need to work out how to select the correct state here....
|
191 |
+
//lets copy the data into the appropriate fields
|
192 |
+
if(item.value=='orig'){
|
193 |
+
//go with orig values
|
194 |
+
addr1 = $('ubercx_ship_addr_orig_addr1').value;
|
195 |
+
addr2 = $('ubercx_ship_addr_orig_addr2').value;
|
196 |
+
city = $('ubercx_ship_addr_orig_city').value;
|
197 |
+
state = $('ubercx_ship_addr_orig_region_id').value;
|
198 |
+
zip = $('ubercx_ship_addr_orig_zip').value;
|
199 |
+
|
200 |
+
} else {
|
201 |
+
//it is one of the corrected fields
|
202 |
+
key = item.value;
|
203 |
+
addr1 = $('ubercx_ship_addr_corrected_' + key + '_addr1').value;
|
204 |
+
addr2 = $('ubercx_ship_addr_corrected_' + key + '_addr2').value;
|
205 |
+
city = $('ubercx_ship_addr_corrected_' + key + '_city').value;
|
206 |
+
state = $('ubercx_ship_addr_corrected_' + key + '_region_id').value;
|
207 |
+
zip = $('ubercx_ship_addr_corrected_' + key + '_zip').value;
|
208 |
+
}
|
209 |
+
|
210 |
+
//OK are we shipping to different addr?
|
211 |
+
if($('billing:use_for_shipping_no').checked ){
|
212 |
+
//shipping to different addr
|
213 |
+
$('shipping:street1').value = addr1;
|
214 |
+
$('shipping:street2').value =addr2;
|
215 |
+
$('shipping:city').value =city;
|
216 |
+
$('shipping:region_id').value =state;
|
217 |
+
$('shipping:postcode').value =zip;
|
218 |
+
}
|
219 |
+
}
|
220 |
+
|
221 |
+
function clear_validations(divId){
|
222 |
+
$('ubercx'+divId+'_addr_radio').innerHTML = '';
|
223 |
+
$('ubercx'+divId+'_addr_correction').hide();
|
224 |
+
}
|