UberCX_AVS - Version 1.1.0

Version Notes

Second stable release

Download this release

Release Info

Developer snapCX
Extension UberCX_AVS
Version 1.1.0
Comparing to
See all releases


Code changes from version 1.0.1 to 1.1.0

app/code/community/Ubercx/Addressvalidator/Block/Response.php ADDED
@@ -0,0 +1,46 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Magento
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
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/osl-3.0.php
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@magentocommerce.com so we can send you a copy immediately.
14
+ *
15
+ * @category Phoenix
16
+ * @package Phoenix_Moneybookers
17
+ * @copyright Copyright (c) 2014 Phoenix Medien GmbH & Co. KG (http://www.phoenix-medien.de)
18
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
19
+ */
20
+ class Ubercx_Addressvalidator_Block_Response extends Mage_Core_Block_Template
21
+ {
22
+
23
+ /**
24
+ * construct
25
+ *
26
+ * @param
27
+ * @return
28
+ */
29
+ public function __construct(){
30
+ parent::__construct();
31
+ }
32
+
33
+ /**
34
+ * Set result to the block
35
+ *
36
+ * @param
37
+ * @return string,array
38
+ */
39
+ public function getResult(){
40
+ if(Mage::getSingleton("core/session")->getUbercxResult()){
41
+ $result = Mage::getSingleton("core/session")->getUbercxResult();
42
+ //Mage::getSingleton("core/session")->unsUbercxResult() ;
43
+ return $result;
44
+ }
45
+ }
46
+ }
app/code/community/Ubercx/Addressvalidator/Model/Observer.php CHANGED
@@ -22,13 +22,15 @@
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();
@@ -45,8 +47,10 @@ class Ubercx_Addressvalidator_Model_Observer extends Mage_Core_Model_Abstract {
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'){
@@ -103,7 +107,6 @@ class Ubercx_Addressvalidator_Model_Observer extends Mage_Core_Model_Abstract {
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
@@ -115,9 +118,6 @@ class Ubercx_Addressvalidator_Model_Observer extends Mage_Core_Model_Abstract {
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);
@@ -127,12 +127,256 @@ class Ubercx_Addressvalidator_Model_Observer extends Mage_Core_Model_Abstract {
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();
@@ -155,23 +399,24 @@ class Ubercx_Addressvalidator_Model_Observer extends Mage_Core_Model_Abstract {
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){
@@ -199,7 +444,8 @@ class Ubercx_Addressvalidator_Model_Observer extends Mage_Core_Model_Abstract {
199
  break;
200
  }
201
  else{
202
- return $observer;
 
203
  }
204
  break;
205
  case 'AVS_02':
@@ -239,18 +485,9 @@ class Ubercx_Addressvalidator_Model_Observer extends Mage_Core_Model_Abstract {
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
  }
22
 
23
  class Ubercx_Addressvalidator_Model_Observer extends Mage_Core_Model_Abstract {
24
  const UBERCX_ADDR_DOMAIN = 'ubercx-addr-val';
25
+
26
  /**
27
  * Validate address using Ubercx API, rewrite response if suggestions available
28
  *
29
  * @param Varien_Event_Observer $observer
30
  * @return Varien_Event_Observer $observer
31
  */
32
+ public function validateOnepageAddress($observer) {
33
+
34
  $helper = Mage::helper('addressvalidator');
35
  $request = Mage::app()->getRequest();
36
  $event = $observer->getEvent();
47
 
48
  if ($event->getName() == 'controller_action_postdispatch_checkout_onepage_saveBilling') {
49
  $address = $quote->getBillingAddress();
50
+ $address_id = $request->getParam('billing_address_id');
51
  } else {
52
  $address = $quote->getShippingAddress();
53
+ $address_id = $request->getParam('shipping_address_id');
54
  }
55
 
56
  if ($address->getAddressType()=='billing'){
107
  ($address->getPostcode() == $post_zip) ? $dirty=$dirty : $dirty=true;
108
  ($address->getCountry() == 'US') ? $dirty=$dirty : $dirty=true;
109
 
 
110
  //if clean then lets just return the data and we are good to go
111
  if(!$dirty){
112
  //TODO for now we return nothing so the order doesnt process
118
  //so either it is dirty or it is the first time thru - either way validate the address!
119
  //now check if the user opted to use the corrected addr
120
 
 
 
 
121
  $first_name = $address->getFirstname();
122
  $last_name = $address->getLastname();
123
  $address_1 = $address->getStreet(1);
127
  $zip = $address->getPostcode();
128
  $country = $address->getCountry();
129
 
130
+ //generate a unique request id
131
+ $requestId = 'Magento_' . time();
132
+
133
+ $url = '?request_id='.$requestId.'&street='.urlencode($address_1).'&secondary='.urlencode($address_2).'&state='.urlencode($state).'&city='.urlencode($city).'&zipcode='.urlencode($zip);
134
+
135
+ //Call the api via curl
136
+ if(!$response=$this->callApi($url)){
137
+ return $observer;
138
+ }
139
+
140
+ $transient = array();
141
+ $transient['orig'] = array();
142
+ $transient['orig']['addr1'] = $address->getStreet(1);
143
+ $transient['orig']['addr2'] = $address->getStreet(2);
144
+ $transient['orig']['city'] = $address->getCity();
145
+ $transient['orig']['state'] = $address->getRegion();
146
+ $transient['orig']['region_id'] = $address->getRegionId();
147
+ $transient['orig']['zip'] = $address->getPostcode();
148
+
149
+ if($result = $this->evaluateResponse($response, $transient, $zip)){
150
+ $result['address_id'] = $address_id;
151
+ if(!$result['error'])return $observer;
152
+ $ob_response->setBody(Mage::helper('core')->jsonEncode($result));
153
+ $observer->setResult($result);
154
+ }
155
+ return $observer;
156
+ }
157
+
158
+ /**
159
+ * Validate address using Ubercx API, for standalone shipping address from at check out
160
+ *
161
+ * @param Varien_Event_Observer $observer
162
+ * @return Varien_Event_Observer $observer
163
+ */
164
+ public function validateAddress($observer) {
165
+
166
+ $helper = Mage::helper('addressvalidator');
167
+ $request = Mage::app()->getRequest();
168
+ $event = $observer->getEvent();
169
+ $store = Mage::app()->getStore();
170
+ $storeId = $store->getId();
171
+ $quote = Mage::getSingleton('checkout/session')->getQuote();
172
+ $address = $observer->getAddress();
173
+
174
+ //check if module is actiave to use
175
+ if(!$helper->isEnable()){
176
+ return $observer;
177
+ }
178
+ if(!isset($_POST['success_url'])){
179
+ return $observer;
180
+ }
181
+ //check if address is for shipping
182
+ if(!preg_match('/shipping/i',$_POST['success_url']) && !preg_match('/shipping/i',$_POST['error_url'])){
183
+ return $observer;
184
+ }
185
+
186
+ //ok if we have a 'which_to_use' it means the user has selected one - which means we validated already
187
+ //Lets see if they have changed any data, if they have we need to revalidate!!!
188
+ if(isset($_POST['ubercx_which_to_use'])){
189
+
190
+ //ok lets see if any of the fields are dirty
191
+ //which one did they select
192
+ $selected = $_POST['ubercx_which_to_use'];
193
+
194
+ // create the hidden id used in the html so we can check if it is dirty
195
+ if($selected != 'orig'){
196
+ $selected = "corrected_" . $selected;
197
+ }
198
+
199
+ $post_addr1 = $_POST['ubercx_ship_addr_' . $selected . '_addr1'];
200
+ $post_addr2 = $_POST['ubercx_ship_addr_' . $selected . '_addr2'];
201
+ $post_city = $_POST['ubercx_ship_addr_' . $selected . '_city'];
202
+ $post_state = $_POST['ubercx_ship_addr_' . $selected . '_state'];
203
+ $post_zip = $_POST['ubercx_ship_addr_' . $selected . '_zip'];
204
+
205
+ //Now compare them to the form to see if it is dirty
206
+ //Billing or shipping addr?
207
+ $dirty = false;
208
+
209
+ ($address->getStreet(1) == $post_addr1) ? $dirty=$dirty : $dirty=true;
210
+ ($address->getStreet(2) == $post_addr2) ? $dirty=$dirty : $dirty=true;
211
+ ($address->getCity() == $post_city) ? $dirty=$dirty : $dirty=true;
212
+ if($selected != 'orig'){
213
+ $region = Mage::getModel('directory/region')->loadByCode($post_state, 'US');
214
+ $post_state = $region->getName();
215
+ }
216
+ ($address->getRegion() == $post_state) ? $dirty=$dirty : $dirty=true;
217
+ ($address->getPostcode() == $post_zip) ? $dirty=$dirty : $dirty=true;
218
+ ($address->getCountry() == 'US') ? $dirty=$dirty : $dirty=true;
219
+
220
+ //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;;
221
+ //if clean then lets just return the data and we are good to go
222
+ if(!$dirty){
223
+ $sessResults = Mage::getSingleton("core/session")->getUbercxResult();
224
+ if($sessResults){
225
+ foreach($sessResults as $k => $sessResult){
226
+ $obj = json_decode($sessResult);
227
+ if($obj->address_id == $address->getId()){
228
+ unset($sessResults[$k]);
229
+
230
+ }
231
+ }
232
+ $sessResults = array_values($sessResults);
233
+ Mage::getSingleton("core/session")->setUbercxResult($sessResults);
234
+ }
235
+ //TODO for now we return nothing so the order doesnt process
236
+ //faking error on clean!
237
+ return $observer;
238
+ }
239
+ else{
240
+
241
+ }
242
+
243
+ }
244
+
245
+
246
+ //so either it is dirty or it is the first time thru - either way validate the address!
247
+ //now check if the user opted to use the corrected addr
248
+
249
+ $first_name = $address->getFirstname();
250
+ $last_name = $address->getLastname();
251
+ $address_1 = $address->getStreet(1);
252
+ $address_2 = $address->getStreet(2);
253
+ $city = $address->getCity();
254
+ $state = $address->getRegion();
255
+ $zip = $address->getPostcode();
256
+ $country = $address->getCountry();
257
 
258
+ //generate a unique request id
259
  $requestId = 'Magento_' . time();
260
 
261
+ $url = '?request_id='.$requestId.'&street='.urlencode($address_1).'&secondary='.urlencode($address_2).'&state='.urlencode($state).'&city='.urlencode($city).'&zipcode='.urlencode($zip);
262
+
263
+ //Call the api via curl
264
+ if(!$response=$this->callApi($url)){
265
+ return $observer;
266
+ }
267
+
268
+ $transient = array();
269
+ $transient['orig'] = array();
270
+ $transient['orig']['addr1'] = $address->getStreet(1);
271
+ $transient['orig']['addr2'] = $address->getStreet(2);
272
+ $transient['orig']['city'] = $address->getCity();
273
+ $transient['orig']['state'] = $address->getRegion();
274
+ $transient['orig']['region_id'] = $address->getRegionId();
275
+ $transient['orig']['zip'] = $address->getPostcode();
276
+
277
+ if($result = $this->evaluateResponse($response, $transient, $zip)){
278
+ $address->addError('');
279
+ Mage::getSingleton("core/session")->setUbercxResult(Mage::helper('core')->jsonEncode($result));
280
+ }
281
+ return $observer;
282
+ }
283
+
284
+ /**
285
+ * Validate address using Ubercx API, for multiple shipping address form at check out
286
+ *
287
+ * @param Varien_Event_Observer $observer
288
+ * @return Varien_Event_Observer $observer
289
+ */
290
+ public function validateMultiShippingAddress($observer) {
291
+
292
+ $helper = Mage::helper('addressvalidator');
293
+ $request = Mage::app()->getRequest();
294
+ $event = $observer->getEvent();
295
+ $controller = $event->getControllerAction();
296
+ $ob_response = $controller->getResponse();
297
+ $store = Mage::app()->getStore();
298
+ $storeId = $store->getId();
299
+ $quote = Mage::getSingleton('checkout/session')->getQuote();
300
+ $address_type = '';
301
+ $results = array();
302
+ $address_read = array();
303
+ //check if module is actiave to use
304
+ if(!$helper->isEnable()){
305
+ return $observer;
306
+ }
307
+
308
+ if(count($request->getParam('ship'))){
309
+ $ship_addresses = $request->getParam('ship');
310
+
311
+ for($i=0;$i<count($ship_addresses);$i++){
312
+
313
+ foreach($ship_addresses[$i] as $ship_address){
314
+
315
+
316
+ if(in_array($ship_address['address'],$address_read)){
317
+ continue;
318
+ }
319
+ //echo $ship_addresses[$i][$quote->getId()]['address'].'<br>';
320
+ $address = Mage::getModel('customer/address')->load($ship_address['address']);
321
+
322
+ //so either it is dirty or it is the first time thru - either way validate the address!
323
+ //now check if the user opted to use the corrected addr
324
+
325
+ $first_name = $address->getFirstname();
326
+ $last_name = $address->getLastname();
327
+ $address_1 = $address->getStreet(1);
328
+ $address_2 = $address->getStreet(2);
329
+ $city = $address->getCity();
330
+ $state = $address->getRegion();
331
+ $zip = $address->getPostcode();
332
+ $country = $address->getCountry();
333
+
334
+ //generate a unique request id
335
+ $requestId = 'Magento_' . time();
336
+
337
+ $url = '?request_id='.$requestId.'&street='.urlencode($address_1).'&secondary='.urlencode($address_2).'&state='.urlencode($state).'&city='.urlencode($city).'&zipcode='.urlencode($zip);
338
+
339
+ //Call the api via curl
340
+ if(!$response=$this->callApi($url)){
341
+ return $observer;
342
+ }
343
+
344
+ $transient = array();
345
+ $transient['orig'] = array();
346
+ $transient['orig']['addr1'] = $address->getStreet(1);
347
+ $transient['orig']['addr2'] = $address->getStreet(2);
348
+ $transient['orig']['city'] = $address->getCity();
349
+ $transient['orig']['state'] = $address->getRegion();
350
+ $transient['orig']['region_id'] = $address->getRegionId();
351
+ $transient['orig']['zip'] = $address->getPostcode();
352
+
353
+ if($result = $this->evaluateResponse($response, $transient, $zip)){
354
+ $result['address_id'] = $ship_address['address'];
355
+ $results[$i] = Mage::helper('core')->jsonEncode($result);
356
+ }
357
+
358
+ $address_read[] = $ship_address['address'];
359
+ }
360
+ }
361
+ }
362
+
363
+ Mage::getSingleton("core/session")->setUbercxResult($results);
364
+ return $observer;
365
+ }
366
+
367
+
368
+ /**
369
+ * Call Ubecx API to validate addresses
370
+ *
371
+ * @param Varien_Event_Observer $observer
372
+ * @return Varien_Event_Observer $observer
373
+ */
374
+ public function callApi($url){
375
+ //ok now lets call our API
376
+ $api_url = Mage::getStoreConfig('addressvalidator/ubercx_api_url');
377
+ $url = $api_url.''.$url;
378
+ //get the user key
379
+ $user_key = Mage::getStoreConfig('addressvalidator/addressvalidator_settings/addressvalidator_user_key');;
380
 
381
  // Start cURL
382
  $curl = curl_init();
399
  //TODO put status check for "200".
400
  // Close cURL
401
  curl_close($curl);
402
+
 
403
  if($response!=''){
404
  $response = json_decode($response);
405
+ return $response;
406
  } else {
407
+ return false;
408
  }
409
 
410
+ }
411
+
412
+ /**
413
+ * Evaluate the response from api
414
+ *
415
+ * @param Varien_Event_Observer $observer
416
+ * @return Varien_Event_Observer $observer
417
+ */
418
+ public function evaluateResponse($response, $transient,$zip){
419
+ $return = false;
420
  if(is_object($response) && isset( $response->header) && isset( $response->header->status) && $response->header->status == 'SUCCESS'){
421
  if(isset($response->addressRecord[0]) && isset($response->addressRecord[0]->addressSummary) && isset($response->addressRecord[0]->addressSummary->matchCode)){
422
  switch($response->addressRecord[0]->addressSummary->matchCode){
444
  break;
445
  }
446
  else{
447
+ $result['validate'] = true;
448
+ $result['error'] = false;
449
  }
450
  break;
451
  case 'AVS_02':
485
  }
486
  $result['data'] = $transient;
487
  $result['message'] = $response->addressRecord[0]->addressSummary->message;
488
+ $return = $result;
489
+ }
 
 
 
 
 
 
 
 
 
 
490
  }
491
+ return $return;
492
  }
493
  }
app/code/community/Ubercx/Addressvalidator/etc/config.xml CHANGED
@@ -23,7 +23,7 @@
23
  <config>
24
  <modules>
25
  <Ubercx_Addressvalidator>
26
- <version>1.0.1</version>
27
  </Ubercx_Addressvalidator>
28
  </modules>
29
  <frontend>
@@ -32,7 +32,7 @@
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>
@@ -40,10 +40,26 @@
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>
@@ -67,10 +83,15 @@
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>
23
  <config>
24
  <modules>
25
  <Ubercx_Addressvalidator>
26
+ <version>1.1.0</version>
27
  </Ubercx_Addressvalidator>
28
  </modules>
29
  <frontend>
32
  <observers>            
33
  <addressvalidator_checkaddress>                
34
  <class>ubercx_addressvalidator/observer</class>
35
+ <method>validateOnepageAddress</method>
36
  </addressvalidator_checkaddress>
37
  </observers>
38
  </controller_action_postdispatch_checkout_onepage_saveBilling>
40
  <observers>            
41
  <addressvalidator_checkaddress>                
42
  <class>ubercx_addressvalidator/observer</class>
43
+ <method>validateOnepageAddress</method>
44
  </addressvalidator_checkaddress>
45
  </observers>
46
  </controller_action_postdispatch_checkout_onepage_saveShipping>
47
+ <customer_address_validation_after>        
48
+ <observers>            
49
+ <addressvalidator_checkaddress>                
50
+ <class>ubercx_addressvalidator/observer</class>
51
+ <method>validateAddress</method>
52
+ </addressvalidator_checkaddress>
53
+ </observers>
54
+ </customer_address_validation_after>
55
+ <controller_action_postdispatch_checkout_multishipping_addressesPost>        
56
+ <observers>            
57
+ <addressvalidator_checkaddress>                
58
+ <class>ubercx_addressvalidator/observer</class>
59
+ <method>validateMultiShippingAddress</method>
60
+ </addressvalidator_checkaddress>
61
+ </observers>
62
+ </controller_action_postdispatch_checkout_multishipping_addressesPost>
63
  </events>
64
  <layout>
65
  <updates>
83
  <class>Ubercx_Addressvalidator_Helper</class>
84
  </addressvalidator>
85
  </helpers>
86
+ <blocks>
87
+ <ubercx_addressvalidator>
88
+ <class>Ubercx_Addressvalidator_Block</class>
89
+ </ubercx_addressvalidator>
90
+ </blocks>
91
  </global>
92
  <default>
93
  <addressvalidator>
94
+ <ubercx_api_url><![CDATA[https://api.snapcx.io/avs/v1/validateAddress]]></ubercx_api_url>
95
  </addressvalidator>
96
  </default>
97
+ </config>
app/code/community/Ubercx/Addressvalidator/etc/system.xml CHANGED
@@ -23,7 +23,7 @@
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>
@@ -32,20 +32,20 @@
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>
@@ -54,7 +54,7 @@
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>
23
  <config>
24
  <tabs>
25
  <ubercx translate="label" module="addressvalidator">
26
+ <label>snapCX Plugins</label>
27
  <sort_order>301</sort_order>
28
  </ubercx>
29
  </tabs>
32
  <label>Address Validation Settings</label>
33
  <tab>ubercx_addressvalidator</tab>
34
  <frontend_type>text</frontend_type>
35
+ <sort_order>992</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>snapCX 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 snapcx API, which responds in JSON payload. Please visit this <a target="_blank" href="https://snapcx.io/avs/plugins/magento">link</a> to detail documentation about plugins and recipes.]]></comment>
49
  <fields>
50
  <addressvalidator_user_key translate="label">
51
  <label>User Key</label>
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://snapcx.io/signup" target="_blank">Get your User Key</a>]]></comment>
58
  </addressvalidator_user_key>
59
  <addressvalidator_active translate="label">
60
  <label>Enabled</label>
app/design/frontend/base/default/layout/ubercx/addressvalidator.xml CHANGED
@@ -23,7 +23,17 @@
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>
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_onepage.phtml" />
27
  </reference>
28
  </checkout_onepage_index>
29
+ <checkout_multishipping_customer_address>
30
+ <reference name="content">
31
+ <block type="ubercx_addressvalidator/response" after="customer_address_edit" name="ubercx_addressvalidator_response" template="ubercx/addressvalidator/response.phtml"/>
32
+ </reference>
33
+ </checkout_multishipping_customer_address>
34
+ <checkout_multishipping_shipping>
35
+ <reference name="content">
36
+ <block type="ubercx_addressvalidator/response" after="checkout_billing_items" name="ubercx_addressvalidator_responsemulti" template="ubercx/addressvalidator/response_multi.phtml"/>
37
+ </reference>
38
+ </checkout_multishipping_shipping>
39
  </layout>
app/design/frontend/base/default/template/ubercx/addressvalidator/response.phtml CHANGED
@@ -20,15 +20,31 @@
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
 
20
  */
21
 
22
  $storeId = Mage::app()->getStore()->getId();
23
+ $results = $this->getResult();
24
+ if(is_array($results)){
25
+ foreach($results as $res){
26
+ $obj = json_decode($res);
27
+ if(Mage::app()->getRequest()->getParam('id')==$obj->address_id){
28
+ $result = $res;
29
+ }
30
+ }
31
+ }
32
+ else{
33
+ $result = $results;
34
+ }
35
 
36
+ if($result!=""){
37
+ echo '<script type="text/javascript" >var non_ajax_response = '.$result.'</script>';
38
+ }
39
  ?>
40
  <script type="text/javascript" >
41
+ /*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>';*/
42
 
43
  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>';
44
 
45
+ //$('co-billing-form').innerHTML = html+$('co-billing-form').innerHTML;
46
+ $('form-validate').innerHTML = html_ship+$('form-validate').innerHTML;
47
  </script>
48
+
49
  <script src="<?php echo $this->getSkinUrl('js/ubercx/response_handler.js') ?>"></script>
50
 
app/design/frontend/base/default/template/ubercx/addressvalidator/response_multi.phtml ADDED
@@ -0,0 +1,47 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+ $results = $this->getResult();
24
+ if(is_array($results)){
25
+ foreach($results as $result){
26
+ if($result!=""){
27
+ echo '<script type="text/javascript" >var non_ajax_response = '.$result.'</script>';
28
+ $obj = json_decode($result);
29
+ if($obj->error){
30
+ ?>
31
+ <script type="text/javascript" >
32
+ var html = '<div id="" class=""><ul class="messages"><li class="error-msg"><ul><li><span>There appears to be a problem with the address. Please click Change to check the corrections or you can continue with the current address.</span></li></ul></li></ul><div id=""><div id="" class="ubercx-addr-radio"></div><div style="display: none;" id="ubercx_orig_placeholder"></div></div></div>';
33
+ document.observe("dom:loaded", function() {
34
+ $$('#shipping_method_form div.col2-set .box-title a').each(function(index) {
35
+ var hrefv = index.readAttribute('href');
36
+
37
+ regx = /id\/<?php echo $obj->address_id?>/;
38
+ regx2 = /id=<?php echo $obj->address_id?>/;
39
+ if(regx.test(hrefv)||regx2.test(hrefv)){
40
+ index.up('div.col-1').innerHTML = html+index.up('div.col-1').innerHTML;
41
+ }
42
+ });
43
+ });
44
+ </script>
45
+ <?php } } }}?>
46
+ <?php /*?><script src="<?php echo $this->getSkinUrl('js/ubercx/response_handler.js') ?>"></script><?php */?>
47
+
app/design/frontend/base/default/template/ubercx/addressvalidator/response_onepage.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
+ echo '<script type="text/javascript" >var non_ajax_response = \'\';</script>';
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
+
package.xml CHANGED
@@ -1,24 +1,26 @@
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>
@@ -34,7 +36,11 @@
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>
1
  <?xml version="1.0"?>
2
  <package>
3
  <name>UberCX_AVS</name>
4
+ <version>1.1.0</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>Shipping Address validation and Corrections.</summary>
10
+ <description>Address validater, validates address from USA, and provide correct address(es) as suggestion. </description>
11
+ <notes>Second stable release</notes>
12
+ <authors><author><name>snapCX</name><user>snapCX</user><email>support@snapcx.io</email></author></authors>
13
+ <date>2015-10-28</date>
14
  <time>06:14:23</time>
15
  <contents>
16
  <target name="magecommunity">
17
  <dir name="Ubercx">
18
  <dir name="Addressvalidator">
19
+ <dir name="Block"><file name="Response.php" hash="42676f5adc05d1919142337c3677107e"/></dir>
20
  <dir name="Helper"><file name="Data.php" hash="e2208c32f13bd9d9877e4964bd6286cc"/></dir>
21
  <dir name="Model"><file name="Observer.php" hash="0b42264e5e81c3a018bd4abcf3108326"/></dir>
22
+ <dir name="etc">
23
+ <file name="adminhtml.xml" hash="4cb243feddb112f72df7b87c4c3cdd74"/>
24
  <file name="config.xml" hash="47cfe4b52c6eeb92f5b11a0c69659feb"/>
25
  <file name="system.xml" hash="f009266afb65bb05032c1672549e9af8"/>
26
  </dir>
36
  </dir>
37
  <dir name="template">
38
  <dir name="ubercx">
39
+ <dir name="addressvalidator">
40
+ <file name="response.phtml" hash="3dc79ad5891001ab256c975be62d106c"/>
41
+ <file name="response_multi.phtml" hash="bb77cab51d35c13e0459868d279905f1"/>
42
+ <file name="response_onepage.phtml" hash="d660263406a413138dc66206c89d837d"/>
43
+ </dir>
44
  </dir>
45
  </dir>
46
  </dir>
skin/frontend/base/default/js/ubercx/response_handler.js CHANGED
@@ -18,7 +18,6 @@
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) {
@@ -32,8 +31,9 @@ if (window.shipping){
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
@@ -43,12 +43,19 @@ if (window.shipping){
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++) {
@@ -67,7 +74,6 @@ if (window.shipping){
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();
@@ -93,10 +99,12 @@ if (window.shipping){
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
@@ -106,11 +114,18 @@ if (window.shipping){
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){
@@ -130,7 +145,6 @@ if (window.shipping){
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();
@@ -142,6 +156,62 @@ if (window.shipping){
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....
@@ -165,7 +235,7 @@ function ubercx_radio_changed(item){
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;
@@ -181,8 +251,18 @@ function ubercx_radio_changed(item){
181
  $('shipping:region_id').value =state;
182
  $('shipping:postcode').value =zip;
183
  }
184
-
185
-
 
 
 
 
 
 
 
 
 
 
186
  }
187
 
188
  //Handle the radio button change
@@ -215,9 +295,51 @@ function ubercx_radio_ship_changed(item){
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();
18
  * @license http://opensource.org/licenses/gpl-license GNU General Public License
19
  */
20
  if (window.shipping){
 
21
  //replace the nextStep method in the Billing prototype
22
  var replaceBillingNextStepObj = {
23
  nextStep: function (transport) {
31
  }
32
  if (response && response.validate) {}
33
  if (!response.error) {
34
+
35
  } else {
36
+ var selected_address_id = '';
37
  //clear out any previous data in our error area
38
  $('ubercx_addr_radio').innerHTML = '';
39
  //first the original
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
+ if(typeof(response.address_id)!== 'undefined' && response.address_id!=""){
48
+ selected_address_id = "<input type='hidden' name='selected_address_id' id='selected_address_id' value='"+response.address_id+"'>";
49
+ }
50
+ else{
51
+ selected_address_id = "<input type='hidden' name='selected_address_id' id='selected_address_id' value=''>";
52
+ }
53
 
54
  $('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>';
55
 
56
  //The hidden fields that get posted back to our plugin
57
+ $('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 + "'>"+selected_address_id+"</div>";
58
+
59
  //do we have any corrected addresses?
60
  if( typeof(response.data.corrected) !== 'undefined' && response.data.corrected.length > 0){
61
  for (var i = 0; i < response.data.corrected.length; i++) {
74
  }
75
  }
76
  $('ubercx_addr_radio').innerHTML = $('ubercx_addr_radio').innerHTML+'<div style="text-align:right"><a href="javascript:clear_validations(\'\')">Clear Results</a></div>';
 
77
  //un-hide the display
78
  $('ubercx_addr_correction').show();
79
  $('ubercx_addr_correction').scrollTo();
99
  if (response && response.validate) {}
100
 
101
  if (!response.error) {
102
+
103
  /*if (typeof response.data == 'string') {
104
  addressValidator.validateAddress('co-shipping-form', response.message, response.data);
105
  }*/
106
  } else {
107
+ var selected_address_id = '';
108
  //clear out any previous data in our error area
109
  $('ubercx_ship_addr_radio').innerHTML = '';
110
  //first the original
114
  addr += ((response.data.orig.city =="") ? "" : response.data.orig.city + ", ");
115
  addr += ((response.data.orig.state =="") ? "" : response.data.orig.state + ", ");
116
  addr += ((response.data.orig.zip =="") ? "" : response.data.orig.zip);
117
+
118
+ if(typeof(response.address_id)!== 'undefined' && response.address_id!="" && response.address_id!=null){
119
+ selected_address_id = "<input type='hidden' name='selected_address_id' id='selected_address_id' value='"+response.address_id+"'>";
120
+ }
121
+ else{
122
+ selected_address_id = "<input type='hidden' name='selected_address_id' id='selected_address_id' value=''>";
123
+ }
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_orig" onclick="ubercx_radio_ship_changed(this);" value="orig" checked><label for="ubercx_ship_radio_orig"><b> Use Original: </b>' + addr + '</label></div>';
126
 
127
  //The hidden fields that get posted back to our plugin
128
+ $('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 + "'>"+selected_address_id+"</div>";
129
 
130
  //do we have any corrected addresses?
131
  if( typeof(response.data.corrected) !== 'undefined' && response.data.corrected.length > 0){
145
  }
146
  }
147
  $('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>';
 
148
  //un-hide the display
149
  $('ubercx_ship_addr_correction').show();
150
  $('ubercx_ship_addr_correction').scrollTo();
156
  };
157
  Shipping.addMethods(replaceShippingNextStepObj);
158
  }
159
+ if(non_ajax_response==''){
160
+ Ajax.Responders.register({
161
+
162
+ onComplete: function(response){
163
+ if($('opc-shipping_method').hasClassName('active') || $('opc-payment').hasClassName('active') || $('opc-review').hasClassName('active')){
164
+ clear_validations('');
165
+ clear_validations('_ship');
166
+ }
167
+ }
168
+ });
169
+ }
170
+ if(non_ajax_response!=''){
171
+
172
+ if (!non_ajax_response.error) {
173
+ /*if (typeof response.data == 'string') {
174
+ addressValidator.validateAddress('co-shipping-form', response.message, response.data);
175
+ }*/
176
+ } else {
177
+ //clear out any previous data in our error area
178
+ $('ubercx_ship_addr_radio').innerHTML = '';
179
+ //first the original
180
+ //radio button
181
+ addr = ((non_ajax_response.data.orig.addr1 =="") ? "" : non_ajax_response.data.orig.addr1 + ", ");
182
+ addr += ((non_ajax_response.data.orig.addr2 =="") ? "" : non_ajax_response.data.orig.addr2 + ", ");
183
+ addr += ((non_ajax_response.data.orig.city =="") ? "" : non_ajax_response.data.orig.city + ", ");
184
+ addr += ((non_ajax_response.data.orig.state =="") ? "" : non_ajax_response.data.orig.state + ", ");
185
+ addr += ((non_ajax_response.data.orig.zip =="") ? "" : non_ajax_response.data.orig.zip);
186
+
187
+ $('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_no_ajax_changed(this);" value="orig" checked><label for="ubercx_ship_radio_orig"><b> Use Original: </b>' + addr + '</label></div>';
188
+
189
+ //The hidden fields that get posted back to our plugin
190
+ $('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='" + non_ajax_response.data.orig.addr1 + "'><input type='hidden' name='ubercx_ship_addr_orig_addr2' id='ubercx_ship_addr_orig_addr2' value='" + non_ajax_response.data.orig.addr2 + "'><input type='hidden' name='ubercx_ship_addr_orig_city' id='ubercx_ship_addr_orig_city' value='" + non_ajax_response.data.orig.city + "'><input type='hidden' name='ubercx_ship_addr_orig_state' id='ubercx_ship_addr_orig_state' value='" + non_ajax_response.data.orig.state + "'><input type='hidden' name='ubercx_ship_addr_orig_region_id' id='ubercx_ship_addr_orig_region_id' value='" + non_ajax_response.data.orig.region_id + "'><input type='hidden' name='ubercx_ship_addr_orig_zip' id='ubercx_ship_addr_orig_zip' value='" + non_ajax_response.data.orig.zip + "'></div>";
191
+
192
+ //do we have any corrected addresses?
193
+ if( typeof(non_ajax_response.data.corrected) !== 'undefined' && non_ajax_response.data.corrected.length > 0){
194
+ for (var i = 0; i < non_ajax_response.data.corrected.length; i++) {
195
+
196
+ addr = ((non_ajax_response.data.corrected[i].addr1 =="") ? "" : non_ajax_response.data.corrected[i].addr1 + ", ");
197
+ addr += ((non_ajax_response.data.corrected[i].addr2 =="") ? "" : non_ajax_response.data.corrected[i].addr2 + ", ");
198
+ addr += ((non_ajax_response.data.corrected[i].city =="") ? "" : non_ajax_response.data.corrected[i].city + ", ");
199
+ addr += ((non_ajax_response.data.corrected[i].state =="") ? "" : non_ajax_response.data.corrected[i].state + ", ");
200
+ addr += ((non_ajax_response.data.corrected[i].zip =="") ? "" : non_ajax_response.data.corrected[i].zip);
201
+
202
+ $('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_no_ajax_changed(this);"><label for="ubercx_ship_radio_' + i + '"><b> Suggestion: </b>' + addr + '</label></div>';
203
+
204
+ //The hidden fields that get posted back to our plugin
205
+
206
+ $('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='" + non_ajax_response.data.corrected[i].addr1 + "'><input type='hidden' name='ubercx_ship_addr_corrected_" + i + "_addr2' id='ubercx_ship_addr_corrected_" + i + "_addr2' value='" + non_ajax_response.data.corrected[i].addr2 + "'><input type='hidden' name='ubercx_ship_addr_corrected_" + i + "_city' id='ubercx_ship_addr_corrected_" + i + "_city' value='" + non_ajax_response.data.corrected[i].city + "'><input type='hidden' name='ubercx_ship_addr_corrected_" + i + "_state' id='ubercx_ship_addr_corrected_" + i + "_state' value='" + non_ajax_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='" + non_ajax_response.data.corrected[i].region_id + "'><input type='hidden' name='ubercx_ship_addr_corrected_" + i + "_zip' id='ubercx_ship_addr_corrected_" + i + "_zip' value='" + non_ajax_response.data.corrected[i].zip + "'></div>";
207
+ }
208
+ }
209
+ $('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>';
210
+ //un-hide the display
211
+ $('ubercx_ship_addr_correction').show();
212
+ $('ubercx_ship_addr_correction').scrollTo();
213
+ }
214
+ }
215
  //Handle the radio button change
216
  function ubercx_radio_changed(item){
217
  //TODO we need to work out how to select the correct state here....
235
  }
236
 
237
  //OK are we shipping to different addr?
238
+
239
  //shipping to billing
240
  $('billing:street1').value =addr1;
241
  $('billing:street2').value =addr2;
251
  $('shipping:region_id').value =state;
252
  $('shipping:postcode').value =zip;
253
  }
254
+ if(!$('billing-new-address-form').visible() && item.value!="orig"){
255
+ $('billing-address-select').value = "";
256
+ $('billing-new-address-form').show();
257
+
258
+ }
259
+ else if($('billing-new-address-form').visible() && item.value!="orig"){}
260
+ else{
261
+ $('billing-address-select').value = $('selected_address_id').value;
262
+ if($('selected_address_id').value!=""){
263
+ $('billing-new-address-form').hide();
264
+ }
265
+ }
266
  }
267
 
268
  //Handle the radio button change
295
  $('shipping:city').value =city;
296
  $('shipping:region_id').value =state;
297
  $('shipping:postcode').value =zip;
298
+ }
299
+ if(!$('shipping-new-address-form').visible() && item.value!="orig"){
300
+ $('shipping-address-select').value = "";
301
+ $('shipping-new-address-form').show();
302
+ }
303
+ else if($('shipping-new-address-form').visible() && item.value!="orig"){}
304
+ else{
305
+ $('shipping-address-select').value = $('selected_address_id').value;
306
+ if($('selected_address_id').value!=""){
307
+ $('shipping-new-address-form').hide();
308
+ }
309
+ }
310
  }
311
+ //Handle the radio button change
312
+ function ubercx_radio_ship_no_ajax_changed(item){
313
+ //TODO we need to work out how to select the correct state here....
314
+ //lets copy the data into the appropriate fields
315
+ if(item.value=='orig'){
316
+ //go with orig values
317
+ addr1 = $('ubercx_ship_addr_orig_addr1').value;
318
+ addr2 = $('ubercx_ship_addr_orig_addr2').value;
319
+ city = $('ubercx_ship_addr_orig_city').value;
320
+ state = $('ubercx_ship_addr_orig_region_id').value;
321
+ zip = $('ubercx_ship_addr_orig_zip').value;
322
+
323
+ } else {
324
+ //it is one of the corrected fields
325
+ key = item.value;
326
+ addr1 = $('ubercx_ship_addr_corrected_' + key + '_addr1').value;
327
+ addr2 = $('ubercx_ship_addr_corrected_' + key + '_addr2').value;
328
+ city = $('ubercx_ship_addr_corrected_' + key + '_city').value;
329
+ state = $('ubercx_ship_addr_corrected_' + key + '_region_id').value;
330
+ zip = $('ubercx_ship_addr_corrected_' + key + '_zip').value;
331
+ }
332
+
333
+ //OK are we shipping to different addr?
334
 
335
+ //shipping to different addr
336
+ $('street_1').value = addr1;
337
+ $('street_2').value =addr2;
338
+ $('city').value =city;
339
+ $('region_id').value =state;
340
+ $('zip').value =zip;
341
+
342
+ }
343
  function clear_validations(divId){
344
  $('ubercx'+divId+'_addr_radio').innerHTML = '';
345
  $('ubercx'+divId+'_addr_correction').hide();