PostcodeNl_Api - Version 1.0.6.0

Version Notes

Changes:
- Improved support for non-standard/non-default templates
- Fixed bug when switching from non-NL country to non-NL country
- Improved Billing to Shipping synchronization
- Added support for `Apptha One Page Checkout`
- Added support for `Ecommerce Three-Step Checkout`

Download this release

Release Info

Developer Magento Core Team
Extension PostcodeNl_Api
Version 1.0.6.0
Comparing to
See all releases


Code changes from version 1.0.5.0 to 1.0.6.0

app/code/community/PostcodeNl/Api/etc/config.xml CHANGED
@@ -2,7 +2,7 @@
2
  <config>
3
  <modules>
4
  <PostcodeNl_Api>
5
- <version>1.0.5.0</version>
6
  </PostcodeNl_Api>
7
  </modules>
8
  <frontend>
2
  <config>
3
  <modules>
4
  <PostcodeNl_Api>
5
+ <version>1.0.6.0</version>
6
  </PostcodeNl_Api>
7
  </modules>
8
  <frontend>
app/design/frontend/default/default/layout/postcodenl/api/lookup.xml CHANGED
@@ -1,5 +1,6 @@
1
  <?xml version="1.0"?>
2
  <layout version="0.1.0">
 
3
  <checkout_onepage_index>
4
  <reference name="head">
5
  <action method="addCss" ifconfig="postcodenl/config/enabled"><script>postcodenl/api/css/lookup.css</script></action>
@@ -54,7 +55,7 @@
54
  <block type="postcodenl/jsinit" name="postcodenl.jsinit" template="postcodenl/api/jsinit.phtml" />
55
  </reference>
56
  </checkout_multishipping_address_editbilling>
57
- <!-- Used for `OneStepCheckout(.com)`, but also for `MageStore One Step Checkout` -->
58
  <onestepcheckout_index_index>
59
  <reference name="head">
60
  <action method="addCss" ifconfig="postcodenl/config/enabled"><script>postcodenl/api/css/lookup.css</script></action>
@@ -94,7 +95,7 @@
94
  <block type="postcodenl/jsinit" name="postcodenl.jsinit" template="postcodenl/api/jsinit.phtml" />
95
  </reference>
96
  </checkout_onestep_index>
97
- <!-- For `IDW Free One Page / Step Checkout` -->
98
  <onepagecheckout_index_index>
99
  <reference name="head">
100
  <action method="addCss" ifconfig="postcodenl/config/enabled"><script>postcodenl/api/css/lookup.css</script></action>
1
  <?xml version="1.0"?>
2
  <layout version="0.1.0">
3
+ <!-- Regular Magento Checkout, and other checkout modules which use the same page -->
4
  <checkout_onepage_index>
5
  <reference name="head">
6
  <action method="addCss" ifconfig="postcodenl/config/enabled"><script>postcodenl/api/css/lookup.css</script></action>
55
  <block type="postcodenl/jsinit" name="postcodenl.jsinit" template="postcodenl/api/jsinit.phtml" />
56
  </reference>
57
  </checkout_multishipping_address_editbilling>
58
+ <!-- Used for `OneStepCheckout(.com)`, but also for `MageStore One Step Checkout` and `Apptha One Step Checkout` -->
59
  <onestepcheckout_index_index>
60
  <reference name="head">
61
  <action method="addCss" ifconfig="postcodenl/config/enabled"><script>postcodenl/api/css/lookup.css</script></action>
95
  <block type="postcodenl/jsinit" name="postcodenl.jsinit" template="postcodenl/api/jsinit.phtml" />
96
  </reference>
97
  </checkout_onestep_index>
98
+ <!-- For `IWD Free One Page / Step Checkout` -->
99
  <onepagecheckout_index_index>
100
  <reference name="head">
101
  <action method="addCss" ifconfig="postcodenl/config/enabled"><script>postcodenl/api/css/lookup.css</script></action>
js/postcodenl/api/lookup.js CHANGED
@@ -13,6 +13,11 @@ document.observe("dom:loaded", function()
13
  }
14
 
15
  var PostcodeNl_Api = {
 
 
 
 
 
16
  /**
17
  * Hide multiple field-rows in forms
18
  */
@@ -24,12 +29,12 @@ document.observe("dom:loaded", function()
24
  {
25
  if ($(fieldId).up('div.two_fields'))
26
  {
27
- // For `IDW Free One Page / Step Checkout`
28
  $(fieldId).up('div.two_fields').addClassName('pcnl-hidden-field');
29
  }
30
  else if ($(fieldId).up('div.full'))
31
  {
32
- // For `IDW Free One Page / Step Checkout`
33
  $(fieldId).up('div.full').addClassName('pcnl-hidden-field');
34
  }
35
  else if ($(fieldId).up('li'))
@@ -55,12 +60,12 @@ document.observe("dom:loaded", function()
55
  {
56
  if ($(fieldId).up('div.two_fields'))
57
  {
58
- // For `IDW Free One Page / Step Checkout`
59
  $(fieldId).up('div.two_fields').removeClassName('pcnl-hidden-field');
60
  }
61
  else if ($(fieldId).up('div.full'))
62
  {
63
- // For `IDW Free One Page / Step Checkout`
64
  $(fieldId).up('div.full').removeClassName('pcnl-hidden-field');
65
  }
66
  else if ($(fieldId).up('li'))
@@ -244,159 +249,190 @@ document.observe("dom:loaded", function()
244
  if ($(prefix + countryFieldId).getValue() != 'NL' || postcode == '' || housenumber_mixed == '')
245
  return;
246
 
 
 
 
247
  var url = PCNLAPI_CONFIG.baseUrl +'lookup?postcode=' + postcode + '&houseNumber=' + housenumber + '&houseNumberAddition=' + housenumber_addition;
248
- new Ajax.Request(url,
249
  {
250
- method: 'get',
251
- onException: function(transport, e)
252
- {
253
- throw e;
254
- },
255
- onComplete: function(transport)
256
  {
257
- var json = transport.responseText.evalJSON();
258
-
259
- if (PCNLAPI_CONFIG.showcase)
260
  {
261
- if ($(prefix +'showcase'))
262
- $(prefix +'showcase').remove();
263
-
264
- var info = pcnlapi.getFieldListHtml(json.showcaseResponse, 'pcnl-showcase');
265
-
266
- var map = '';
267
- if (json.showcaseResponse.longitude && json.showcaseResponse.latitude)
268
- {
269
- map = '<iframe frameborder="0" scrolling="no" marginheight="0" marginwidth="0" class="map" src="http://maps.google.com/maps?t=h&amp;q='+ json.showcaseResponse.latitude +','+ json.showcaseResponse.longitude +'+(Location found)&amp;z=19&amp;output=embed&amp;iwloc=near"></iframe>';
270
- }
271
-
272
- if ($(prefix + countryFieldId).parentNode.tagName == 'TD')
273
- {
274
- // We're probably in the admin
275
- $(prefix + street1).up('tr').insert({before: '<tr id="' + prefix + 'showcase"><td class="label">'+ PCNLAPI_CONFIG.translations.apiShowcase.escapeHTML() +'</label></td><td class="value"><h4 class="pcnl-showcase">'+ PCNLAPI_CONFIG.translations.apiShowcase.escapeHTML() +'</h4>'+ info + '</td></tr>'});
276
- }
277
- else if ($(prefix + street1).up('div.full'))
278
- {
279
- // For `IDW Free One Page / Step Checkout`
280
- $(prefix + street1).up('div.full').insert({before: '<div id="' + prefix + 'showcase"><h4 class="pcnl-showcase">'+ PCNLAPI_CONFIG.translations.apiShowcase.escapeHTML() +'</h4>'+ info + '</div>'});
281
- }
282
- {
283
- $(prefix + street1).up('li').insert({before: '<li id="' + prefix +'showcase" class="wide"><div class="input-box"><h4 class="pcnl-showcase">'+ PCNLAPI_CONFIG.translations.apiShowcase.escapeHTML() +'</h4>'+ map + info + '</div></li>'});
284
  }
 
285
  }
286
- if (PCNLAPI_CONFIG.debug)
287
- {
288
- if ($(prefix +'debug'))
289
- $(prefix +'debug').remove();
 
 
 
290
 
291
- var info = pcnlapi.getFieldListHtml(json.debugInfo, 'pcnl-debug');
 
 
 
 
 
 
 
 
292
 
293
- if ($(prefix + countryFieldId).parentNode.tagName == 'TD')
294
- {
295
- // We're probably in the admin
296
- $(prefix + street1).up('tr').insert({before: '<tr id="' + prefix + 'debug"><td class="label">'+ PCNLAPI_CONFIG.translations.apiDebug.escapeHTML() +'</label></td><td class="value"><h4 class="pcnl-debug">'+ PCNLAPI_CONFIG.translations.apiDebug.escapeHTML() +'</h4>'+ info + '</td></tr>'});
297
- }
298
- else if ($(prefix + street1).up('div.full'))
299
- {
300
- // For `IDW Free One Page / Step Checkout`
301
- $(prefix + street1).up('div.full').insert({before: '<div id="' + prefix +'debug" class="full"><div class="input-box"><h4 class="pcnl-debug">'+ PCNLAPI_CONFIG.translations.apiDebug.escapeHTML() +'</h4>'+ info + '</div></div>'});
302
- }
303
- else
304
- {
305
- $(prefix + street1).up('li').insert({before: '<li id="' + prefix +'debug" class="wide"><div class="input-box"><h4 class="pcnl-debug">'+ PCNLAPI_CONFIG.translations.apiDebug.escapeHTML() +'</h4>'+ info + '</div></li>'});
306
- }
307
- }
308
 
309
- // Remove any existing error messages
310
- pcnlapi.removeValidationMessages(prefix);
 
 
 
311
 
312
- if (json.postcode != undefined)
313
- {
314
- // Set data from request on form fields
315
- $(prefix + postcodeFieldId).setValue(json.postcode);
316
- $(prefix + 'postcode_input').setValue(json.postcode);
317
- if (PCNLAPI_CONFIG.useStreet2AsHouseNumber && $(prefix + street2))
318
- {
319
- $(prefix + street1).setValue((json.street).trim());
320
- $(prefix + street2).setValue((json.houseNumber +' '+ (json.houseNumberAddition ? json.houseNumberAddition : housenumber_addition)).trim());
321
- }
322
- else
323
- {
324
- $(prefix + street1).setValue((json.street +' '+ json.houseNumber +' '+ (json.houseNumberAddition ? json.houseNumberAddition : housenumber_addition)).trim());
325
- }
326
- $(prefix +'city').setValue(json.city);
327
- if ($(prefix +'region'))
328
- {
329
- $(prefix +'region').setValue(json.province);
330
- }
331
- $(prefix +'postcode_housenumber').setValue(json.houseNumber);
332
 
333
- // Update address result text block
334
- if ($(prefix + 'postcode_output'))
335
- {
336
- pcnlapi.showFields([prefix +'postcode_output']);
337
- $(prefix + 'postcode_output').update((json.street +' '+ json.houseNumber +' '+ (json.houseNumberAddition ? json.houseNumberAddition : housenumber_addition)).trim() + "<br>" + json.postcode + " " + json.city);
338
- }
339
 
340
- // Handle all housenumber addition possiblities
341
- if (json.houseNumberAddition == null && (housenumber_addition_select == housenumber_addition || (housenumber_addition_select == '__none__' && housenumber_addition == '')))
342
- {
343
- // Selected housenumber addition is not known, and the select dropdown already contains that value
 
 
 
 
 
 
 
 
 
 
 
344
 
345
- var additionSelect = pcnlapi.createPostcodeHouseNumberAddition(prefix, postcodeFieldId, countryFieldId, street1, street2, street3, street4, json.houseNumberAdditions, housenumber_addition_select);
 
346
 
347
- // Re-select value if it was selected through the selectbox
348
- if (event && event.element().id == prefix +'postcode_housenumber_addition')
349
- additionSelect.setValue(housenumber_addition_select);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
350
 
351
- if (additionSelect.getValue() != housenumber_addition_select)
352
- {
353
- newAdvice = Validation.createAdvice('invalid-addition', $(prefix +'postcode_housenumber_addition'), false, (housenumber_addition != '' ? PCNLAPI_CONFIG.translations.houseNumberAdditionUnknown.replace('{addition}', housenumber_addition) : PCNLAPI_CONFIG.translations.houseNumberAdditionRequired));
354
- Validation.showAdvice($(prefix +'postcode_housenumber_addition'), newAdvice, 'invalid-addition');
355
- }
356
- }
357
- else if (json.houseNumberAddition == null)
358
- {
359
- // Selected housenumber addition is not known, and the select dropdown does not contain that value
360
 
361
- var additionSelect = pcnlapi.createPostcodeHouseNumberAddition(prefix, postcodeFieldId, countryFieldId, street1, street2, street3, street4, json.houseNumberAdditions, housenumber_addition);
 
 
 
362
 
363
- newAdvice = Validation.createAdvice('invalid-addition', $(prefix +'postcode_housenumber_addition'), false, (housenumber_addition != '' ? PCNLAPI_CONFIG.translations.houseNumberAdditionUnknown.replace('{addition}', housenumber_addition) : PCNLAPI_CONFIG.translations.houseNumberAdditionRequired));
364
- Validation.showAdvice($(prefix +'postcode_housenumber_addition'), newAdvice, 'invalid-addition');
365
- }
366
- else if (json.houseNumberAdditions.length > 1 || (json.houseNumberAdditions.length == 1 && json.houseNumberAdditions[0] != ''))
367
- {
368
- // Address has multiple housenumber additions
369
- var additionSelect = pcnlapi.createPostcodeHouseNumberAddition(prefix, postcodeFieldId, countryFieldId, street1, street2, street3, street4, json.houseNumberAdditions);
370
- additionSelect.setValue(json.houseNumberAddition);
371
- }
372
- else
373
- {
374
- // Address has only one valid addition, and it is the 'no addition' option
375
- pcnlapi.removeHousenumberAddition(prefix);
376
- }
377
- }
378
- else if (json.message != undefined)
379
- {
380
- // Address check returned an error
381
 
382
- newAdvice = Validation.createAdvice('invalid-postcode', $(prefix + (json.messageTarget == 'postcode' ? 'postcode_input' : 'postcode_housenumber')), false, json.message);
383
- Validation.showAdvice($(prefix +'postcode_housenumber'), newAdvice, 'invalid-postcode');
 
384
 
385
- pcnlapi.removeHousenumberAddition(prefix);
386
- }
387
- else
388
  {
389
- // Address check did not return an error or a postcode result (something else wrong)
 
 
 
 
 
 
390
 
391
- newAdvice = Validation.createAdvice('invalid-postcode', $(prefix + (json.messageTarget == 'postcode' ? 'postcode_input' : 'postcode_housenumber')), false, '');
392
- Validation.showAdvice($(prefix +'postcode_housenumber'), newAdvice, 'invalid-postcode');
393
 
394
- pcnlapi.removeHousenumberAddition(prefix);
395
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
396
 
397
- $(prefix + postcodeFieldId).fire('postcode:updated');
 
 
 
 
 
 
 
398
  }
399
- });
 
400
  },
401
 
402
  /**
@@ -439,6 +475,23 @@ document.observe("dom:loaded", function()
439
  }
440
  $(prefix + street1).up('li').insert({before: '<li id="' + prefix + 'postcode_input:output" class="pcnl-hidden-field"><div class="input-box"><label>'+ PCNLAPI_CONFIG.translations.outputLabel +'</label><div id="' + prefix + 'postcode_output" class="pcnl-address-text"></div></div></li>'});
441
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
442
  else if ($(document.body).hasClassName('onestepcheckout-index-index') && $('one-step-checkout-form'))
443
  {
444
  // Support for MageStore One Step Checkout extension
@@ -492,7 +545,7 @@ document.observe("dom:loaded", function()
492
  }
493
  else if ($(document.body).hasClassName('onepagecheckout-index-index'))
494
  {
495
- // IDW Free One Page / Step Checkout
496
 
497
  if (!$(prefix +'postcode_input:info'))
498
  {
@@ -588,32 +641,32 @@ document.observe("dom:loaded", function()
588
  else
589
  {
590
  // Address is not in the Netherlands
591
-
592
  if ($(prefix +'postcode_input_checkbox'))
593
  {
594
  $(prefix +'postcode_input_checkbox').checked = true;
595
  $(prefix +'postcode_input_checkbox').disabled = true;
596
- }
597
 
598
- this.toggleAddressFields(prefix, postcodeFieldId, countryFieldId, street1, street2, street3, street4);
599
 
600
- this.setFieldsReadonly([
601
- prefix +'city',
602
- prefix +'region',
603
- prefix + postcodeFieldId,
604
- prefix + street1,
605
- prefix + street2,
606
- prefix + street3,
607
- prefix + street4,
608
- ], false);
609
 
610
- this.setFieldsReadonly([prefix +'postcode_input', prefix +'postcode_housenumber', prefix +'postcode_housenumber_addition'], true);
611
- this.hideFields([prefix +'postcode_input', prefix +'postcode_housenumber', prefix +'postcode_housenumber_addition']);
612
 
613
- this.showFields([prefix + countryFieldId]);
614
 
615
- if ($(prefix +'showcase'))
616
- Element.remove($(prefix +'showcase'));
 
617
  }
618
  },
619
 
@@ -731,7 +784,7 @@ document.observe("dom:loaded", function()
731
  $(prefix + 'postcode_housenumber').insert({after: '<select title="'+ PCNLAPI_CONFIG.translations.houseNumberAdditionTitle +'" name="'+ prefix + 'postcode_housenumber_addition" id="' + prefix + 'postcode_housenumber_addition" class="validate-select pcnl-input-text-half">'+ options +'</select>'});
732
  if ($(prefix + 'postcode_housenumber').up('div.short'))
733
  {
734
- // IDW checkout module
735
  $(prefix + 'postcode_housenumber').up('div.short').addClassName('pcnl-with-addition');
736
  }
737
  else
@@ -757,9 +810,20 @@ document.observe("dom:loaded", function()
757
  {
758
  if ($('billing:country_id'))
759
  {
760
- $('billing:country_id').observe('change', function () { pcnlapi.toggleCountryPostcode('billing:', 'postcode', 'country_id', 'street1', 'street2', 'street3', 'street4'); });
761
- if (!$('billing:country_id') || $('billing:country_id').getValue() == 'NL')
 
 
 
 
 
 
762
  this.toggleCountryPostcode('billing:', 'postcode', 'country_id', 'street1', 'street2', 'street3', 'street4');
 
 
 
 
 
763
  }
764
  if ($('shipping:country_id'))
765
  {
13
  }
14
 
15
  var PostcodeNl_Api = {
16
+ /**
17
+ * Cache requests to improve multiple identical requests (billing / shipping, etc)
18
+ */
19
+ requestCache: {},
20
+
21
  /**
22
  * Hide multiple field-rows in forms
23
  */
29
  {
30
  if ($(fieldId).up('div.two_fields'))
31
  {
32
+ // For `IWD Free One Page / Step Checkout`
33
  $(fieldId).up('div.two_fields').addClassName('pcnl-hidden-field');
34
  }
35
  else if ($(fieldId).up('div.full'))
36
  {
37
+ // For `IWD Free One Page / Step Checkout`
38
  $(fieldId).up('div.full').addClassName('pcnl-hidden-field');
39
  }
40
  else if ($(fieldId).up('li'))
60
  {
61
  if ($(fieldId).up('div.two_fields'))
62
  {
63
+ // For `IWD Free One Page / Step Checkout`
64
  $(fieldId).up('div.two_fields').removeClassName('pcnl-hidden-field');
65
  }
66
  else if ($(fieldId).up('div.full'))
67
  {
68
+ // For `IWD Free One Page / Step Checkout`
69
  $(fieldId).up('div.full').removeClassName('pcnl-hidden-field');
70
  }
71
  else if ($(fieldId).up('li'))
249
  if ($(prefix + countryFieldId).getValue() != 'NL' || postcode == '' || housenumber_mixed == '')
250
  return;
251
 
252
+ // Make uppercase to prevent double, but identical, requests
253
+ postcode = postcode.toUpperCase();
254
+
255
  var url = PCNLAPI_CONFIG.baseUrl +'lookup?postcode=' + postcode + '&houseNumber=' + housenumber + '&houseNumberAddition=' + housenumber_addition;
256
+ if (typeof this.requestCache[url] === 'undefined')
257
  {
258
+ new Ajax.Request(url,
 
 
 
 
 
259
  {
260
+ method: 'get',
261
+ onException: function(transport, e)
 
262
  {
263
+ throw e;
264
+ },
265
+ onComplete: function(transport)
266
+ {
267
+ var json = transport.responseText.evalJSON();
268
+ if (!PCNLAPI_CONFIG.debug) {
269
+ pcnlapi.requestCache[url] = json;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
270
  }
271
+ pcnlapi.updatePostcodeLookup(json, housenumber_addition, housenumber_addition_select, prefix, postcodeFieldId, countryFieldId, street1, street2, street3, street4, event);
272
  }
273
+ });
274
+ }
275
+ else
276
+ {
277
+ this.updatePostcodeLookup(this.requestCache[url], housenumber_addition, housenumber_addition_select, prefix, postcodeFieldId, countryFieldId, street1, street2, street3, street4, event);
278
+ }
279
+ },
280
 
281
+ /**
282
+ * Update the address fields, given the validated data.
283
+ */
284
+ updatePostcodeLookup: function(data, housenumber_addition, housenumber_addition_select, prefix, postcodeFieldId, countryFieldId, street1, street2, street3, street4, event)
285
+ {
286
+ if (PCNLAPI_CONFIG.showcase)
287
+ {
288
+ if ($(prefix +'showcase'))
289
+ $(prefix +'showcase').remove();
290
 
291
+ var info = this.getFieldListHtml(data.showcaseResponse, 'pcnl-showcase');
 
 
 
 
 
 
 
 
 
 
 
 
 
 
292
 
293
+ var map = '';
294
+ if (data.showcaseResponse.longitude && data.showcaseResponse.latitude)
295
+ {
296
+ map = '<iframe frameborder="0" scrolling="no" marginheight="0" marginwidth="0" class="map" src="http://maps.google.com/maps?t=h&amp;q='+ data.showcaseResponse.latitude +','+ data.showcaseResponse.longitude +'+(Location found)&amp;z=19&amp;output=embed&amp;iwloc=near"></iframe>';
297
+ }
298
 
299
+ if ($(prefix + countryFieldId).parentNode.tagName == 'TD')
300
+ {
301
+ // We're probably in the admin
302
+ $(prefix + street1).up('tr').insert({before: '<tr id="' + prefix + 'showcase"><td class="label">'+ PCNLAPI_CONFIG.translations.apiShowcase.escapeHTML() +'</label></td><td class="value"><h4 class="pcnl-showcase">'+ PCNLAPI_CONFIG.translations.apiShowcase.escapeHTML() +'</h4>'+ info + '</td></tr>'});
303
+ }
304
+ else if ($(prefix + street1).up('div.full'))
305
+ {
306
+ // For `IWD Free One Page / Step Checkout`
307
+ $(prefix + street1).up('div.full').insert({before: '<div id="' + prefix + 'showcase"><h4 class="pcnl-showcase">'+ PCNLAPI_CONFIG.translations.apiShowcase.escapeHTML() +'</h4>'+ info + '</div>'});
308
+ }
309
+ else
310
+ {
311
+ $(prefix + street1).up('li').insert({before: '<li id="' + prefix +'showcase" class="wide"><div class="input-box"><h4 class="pcnl-showcase">'+ PCNLAPI_CONFIG.translations.apiShowcase.escapeHTML() +'</h4>'+ map + info + '</div></li>'});
312
+ }
313
+ }
314
+ if (PCNLAPI_CONFIG.debug)
315
+ {
316
+ if ($(prefix +'debug'))
317
+ $(prefix +'debug').remove();
 
318
 
319
+ var info = this.getFieldListHtml(data.debugInfo, 'pcnl-debug');
 
 
 
 
 
320
 
321
+ if ($(prefix + countryFieldId).parentNode.tagName == 'TD')
322
+ {
323
+ // We're probably in the admin
324
+ $(prefix + street1).up('tr').insert({before: '<tr id="' + prefix + 'debug"><td class="label">'+ PCNLAPI_CONFIG.translations.apiDebug.escapeHTML() +'</label></td><td class="value"><h4 class="pcnl-debug">'+ PCNLAPI_CONFIG.translations.apiDebug.escapeHTML() +'</h4>'+ info + '</td></tr>'});
325
+ }
326
+ else if ($(prefix + street1).up('div.full'))
327
+ {
328
+ // For `IWD Free One Page / Step Checkout`
329
+ $(prefix + street1).up('div.full').insert({before: '<div id="' + prefix +'debug" class="full"><div class="input-box"><h4 class="pcnl-debug">'+ PCNLAPI_CONFIG.translations.apiDebug.escapeHTML() +'</h4>'+ info + '</div></div>'});
330
+ }
331
+ else
332
+ {
333
+ $(prefix + street1).up('li').insert({before: '<li id="' + prefix +'debug" class="wide"><div class="input-box"><h4 class="pcnl-debug">'+ PCNLAPI_CONFIG.translations.apiDebug.escapeHTML() +'</h4>'+ info + '</div></li>'});
334
+ }
335
+ }
336
 
337
+ // Remove any existing error messages
338
+ this.removeValidationMessages(prefix);
339
 
340
+ if (data.postcode != undefined)
341
+ {
342
+ // Set data from request on form fields
343
+ $(prefix + postcodeFieldId).setValue(data.postcode);
344
+ $(prefix + 'postcode_input').setValue(data.postcode);
345
+ if (PCNLAPI_CONFIG.useStreet2AsHouseNumber && $(prefix + street2))
346
+ {
347
+ $(prefix + street1).setValue((data.street).trim());
348
+ $(prefix + street2).setValue((data.houseNumber +' '+ (data.houseNumberAddition ? data.houseNumberAddition : housenumber_addition)).trim());
349
+ }
350
+ else
351
+ {
352
+ $(prefix + street1).setValue((data.street +' '+ data.houseNumber +' '+ (data.houseNumberAddition ? data.houseNumberAddition : housenumber_addition)).trim());
353
+ }
354
+ $(prefix +'city').setValue(data.city);
355
+ if ($(prefix +'region'))
356
+ {
357
+ $(prefix +'region').setValue(data.province);
358
+ }
359
+ $(prefix +'postcode_housenumber').setValue(data.houseNumber);
360
 
361
+ // Update address result text block
362
+ if ($(prefix + 'postcode_output'))
363
+ {
364
+ this.showFields([prefix +'postcode_output']);
365
+ $(prefix + 'postcode_output').update((data.street +' '+ data.houseNumber +' '+ (data.houseNumberAddition ? data.houseNumberAddition : housenumber_addition)).trim() + "<br>" + data.postcode + " " + data.city);
366
+ }
 
 
 
367
 
368
+ // Handle all housenumber addition possiblities
369
+ if (data.houseNumberAddition == null && (housenumber_addition_select == housenumber_addition || (housenumber_addition_select == '__none__' && housenumber_addition == '')))
370
+ {
371
+ // Selected housenumber addition is not known, and the select dropdown already contains that value
372
 
373
+ var additionSelect = this.createPostcodeHouseNumberAddition(prefix, postcodeFieldId, countryFieldId, street1, street2, street3, street4, data.houseNumberAdditions, housenumber_addition_select);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
374
 
375
+ // Re-select value if it was selected through the selectbox
376
+ if (event && event.element().id == prefix +'postcode_housenumber_addition')
377
+ additionSelect.setValue(housenumber_addition_select);
378
 
379
+ if (additionSelect.getValue() != housenumber_addition_select)
 
 
380
  {
381
+ newAdvice = Validation.createAdvice('invalid-addition', $(prefix +'postcode_housenumber_addition'), false, (housenumber_addition != '' ? PCNLAPI_CONFIG.translations.houseNumberAdditionUnknown.replace('{addition}', housenumber_addition) : PCNLAPI_CONFIG.translations.houseNumberAdditionRequired));
382
+ Validation.showAdvice($(prefix +'postcode_housenumber_addition'), newAdvice, 'invalid-addition');
383
+ }
384
+ }
385
+ else if (data.houseNumberAddition == null)
386
+ {
387
+ // Selected housenumber addition is not known, and the select dropdown does not contain that value
388
 
389
+ var additionSelect = this.createPostcodeHouseNumberAddition(prefix, postcodeFieldId, countryFieldId, street1, street2, street3, street4, data.houseNumberAdditions, housenumber_addition);
 
390
 
391
+ newAdvice = Validation.createAdvice('invalid-addition', $(prefix +'postcode_housenumber_addition'), false, (housenumber_addition != '' ? PCNLAPI_CONFIG.translations.houseNumberAdditionUnknown.replace('{addition}', housenumber_addition) : PCNLAPI_CONFIG.translations.houseNumberAdditionRequired));
392
+ Validation.showAdvice($(prefix +'postcode_housenumber_addition'), newAdvice, 'invalid-addition');
393
+ }
394
+ else if (data.houseNumberAdditions.length > 1 || (data.houseNumberAdditions.length == 1 && data.houseNumberAdditions[0] != ''))
395
+ {
396
+ // Address has multiple housenumber additions
397
+ var additionSelect = this.createPostcodeHouseNumberAddition(prefix, postcodeFieldId, countryFieldId, street1, street2, street3, street4, data.houseNumberAdditions);
398
+ additionSelect.setValue(data.houseNumberAddition);
399
+ }
400
+ else
401
+ {
402
+ // Address has only one valid addition, and it is the 'no addition' option
403
+ this.removeHousenumberAddition(prefix);
404
+ }
405
+ }
406
+ else if (data.message != undefined)
407
+ {
408
+ // Address check returned an error
409
+
410
+ newAdvice = Validation.createAdvice('invalid-postcode', $(prefix + (data.messageTarget == 'postcode' ? 'postcode_input' : 'postcode_housenumber')), false, data.message);
411
+ Validation.showAdvice($(prefix +'postcode_housenumber'), newAdvice, 'invalid-postcode');
412
+
413
+ this.removeHousenumberAddition(prefix);
414
+ }
415
+ else
416
+ {
417
+ // Address check did not return an error or a postcode result (something else wrong)
418
+
419
+ newAdvice = Validation.createAdvice('invalid-postcode', $(prefix + (data.messageTarget == 'postcode' ? 'postcode_input' : 'postcode_housenumber')), false, '');
420
+ Validation.showAdvice($(prefix +'postcode_housenumber'), newAdvice, 'invalid-postcode');
421
+
422
+ this.removeHousenumberAddition(prefix);
423
+ }
424
 
425
+ $(prefix + postcodeFieldId).fire('postcode:updated');
426
+
427
+ // Add support for syncing Billing & Shipping
428
+ if (prefix == 'billing:' && $('shipping:' + postcodeFieldId)) {
429
+ if (typeof shipping != 'undefined') {
430
+ if ($('shipping:same_as_billing') && $('shipping:same_as_billing').checked) {
431
+ shipping.syncWithBilling();
432
+ }
433
  }
434
+ this.lookupPostcode('shipping:', postcodeFieldId, countryFieldId, street1, street2, street3, street4);
435
+ }
436
  },
437
 
438
  /**
475
  }
476
  $(prefix + street1).up('li').insert({before: '<li id="' + prefix + 'postcode_input:output" class="pcnl-hidden-field"><div class="input-box"><label>'+ PCNLAPI_CONFIG.translations.outputLabel +'</label><div id="' + prefix + 'postcode_output" class="pcnl-address-text"></div></div></li>'});
477
  }
478
+ else if ($(document.body).hasClassName('onestepcheckout-index-index') && $('co-form'))
479
+ {
480
+ // Support for Apptha One Step Checkout extension
481
+
482
+ if (!$(prefix +'postcode_input:info'))
483
+ {
484
+ $(prefix + street1).up('li').insert({before: '<li id="' + prefix + 'postcode_input:info"><div class="input-box"><label class="pcnl-info-label">'+ PCNLAPI_CONFIG.translations.infoLabel +'</label><div class="pcnl-info-text">'+ PCNLAPI_CONFIG.translations.infoText +'</div></div></li>'});
485
+ }
486
+ $(prefix + street1).up('li').insert({before: '<li id="' + prefix + 'postcode_input:wrapper" class="fields"><div class="pcnl-apptha-fields"><div class="field"><label for="' + prefix + 'postcode_input" class="required">'+ PCNLAPI_CONFIG.translations.postcodeInputLabel +'<em>*</em></label><div class="input-box"><input type="text" title="'+ PCNLAPI_CONFIG.translations.postcodeInputTitle +'" id="' + prefix + 'postcode_input" value="" class="input-text required-entry" /></div></div>'+
487
+ '<div class="field input-postcode pcnl-input-housenumber"><label for="' + prefix + 'postcode_housenumber" class="required">'+ PCNLAPI_CONFIG.translations.houseNumberLabel +' <em>*</em></label><div class="input-box"><input type="text" title="'+ PCNLAPI_CONFIG.translations.houseNumberTitle +'" name="billing[postcode_housenumber]" id="' + prefix + 'postcode_housenumber" value="" class="input-text pcnl-input-text-half required-entry" /></div></div></div></li>'});
488
+ if (!$(prefix +'postcode_input:checkbox'))
489
+ {
490
+ $(prefix + street1).up('li').insert({before: '<li id="' + prefix + 'postcode_input:checkbox" class="pcnl-apptha-checkbox"><div class="field"><div class="input-box"><input type="checkbox" title="'+ PCNLAPI_CONFIG.translations.postcodeInputTitle +'" id="' + prefix + 'postcode_input_checkbox" value="" class="checkbox" /><label for="' + prefix + 'postcode_input_checkbox">'+ PCNLAPI_CONFIG.translations.manualInputText +'</label></div></div></li>'});
491
+ $(prefix +'postcode_input_checkbox').observe('click', function () { pcnlapi.toggleCountryPostcode(prefix, postcodeFieldId, countryFieldId, street1, street2, street3, street4); });
492
+ }
493
+ $(prefix + street1).up('li').insert({before: '<li id="' + prefix + 'postcode_input:output" class="pcnl-hidden-field"><div class="input-box"><label>'+ PCNLAPI_CONFIG.translations.outputLabel +'</label><div id="' + prefix + 'postcode_output" class="pcnl-address-text"></div></div></li>'});
494
+ }
495
  else if ($(document.body).hasClassName('onestepcheckout-index-index') && $('one-step-checkout-form'))
496
  {
497
  // Support for MageStore One Step Checkout extension
545
  }
546
  else if ($(document.body).hasClassName('onepagecheckout-index-index'))
547
  {
548
+ // IWD Free One Page / Step Checkout
549
 
550
  if (!$(prefix +'postcode_input:info'))
551
  {
641
  else
642
  {
643
  // Address is not in the Netherlands
644
+ // Only toggle things if we have already created elements (test for existence of input checkbox)
645
  if ($(prefix +'postcode_input_checkbox'))
646
  {
647
  $(prefix +'postcode_input_checkbox').checked = true;
648
  $(prefix +'postcode_input_checkbox').disabled = true;
 
649
 
650
+ this.toggleAddressFields(prefix, postcodeFieldId, countryFieldId, street1, street2, street3, street4);
651
 
652
+ this.setFieldsReadonly([
653
+ prefix +'city',
654
+ prefix +'region',
655
+ prefix + postcodeFieldId,
656
+ prefix + street1,
657
+ prefix + street2,
658
+ prefix + street3,
659
+ prefix + street4,
660
+ ], false);
661
 
662
+ this.setFieldsReadonly([prefix +'postcode_input', prefix +'postcode_housenumber', prefix +'postcode_housenumber_addition'], true);
663
+ this.hideFields([prefix +'postcode_input', prefix +'postcode_housenumber', prefix +'postcode_housenumber_addition']);
664
 
665
+ this.showFields([prefix + countryFieldId]);
666
 
667
+ if ($(prefix +'showcase'))
668
+ Element.remove($(prefix +'showcase'));
669
+ }
670
  }
671
  },
672
 
784
  $(prefix + 'postcode_housenumber').insert({after: '<select title="'+ PCNLAPI_CONFIG.translations.houseNumberAdditionTitle +'" name="'+ prefix + 'postcode_housenumber_addition" id="' + prefix + 'postcode_housenumber_addition" class="validate-select pcnl-input-text-half">'+ options +'</select>'});
785
  if ($(prefix + 'postcode_housenumber').up('div.short'))
786
  {
787
+ // IWD checkout module
788
  $(prefix + 'postcode_housenumber').up('div.short').addClassName('pcnl-with-addition');
789
  }
790
  else
810
  {
811
  if ($('billing:country_id'))
812
  {
813
+ $('billing:country_id').observe('change', function () {
814
+ pcnlapi.toggleCountryPostcode('billing:', 'postcode', 'country_id', 'street1', 'street2', 'street3', 'street4');
815
+ // Also toggle shipping, because it may be synced 'silently' with billing
816
+ if ($('shipping:country_id')) {
817
+ pcnlapi.toggleCountryPostcode('shipping:', 'postcode', 'country_id', 'street1', 'street2', 'street3', 'street4');
818
+ }
819
+ });
820
+ if (!$('billing:country_id') || $('billing:country_id').getValue() == 'NL') {
821
  this.toggleCountryPostcode('billing:', 'postcode', 'country_id', 'street1', 'street2', 'street3', 'street4');
822
+ if ($('shipping:country_id')) {
823
+ // Also toggle shipping, because it may be synced 'silently' with billing
824
+ this.toggleCountryPostcode('shipping:', 'postcode', 'country_id', 'street1', 'street2', 'street3', 'street4');
825
+ }
826
+ }
827
  }
828
  if ($('shipping:country_id'))
829
  {
package.xml CHANGED
@@ -1,7 +1,7 @@
1
  <?xml version="1.0"?>
2
  <package>
3
  <name>PostcodeNl_Api</name>
4
- <version>1.0.5.0</version>
5
  <stability>stable</stability>
6
  <license>Simplified BSD License</license>
7
  <channel>community</channel>
@@ -16,16 +16,15 @@
16
  &#xD;
17
  The postcode Magento plugin from Postcode.nl is free of charge, based on a Fair-Use policy. The use of the Postcode.nl Magento plugin is subject to our Terms and Conditions.</description>
18
  <notes>Changes:&#xD;
19
- - Better debug feedback for CURL errors&#xD;
20
- - Do not fail when shipping or billing input elements are not present&#xD;
21
- - Better Javascript exception handling in admin&#xD;
22
- - Added support for `IDW Free One Page / Step Checkout`&#xD;
23
- - Added option to always show country-selector&#xD;
24
- - Fix admin functionality to support multi-shops</notes>
25
  <authors><author><name>Postcode.nl Technical Support</name><user>auto-converted</user><email>tech@postcode.nl</email></author></authors>
26
- <date>2012-12-13</date>
27
- <time>13:59:46</time>
28
- <contents><target name="magecommunity"><dir name="PostcodeNl"><dir name="Api"><dir name="Block"><file name="Jsinit.php" hash="79bb826a50ce0cf4f87cc2f958bfafa1"/></dir><dir name="Helper"><file name="Data.php" hash="1dc6157d08029c42ed743ca3a2350a14"/></dir><dir name="controllers"><dir name="Adminhtml"><file name="PcnlController.php" hash="b86f92da28638dfb619b68106523104e"/></dir><file name="JsonController.php" hash="273cdee0eb176860a68dd1788d9fef08"/></dir><dir name="etc"><file name="config.xml" hash="411f537c43bef21561990b95b76ac770"/><file name="system.xml" hash="11a7b7f1d8d7258c90133dfe2581ce00"/></dir></dir></dir></target><target name="magedesign"><dir name="adminhtml"><dir name="default"><dir name="default"><dir name="layout"><dir name="postcodenl"><dir name="api"><file name="lookup.xml" hash="912aa0881de03e5d7bd338a00e783215"/></dir></dir></dir><dir name="template"><dir name="postcodenl"><dir name="api"><file name="jsinit.phtml" hash="e08a3ce7a48801bf997dbd4f6743b53f"/></dir></dir></dir></dir></dir></dir><dir name="frontend"><dir name="default"><dir name="default"><dir name="layout"><dir name="postcodenl"><dir name="api"><file name="lookup.xml" hash="c19ccc1dc60d8e18c00284e4493199a9"/></dir></dir></dir><dir name="template"><dir name="postcodenl"><dir name="api"><file name="jsinit.phtml" hash="339610e5950a53c3966d80cccf9bede4"/></dir></dir></dir></dir></dir></dir></target><target name="magelocale"><dir name="en_US"><file name="PostcodeNl_Api.csv" hash="d8f9ff15eb17aa09a7a40a72aa890095"/></dir><dir name="nl_NL"><file name="PostcodeNl_Api.csv" hash="d196b00bf35dec9fc858b5fc4f9dac9f"/></dir></target><target name="mageweb"><dir name="js"><dir name="postcodenl"><dir name="api"><file name="lookup.js" hash="ead333c7dc834c1bb058f0af9f8cc884"/></dir></dir></dir></target><target name="mageskin"><dir name="adminhtml"><dir name="default"><dir name="default"><dir name="postcodenl"><dir name="api"><dir name="css"><file name="lookup.css" hash="c58103b505f8bcdf55cea1159ca21e27"/></dir><dir name="images"><file name="postcode-logo.png" hash="da02bc29be1057a0201e63f81ee4bd02"/></dir></dir></dir></dir></dir></dir><dir name="frontend"><dir name="default"><dir name="default"><dir name="postcodenl"><dir name="api"><dir name="css"><file name="lookup.css" hash="64ff19e6eae39735d997ac5a73c039cb"/></dir><dir name="images"><file name="postcode-logo.png" hash="da02bc29be1057a0201e63f81ee4bd02"/></dir></dir></dir></dir></dir></dir></target><target name="mageetc"><dir name="modules"><file name="PostcodeNl_Api.xml" hash="feeaf95128ffe4ad109ed8b0b8bc85ab"/></dir></target></contents>
29
  <compatible/>
30
  <dependencies/>
31
  </package>
1
  <?xml version="1.0"?>
2
  <package>
3
  <name>PostcodeNl_Api</name>
4
+ <version>1.0.6.0</version>
5
  <stability>stable</stability>
6
  <license>Simplified BSD License</license>
7
  <channel>community</channel>
16
  &#xD;
17
  The postcode Magento plugin from Postcode.nl is free of charge, based on a Fair-Use policy. The use of the Postcode.nl Magento plugin is subject to our Terms and Conditions.</description>
18
  <notes>Changes:&#xD;
19
+ - Improved support for non-standard/non-default templates&#xD;
20
+ - Fixed bug when switching from non-NL country to non-NL country&#xD;
21
+ - Improved Billing to Shipping synchronization&#xD;
22
+ - Added support for `Apptha One Page Checkout`&#xD;
23
+ - Added support for `Ecommerce Three-Step Checkout`</notes>
 
24
  <authors><author><name>Postcode.nl Technical Support</name><user>auto-converted</user><email>tech@postcode.nl</email></author></authors>
25
+ <date>2013-01-09</date>
26
+ <time>10:08:04</time>
27
+ <contents><target name="magecommunity"><dir name="PostcodeNl"><dir name="Api"><dir name="Block"><file name="Jsinit.php" hash="79bb826a50ce0cf4f87cc2f958bfafa1"/></dir><dir name="Helper"><file name="Data.php" hash="1dc6157d08029c42ed743ca3a2350a14"/></dir><dir name="controllers"><dir name="Adminhtml"><file name="PcnlController.php" hash="b86f92da28638dfb619b68106523104e"/></dir><file name="JsonController.php" hash="273cdee0eb176860a68dd1788d9fef08"/></dir><dir name="etc"><file name="config.xml" hash="89dadeae0873e961437bb5e0046754a2"/><file name="system.xml" hash="11a7b7f1d8d7258c90133dfe2581ce00"/></dir></dir></dir></target><target name="magedesign"><dir name="adminhtml"><dir name="default"><dir name="default"><dir name="layout"><dir name="postcodenl"><dir name="api"><file name="lookup.xml" hash="912aa0881de03e5d7bd338a00e783215"/></dir></dir></dir><dir name="template"><dir name="postcodenl"><dir name="api"><file name="jsinit.phtml" hash="e08a3ce7a48801bf997dbd4f6743b53f"/></dir></dir></dir></dir></dir></dir><dir name="frontend"><dir name="default"><dir name="default"><dir name="layout"><dir name="postcodenl"><dir name="api"><file name="lookup.xml" hash="4b209228600162da76d115d7dda2ea31"/></dir></dir></dir><dir name="template"><dir name="postcodenl"><dir name="api"><file name="jsinit.phtml" hash="339610e5950a53c3966d80cccf9bede4"/></dir></dir></dir></dir></dir></dir></target><target name="magelocale"><dir name="en_US"><file name="PostcodeNl_Api.csv" hash="d8f9ff15eb17aa09a7a40a72aa890095"/></dir><dir name="nl_NL"><file name="PostcodeNl_Api.csv" hash="d196b00bf35dec9fc858b5fc4f9dac9f"/></dir></target><target name="mageweb"><dir name="js"><dir name="postcodenl"><dir name="api"><file name="lookup.js" hash="16f59f70003c8f7abd69d52ea963b149"/></dir></dir></dir></target><target name="mageskin"><dir name="adminhtml"><dir name="default"><dir name="default"><dir name="postcodenl"><dir name="api"><dir name="css"><file name="lookup.css" hash="c58103b505f8bcdf55cea1159ca21e27"/></dir><dir name="images"><file name="postcode-logo.png" hash="da02bc29be1057a0201e63f81ee4bd02"/></dir></dir></dir></dir></dir></dir><dir name="frontend"><dir name="default"><dir name="default"><dir name="postcodenl"><dir name="api"><dir name="css"><file name="lookup.css" hash="4fca81fe07d2e343340025e7f6d462ce"/></dir><dir name="images"><file name="postcode-logo.png" hash="da02bc29be1057a0201e63f81ee4bd02"/></dir></dir></dir></dir></dir></dir></target><target name="mageetc"><dir name="modules"><file name="PostcodeNl_Api.xml" hash="feeaf95128ffe4ad109ed8b0b8bc85ab"/></dir></target></contents>
28
  <compatible/>
29
  <dependencies/>
30
  </package>
skin/frontend/default/default/postcodenl/api/css/lookup.css CHANGED
@@ -129,3 +129,20 @@ body.gomage-checkout-onepage-index .pcnl-info-text {
129
  body.onestepcheckout-index-index #one-step-checkout-form .pcnl-info-text {
130
  width: 78%;
131
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
129
  body.onestepcheckout-index-index #one-step-checkout-form .pcnl-info-text {
130
  width: 78%;
131
  }
132
+
133
+ /* Apptha One Step Checkout */
134
+ body.onestepcheckout-index-index .onepage .form-list .pcnl-apptha-fields .field {
135
+ margin-right: 14px;
136
+ }
137
+ body.onestepcheckout-index-index .onepage .form-list .pcnl-apptha-checkbox .field {
138
+ width: 250px !important
139
+ }
140
+ body.onestepcheckout-index-index .onepage .form-list .pcnl-apptha-checkbox input {
141
+ float: left;
142
+ margin-top: 2px;
143
+ margin-right: 0;
144
+ }
145
+ body.onestepcheckout-index-index .onepage .form-list .pcnl-apptha-checkbox label {
146
+ padding-left: 6px;
147
+ }
148
+