PostcodeNl_Api - Version 1.0.5.0

Version Notes

Changes:
- Better debug feedback for CURL errors
- Do not fail when shipping or billing input elements are not present
- Better Javascript exception handling in admin
- Added support for `IDW Free One Page / Step Checkout`
- Added option to always show country-selector
- Fix admin functionality to support multi-shops

Download this release

Release Info

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


Code changes from version 1.0.4.1 to 1.0.5.0

app/code/community/PostcodeNl/Api/Helper/Data.php CHANGED
@@ -1,4 +1,149 @@
1
  <?php
2
  class PostcodeNl_Api_Helper_Data extends Mage_Core_Helper_Abstract
3
  {
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
4
  }
1
  <?php
2
  class PostcodeNl_Api_Helper_Data extends Mage_Core_Helper_Abstract
3
  {
4
+ const API_TIMEOUT = 3;
5
+
6
+ protected $_modules;
7
+
8
+ protected function _getMagentoVersion()
9
+ {
10
+ if ($this->_getModuleInfo('Enterprise_CatalogPermissions') !== null)
11
+ {
12
+ // Detect enterprise
13
+ return 'MagentoEnterprise/'. Mage::getVersion();
14
+ }
15
+ elseif ($this->_getModuleInfo('Enterprise_Enterprise') !== null)
16
+ {
17
+ // Detect professional
18
+ return 'MagentoProfessional/'. Mage::getVersion();
19
+ }
20
+ else
21
+ {
22
+ // Rest
23
+ return 'Magento/'. Mage::getVersion();
24
+ }
25
+ }
26
+
27
+ protected function _getModuleInfo($moduleName)
28
+ {
29
+ if (!isset($this->_modules))
30
+ $this->_modules = (array)Mage::getConfig()->getNode('modules')->children();
31
+
32
+ if (!isset($this->_modules[$moduleName]))
33
+ return null;
34
+
35
+ return $this->_modules[$moduleName];
36
+ }
37
+
38
+ public function lookupAddress($postcode, $houseNumber, $houseNumberAddition)
39
+ {
40
+ if (!Mage::getStoreConfig('postcodenl/config/enabled'))
41
+ {
42
+ return array('message' => $this->__('Postcode.nl API not enabled.'));
43
+ }
44
+
45
+ $serviceUrl = trim(Mage::getStoreConfig('postcodenl/config/api_url'));
46
+ $serviceKey = trim(Mage::getStoreConfig('postcodenl/config/api_key'));
47
+ $serviceSecret = trim(Mage::getStoreConfig('postcodenl/config/api_secret'));
48
+ $serviceShowcase = Mage::getStoreConfig('postcodenl/config/api_showcase');
49
+ $serviceDebug = Mage::getStoreConfig('postcodenl/config/api_debug');
50
+
51
+ $extensionInfo = $this->_getModuleInfo('PostcodeNl_Api');
52
+ $extensionVersion = $extensionInfo ? (string)$extensionInfo->version : 'unknown';
53
+
54
+ if (!$serviceUrl || !$serviceKey || !$serviceSecret)
55
+ {
56
+ return array('message' => $this->__('Postcode.nl API not configured.'));
57
+ }
58
+
59
+ // Check for SSL support in CURL, if connecting to `https`
60
+ if (substr($serviceUrl, 0, 8) == 'https://')
61
+ {
62
+ $curlVersion = curl_version();
63
+ if (!($curlVersion['features'] & CURL_VERSION_SSL))
64
+ {
65
+ return array('message' => $this->__('Cannot connect to Postcode.nl API: Server is missing SSL (https) support for CURL.'));
66
+ }
67
+ }
68
+
69
+ $url = $serviceUrl . '/rest/addresses/' . urlencode($postcode). '/'. urlencode($houseNumber) . '/'. urlencode($houseNumberAddition);
70
+ $ch = curl_init();
71
+ curl_setopt($ch, CURLOPT_URL, $url);
72
+ curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
73
+ curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, self::API_TIMEOUT);
74
+ curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_ANY);
75
+ curl_setopt($ch, CURLOPT_USERPWD, $serviceKey .':'. $serviceSecret);
76
+ curl_setopt($ch, CURLOPT_USERAGENT, 'PostcodeNl_Api_MagentoPlugin/' . $extensionVersion .' '. $this->_getMagentoVersion());
77
+ $jsonResponse = curl_exec($ch);
78
+ $curlError = curl_error($ch);
79
+ curl_close($ch);
80
+
81
+ $response = json_decode($jsonResponse, true);
82
+
83
+ $sendResponse = array();
84
+ if ($serviceShowcase)
85
+ $sendResponse['showcaseResponse'] = $response;
86
+
87
+ if ($serviceDebug)
88
+ {
89
+ $modules = array();
90
+ foreach (Mage::getConfig()->getNode('modules')->children() as $name => $module)
91
+ {
92
+ $modules[$name] = array();
93
+ foreach ($module as $key => $value)
94
+ {
95
+ if (in_array((string)$key, array('active')))
96
+ $modules[$name][$key] = (string)$value == 'true' ? true : false;
97
+ else if (in_array((string)$key, array('codePool', 'version')))
98
+ $modules[$name][$key] = (string)$value;
99
+ }
100
+ }
101
+
102
+ $sendResponse['debugInfo'] = array(
103
+ 'requestUrl' => $url,
104
+ 'rawResponse' => $jsonResponse,
105
+ 'parsedResponse' => $response,
106
+ 'curlError' => $curlError,
107
+ 'configuration' => array(
108
+ 'url' => $serviceUrl,
109
+ 'key' => $serviceKey,
110
+ 'secret' => substr($serviceSecret, 0, 6) .'[hidden]',
111
+ 'showcase' => $serviceShowcase,
112
+ 'debug' => $serviceDebug,
113
+ ),
114
+ 'magentoVersion' => $this->_getMagentoVersion(),
115
+ 'extensionVersion' => $extensionVersion,
116
+ 'modules' => $modules,
117
+ );
118
+ }
119
+
120
+ if (is_array($response) && isset($response['exceptionId']))
121
+ {
122
+ switch ($response['exceptionId'])
123
+ {
124
+ case 'PostcodeNl_Controller_Address_InvalidPostcodeException':
125
+ $sendResponse['message'] = $this->__('Invalid postcode format, use `1234AB` format.');
126
+ $sendResponse['messageTarget'] = 'postcode';
127
+ break;
128
+ case 'PostcodeNl_Service_PostcodeAddress_AddressNotFoundException':
129
+ $sendResponse['message'] = $this->__('Unknown postcode + housenumber combination.');
130
+ $sendResponse['messageTarget'] = 'housenumber';
131
+ break;
132
+ default:
133
+ $sendResponse['message'] = $this->__('Validation error, please use manual input.');
134
+ $sendResponse['messageTarget'] = 'housenumber';
135
+ break;
136
+ }
137
+ }
138
+ else if (is_array($response) && isset($response['postcode']))
139
+ {
140
+ $sendResponse = array_merge($sendResponse, $response);
141
+ }
142
+ else
143
+ {
144
+ $sendResponse['message'] = $this->__('Validation unavailable, please use manual input.');
145
+ $sendResponse['messageTarget'] = 'housenumber';
146
+ }
147
+ return $sendResponse;
148
+ }
149
  }
app/code/community/PostcodeNl/Api/controllers/Adminhtml/PcnlController.php ADDED
@@ -0,0 +1,11 @@
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ class PostcodeNl_Api_Adminhtml_PcnlController extends Mage_Adminhtml_Controller_Action
3
+ {
4
+ public function lookupAction()
5
+ {
6
+ $helper = new PostcodeNl_Api_Helper_Data();
7
+
8
+ $this->getResponse()->setHeader('Content-type', 'application/json');
9
+ $this->getResponse()->setBody(json_encode($helper->lookupAddress($_GET['postcode'], $_GET['houseNumber'], $_GET['houseNumberAddition'])));
10
+ }
11
+ }
app/code/community/PostcodeNl/Api/controllers/JsonController.php CHANGED
@@ -1,140 +1,10 @@
1
  <?php
2
  class PostcodeNl_Api_JsonController extends Mage_Core_Controller_Front_Action
3
  {
4
- const API_TIMEOUT = 3;
5
-
6
- protected $_modules;
7
-
8
- protected function _getMagentoVersion()
9
- {
10
- if ($this->_getModuleInfo('Enterprise_CatalogPermissions') !== null)
11
- {
12
- // Detect enterprise
13
- return 'MagentoEnterprise/'. Mage::getVersion();
14
- }
15
- elseif ($this->_getModuleInfo('Enterprise_Enterprise') !== null)
16
- {
17
- // Detect professional
18
- return 'MagentoProfessional/'. Mage::getVersion();
19
- }
20
- else
21
- {
22
- // Rest
23
- return 'Magento/'. Mage::getVersion();
24
- }
25
- }
26
-
27
- protected function _getModuleInfo($moduleName)
28
- {
29
- if (!isset($this->_modules))
30
- $this->_modules = (array)Mage::getConfig()->getNode('modules')->children();
31
-
32
- if (!isset($this->_modules[$moduleName]))
33
- return null;
34
-
35
- return $this->_modules[$moduleName];
36
- }
37
-
38
  public function lookupAction()
39
  {
40
- if (!Mage::getStoreConfig('postcodenl/config/enabled'))
41
- {
42
- echo json_encode(array('message' => $this->__('Postcode.nl API not enabled.')));
43
- return;
44
- }
45
-
46
- $serviceUrl = trim(Mage::getStoreConfig('postcodenl/config/api_url'));
47
- $serviceKey = trim(Mage::getStoreConfig('postcodenl/config/api_key'));
48
- $serviceSecret = trim(Mage::getStoreConfig('postcodenl/config/api_secret'));
49
- $serviceShowcase = Mage::getStoreConfig('postcodenl/config/api_showcase');
50
- $serviceDebug = Mage::getStoreConfig('postcodenl/config/api_debug');
51
-
52
- $extensionInfo = $this->_getModuleInfo('PostcodeNl_Api');
53
- $extensionVersion = $extensionInfo ? (string)$extensionInfo->version : 'unknown';
54
-
55
- if (!$serviceUrl || !$serviceKey || !$serviceSecret)
56
- {
57
- echo json_encode(array('message' => $this->__('Postcode.nl API not configured.')));
58
- return;
59
- }
60
-
61
- $url = $serviceUrl . '/rest/addresses/' . urlencode($_GET['postcode']). '/'. urlencode($_GET['houseNumber']) . '/'. urlencode($_GET['houseNumberAddition']);
62
- $ch = curl_init();
63
- curl_setopt($ch, CURLOPT_URL, $url);
64
- curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
65
- curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, self::API_TIMEOUT);
66
- curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_ANY);
67
- curl_setopt($ch, CURLOPT_USERPWD, $serviceKey .':'. $serviceSecret);
68
- curl_setopt($ch, CURLOPT_USERAGENT, 'PostcodeNl_Api_MagentoPlugin/' . $extensionVersion .' '. $this->_getMagentoVersion());
69
- $jsonResponse = curl_exec($ch);
70
- curl_close($ch);
71
-
72
- $response = json_decode($jsonResponse, true);
73
-
74
- $sendResponse = array();
75
- if ($serviceShowcase)
76
- $sendResponse['showcaseResponse'] = $response;
77
-
78
- if ($serviceDebug)
79
- {
80
- $modules = array();
81
- foreach (Mage::getConfig()->getNode('modules')->children() as $name => $module)
82
- {
83
- $modules[$name] = array();
84
- foreach ($module as $key => $value)
85
- {
86
- if (in_array((string)$key, array('active')))
87
- $modules[$name][$key] = (string)$value == 'true' ? true : false;
88
- else if (in_array((string)$key, array('codePool', 'version')))
89
- $modules[$name][$key] = (string)$value;
90
- }
91
- }
92
-
93
- $sendResponse['debugInfo'] = array(
94
- 'requestUrl' => $url,
95
- 'rawResponse' => $jsonResponse,
96
- 'parsedResponse' => $response,
97
- 'curlError' => curl_error($ch),
98
- 'configuration' => array(
99
- 'url' => $serviceUrl,
100
- 'key' => $serviceKey,
101
- 'secret' => substr($serviceSecret, 0, 6) .'[hidden]',
102
- 'showcase' => $serviceShowcase,
103
- 'debug' => $serviceDebug,
104
- ),
105
- 'magentoVersion' => $this->_getMagentoVersion(),
106
- 'extensionVersion' => $extensionVersion,
107
- 'modules' => $modules,
108
- );
109
- }
110
-
111
- if (is_array($response) && isset($response['exceptionId']))
112
- {
113
- switch ($response['exceptionId'])
114
- {
115
- case 'PostcodeNl_Controller_Address_InvalidPostcodeException':
116
- $sendResponse['message'] = $this->__('Invalid postcode format, use `1234AB` format.');
117
- $sendResponse['messageTarget'] = 'postcode';
118
- break;
119
- case 'PostcodeNl_Service_PostcodeAddress_AddressNotFoundException':
120
- $sendResponse['message'] = $this->__('Unknown postcode + housenumber combination.');
121
- $sendResponse['messageTarget'] = 'housenumber';
122
- break;
123
- default:
124
- $sendResponse['message'] = $this->__('Validation error, please use manual input.');
125
- $sendResponse['messageTarget'] = 'housenumber';
126
- break;
127
- }
128
- }
129
- else if (is_array($response) && isset($response['postcode']))
130
- {
131
- $sendResponse = array_merge($sendResponse, $response);
132
- }
133
- else
134
- {
135
- $sendResponse['message'] = $this->__('Validation unavailable, please use manual input.');
136
- $sendResponse['messageTarget'] = 'housenumber';
137
- }
138
- echo json_encode($sendResponse);
139
  }
140
  }
1
  <?php
2
  class PostcodeNl_Api_JsonController extends Mage_Core_Controller_Front_Action
3
  {
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
4
  public function lookupAction()
5
  {
6
+ $helper = new PostcodeNl_Api_Helper_Data();
7
+ echo json_encode($helper->lookupAddress($_GET['postcode'], $_GET['houseNumber'], $_GET['houseNumberAddition']));
8
+ return;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
9
  }
10
  }
app/code/community/PostcodeNl/Api/etc/config.xml CHANGED
@@ -2,7 +2,7 @@
2
  <config>
3
  <modules>
4
  <PostcodeNl_Api>
5
- <version>1.0.4.1</version>
6
  </PostcodeNl_Api>
7
  </modules>
8
  <frontend>
@@ -32,6 +32,17 @@
32
  </modules>
33
  </translate>
34
  </frontend>
 
 
 
 
 
 
 
 
 
 
 
35
  <global>
36
  <helpers>
37
  <postcodenl>
@@ -88,6 +99,7 @@
88
  <postcodenl>
89
  <config>
90
  <enabled>1</enabled>
 
91
  <api_secret></api_secret>
92
  <api_url>https://api.postcode.nl</api_url>
93
  <api_key></api_key>
2
  <config>
3
  <modules>
4
  <PostcodeNl_Api>
5
+ <version>1.0.5.0</version>
6
  </PostcodeNl_Api>
7
  </modules>
8
  <frontend>
32
  </modules>
33
  </translate>
34
  </frontend>
35
+ <admin>
36
+ <routers>
37
+ <adminhtml>
38
+ <args>
39
+ <modules>
40
+ <postcodenlnl before="Mage_Adminhtml">PostcodeNl_Api_Adminhtml</postcodenlnl>
41
+ </modules>
42
+ </args>
43
+ </adminhtml>
44
+ </routers>
45
+ </admin>
46
  <global>
47
  <helpers>
48
  <postcodenl>
99
  <postcodenl>
100
  <config>
101
  <enabled>1</enabled>
102
+ <never_hide_country>0</never_hide_country>
103
  <api_secret></api_secret>
104
  <api_url>https://api.postcode.nl</api_url>
105
  <api_key></api_key>
app/code/community/PostcodeNl/Api/etc/system.xml CHANGED
@@ -69,6 +69,20 @@
69
  If you use the second 'street' field as a separate house-number field, enable this option.
70
  ]]></comment>
71
  </use_street2_as_housenumber>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
72
  <api_showcase translate="label">
73
  <label>Enable API Showcase</label>
74
  <frontend_type>select</frontend_type>
@@ -79,8 +93,8 @@
79
  <show_in_store>1</show_in_store>
80
  <comment>
81
  <![CDATA[
82
- By enabling this option, you will see what additional information the Postcode.nl API has to offer, every time your information is enriched.
83
- (this is not recommended in production environments)
84
  ]]></comment>
85
  </api_showcase>
86
  <api_debug translate="label">
@@ -93,8 +107,8 @@
93
  <show_in_store>1</show_in_store>
94
  <comment>
95
  <![CDATA[
96
- Additional debug information used for trouble-shooting will be sent by the Postcode.nl API extension.
97
- (this is not recommended in production environments!)
98
  ]]></comment>
99
  </api_debug>
100
  </fields>
69
  If you use the second 'street' field as a separate house-number field, enable this option.
70
  ]]></comment>
71
  </use_street2_as_housenumber>
72
+ <never_hide_country translate="label">
73
+ <label>Never hide country selector</label>
74
+ <frontend_type>select</frontend_type>
75
+ <source_model>adminhtml/system_config_source_yesno</source_model>
76
+ <sort_order>47</sort_order>
77
+ <show_in_default>1</show_in_default>
78
+ <show_in_website>1</show_in_website>
79
+ <show_in_store>1</show_in_store>
80
+ <comment>
81
+ <![CDATA[
82
+ For webshops with a more international audience, do not hide the country selector when in validation mode.
83
+ <b>Note</b>: This only works for checkout pages / extensions, which have the country selector in a seperate row. (does not work with the default Magento checkout page)
84
+ ]]></comment>
85
+ </never_hide_country>
86
  <api_showcase translate="label">
87
  <label>Enable API Showcase</label>
88
  <frontend_type>select</frontend_type>
93
  <show_in_store>1</show_in_store>
94
  <comment>
95
  <![CDATA[
96
+ By enabling this option, you will see what additional information the Postcode.nl API has to offer, every time your information is enriched.<br />
97
+ <em>(this is not recommended in production environments!)</em>
98
  ]]></comment>
99
  </api_showcase>
100
  <api_debug translate="label">
107
  <show_in_store>1</show_in_store>
108
  <comment>
109
  <![CDATA[
110
+ Additional debug information used for trouble-shooting will be sent by the Postcode.nl API extension.<br />
111
+ <em>(this is not recommended in production environments!)</em>
112
  ]]></comment>
113
  </api_debug>
114
  </fields>
app/design/adminhtml/default/default/template/postcodenl/api/jsinit.phtml CHANGED
@@ -1,11 +1,12 @@
1
  <script type="text/javascript">
2
  //<![CDATA[
3
  var PCNLAPI_CONFIG = {
4
- baseUrl: "<?php echo htmlspecialchars(Mage::getUrl('', array('_secure' => true))) ?>",
5
  showcase: <?php echo Mage::getStoreConfig('postcodenl/config/api_showcase') ? 'true' : 'false' ?>,
6
  debug: <?php echo Mage::getStoreConfig('postcodenl/config/api_debug') ? 'true' : 'false' ?>,
7
  useStreet2AsHouseNumber: <?php echo Mage::getStoreConfig('postcodenl/config/use_street2_as_housenumber') ? 'true' : 'false' ?>,
8
  adminValidationDisabled: <?php echo Mage::getStoreConfig('postcodenl/config/admin_validation_disabled') ? 'true' : 'false' ?>,
 
9
  translations: {
10
  defaultError: "<?php echo htmlspecialchars($this->__('Unknown postcode + housenumber combination.')) ?>",
11
  postcodeInputLabel: "<?php echo htmlspecialchars($this->__('Postcode (auto-validating)')) ?>",
1
  <script type="text/javascript">
2
  //<![CDATA[
3
  var PCNLAPI_CONFIG = {
4
+ baseUrl: "<?php echo htmlspecialchars(Mage::helper('adminhtml')->getUrl('*/pcnl/lookup', array('_secure' => true))) ?>",
5
  showcase: <?php echo Mage::getStoreConfig('postcodenl/config/api_showcase') ? 'true' : 'false' ?>,
6
  debug: <?php echo Mage::getStoreConfig('postcodenl/config/api_debug') ? 'true' : 'false' ?>,
7
  useStreet2AsHouseNumber: <?php echo Mage::getStoreConfig('postcodenl/config/use_street2_as_housenumber') ? 'true' : 'false' ?>,
8
  adminValidationDisabled: <?php echo Mage::getStoreConfig('postcodenl/config/admin_validation_disabled') ? 'true' : 'false' ?>,
9
+ neverHideCountry: <?php echo Mage::getStoreConfig('postcodenl/config/never_hide_country') ? 'true' : 'false' ?>,
10
  translations: {
11
  defaultError: "<?php echo htmlspecialchars($this->__('Unknown postcode + housenumber combination.')) ?>",
12
  postcodeInputLabel: "<?php echo htmlspecialchars($this->__('Postcode (auto-validating)')) ?>",
app/design/frontend/default/default/layout/postcodenl/api/lookup.xml CHANGED
@@ -9,6 +9,15 @@
9
  <block type="postcodenl/jsinit" name="postcodenl.jsinit" template="postcodenl/api/jsinit.phtml" />
10
  </reference>
11
  </checkout_onepage_index>
 
 
 
 
 
 
 
 
 
12
  <checkout_multishipping_register>
13
  <reference name="head">
14
  <action method="addCss" ifconfig="postcodenl/config/enabled"><script>postcodenl/api/css/lookup.css</script></action>
@@ -55,6 +64,7 @@
55
  <block type="postcodenl/jsinit" name="postcodenl.jsinit" template="postcodenl/api/jsinit.phtml" />
56
  </reference>
57
  </onestepcheckout_index_index>
 
58
  <gomage_checkout_onepage_index>
59
  <reference name="head">
60
  <action method="addCss" ifconfig="postcodenl/config/enabled"><script>postcodenl/api/css/lookup.css</script></action>
@@ -64,6 +74,7 @@
64
  <block type="postcodenl/jsinit" name="postcodenl.jsinit" template="postcodenl/api/jsinit.phtml" />
65
  </reference>
66
  </gomage_checkout_onepage_index>
 
67
  <firecheckout_onepage_index>
68
  <reference name="head">
69
  <action method="addCss" ifconfig="postcodenl/config/enabled"><script>postcodenl/api/css/lookup.css</script></action>
@@ -83,7 +94,8 @@
83
  <block type="postcodenl/jsinit" name="postcodenl.jsinit" template="postcodenl/api/jsinit.phtml" />
84
  </reference>
85
  </checkout_onestep_index>
86
- <customer_address_form>
 
87
  <reference name="head">
88
  <action method="addCss" ifconfig="postcodenl/config/enabled"><script>postcodenl/api/css/lookup.css</script></action>
89
  <action method="addJs" ifconfig="postcodenl/config/enabled"><script>postcodenl/api/lookup.js</script></action>
@@ -91,5 +103,5 @@
91
  <reference name="content">
92
  <block type="postcodenl/jsinit" name="postcodenl.jsinit" template="postcodenl/api/jsinit.phtml" />
93
  </reference>
94
- </customer_address_form>
95
  </layout>
9
  <block type="postcodenl/jsinit" name="postcodenl.jsinit" template="postcodenl/api/jsinit.phtml" />
10
  </reference>
11
  </checkout_onepage_index>
12
+ <customer_address_form>
13
+ <reference name="head">
14
+ <action method="addCss" ifconfig="postcodenl/config/enabled"><script>postcodenl/api/css/lookup.css</script></action>
15
+ <action method="addJs" ifconfig="postcodenl/config/enabled"><script>postcodenl/api/lookup.js</script></action>
16
+ </reference>
17
+ <reference name="content">
18
+ <block type="postcodenl/jsinit" name="postcodenl.jsinit" template="postcodenl/api/jsinit.phtml" />
19
+ </reference>
20
+ </customer_address_form>
21
  <checkout_multishipping_register>
22
  <reference name="head">
23
  <action method="addCss" ifconfig="postcodenl/config/enabled"><script>postcodenl/api/css/lookup.css</script></action>
64
  <block type="postcodenl/jsinit" name="postcodenl.jsinit" template="postcodenl/api/jsinit.phtml" />
65
  </reference>
66
  </onestepcheckout_index_index>
67
+ <!-- For `GoMage LightCheckout` -->
68
  <gomage_checkout_onepage_index>
69
  <reference name="head">
70
  <action method="addCss" ifconfig="postcodenl/config/enabled"><script>postcodenl/api/css/lookup.css</script></action>
74
  <block type="postcodenl/jsinit" name="postcodenl.jsinit" template="postcodenl/api/jsinit.phtml" />
75
  </reference>
76
  </gomage_checkout_onepage_index>
77
+ <!-- For `Fire Checkout` -->
78
  <firecheckout_onepage_index>
79
  <reference name="head">
80
  <action method="addCss" ifconfig="postcodenl/config/enabled"><script>postcodenl/api/css/lookup.css</script></action>
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>
101
  <action method="addJs" ifconfig="postcodenl/config/enabled"><script>postcodenl/api/lookup.js</script></action>
103
  <reference name="content">
104
  <block type="postcodenl/jsinit" name="postcodenl.jsinit" template="postcodenl/api/jsinit.phtml" />
105
  </reference>
106
+ </onepagecheckout_index_index>
107
  </layout>
app/design/frontend/default/default/template/postcodenl/api/jsinit.phtml CHANGED
@@ -1,11 +1,12 @@
1
  <script type="text/javascript">
2
  //<![CDATA[
3
  var PCNLAPI_CONFIG = {
4
- baseUrl: "<?php echo htmlspecialchars(Mage::getUrl('', array('_secure' => true))) ?>",
5
  showcase: <?php echo Mage::getStoreConfig('postcodenl/config/api_showcase') ? 'true' : 'false' ?>,
6
  debug: <?php echo Mage::getStoreConfig('postcodenl/config/api_debug') ? 'true' : 'false' ?>,
7
  useStreet2AsHouseNumber: <?php echo Mage::getStoreConfig('postcodenl/config/use_street2_as_housenumber') ? 'true' : 'false' ?>,
8
  adminValidationDisabled: <?php echo Mage::getStoreConfig('postcodenl/config/admin_validation_disabled') ? 'true' : 'false' ?>,
 
9
  translations: {
10
  defaultError: "<?php echo htmlspecialchars($this->__('Unknown postcode + housenumber combination.')) ?>",
11
  postcodeInputLabel: "<?php echo htmlspecialchars($this->__('Postcode')) ?>",
1
  <script type="text/javascript">
2
  //<![CDATA[
3
  var PCNLAPI_CONFIG = {
4
+ baseUrl: "<?php echo htmlspecialchars(Mage::getUrl('postcodenl/json', array('_secure' => true))) ?>",
5
  showcase: <?php echo Mage::getStoreConfig('postcodenl/config/api_showcase') ? 'true' : 'false' ?>,
6
  debug: <?php echo Mage::getStoreConfig('postcodenl/config/api_debug') ? 'true' : 'false' ?>,
7
  useStreet2AsHouseNumber: <?php echo Mage::getStoreConfig('postcodenl/config/use_street2_as_housenumber') ? 'true' : 'false' ?>,
8
  adminValidationDisabled: <?php echo Mage::getStoreConfig('postcodenl/config/admin_validation_disabled') ? 'true' : 'false' ?>,
9
+ neverHideCountry: <?php echo Mage::getStoreConfig('postcodenl/config/never_hide_country') ? 'true' : 'false' ?>,
10
  translations: {
11
  defaultError: "<?php echo htmlspecialchars($this->__('Unknown postcode + housenumber combination.')) ?>",
12
  postcodeInputLabel: "<?php echo htmlspecialchars($this->__('Postcode')) ?>",
app/locale/en_US/PostcodeNl_Api.csv CHANGED
@@ -4,6 +4,7 @@
4
  "Invalid postcode format, use `1234AB` format.","Invalid postcode format, use `1234AB` format."
5
  "Validation error, please use manual input.","Validation error, please use manual input."
6
  "Validation unavailable, please use manual input.","Validation unavailable, please use manual input."
 
7
  "Postcode","Postcode"
8
  "Postcode (auto-validating)","Postcode (auto-validating)"
9
  "Housenumber","Housenumber"
4
  "Invalid postcode format, use `1234AB` format.","Invalid postcode format, use `1234AB` format."
5
  "Validation error, please use manual input.","Validation error, please use manual input."
6
  "Validation unavailable, please use manual input.","Validation unavailable, please use manual input."
7
+ "Cannot connect to Postcode.nl API: Server is missing SSL (https) support for CURL.","Cannot connect to Postcode.nl API: Server is missing SSL (https) support for CURL."
8
  "Postcode","Postcode"
9
  "Postcode (auto-validating)","Postcode (auto-validating)"
10
  "Housenumber","Housenumber"
app/locale/nl_NL/PostcodeNl_Api.csv CHANGED
@@ -4,6 +4,7 @@
4
  "Invalid postcode format, use `1234AB` format.","Onbekend postcode formaat, gebruik het `1234AB` formaat."
5
  "Validation error, please use manual input.","Validatie fout, gebruik de handmatige invoer."
6
  "Validation unavailable, please use manual input.","Validatie onbereikbaar, gebruik de handmatige invoer."
 
7
  "Postcode","Postcode"
8
  "Postcode (auto-validating)","Postcode (automatisch validerend)"
9
  "Housenumber","Huisnummer"
@@ -17,7 +18,7 @@
17
  "Postcode.nl API not configured.","Postcode.nl API niet configureerd."
18
  "Postcode.nl API not enabled.","Postcode.nl API niet ingeschakeld."
19
  "- disabled -","- uitgeschakeld -"
20
- "Address validation","Adres validatie"
21
  "Fill out your postcode and housenumber to auto-complete your address. You can also manually set your address information.","Vul uw postcode en huisnummer in en uw adres wordt automatisch en foutloos aangevuld. Handmatig invullen kan natuurlijk ook."
22
  "Manual input","Handmatige invoer"
23
  "Fill out address information manually","Handmatig adres invullen"
4
  "Invalid postcode format, use `1234AB` format.","Onbekend postcode formaat, gebruik het `1234AB` formaat."
5
  "Validation error, please use manual input.","Validatie fout, gebruik de handmatige invoer."
6
  "Validation unavailable, please use manual input.","Validatie onbereikbaar, gebruik de handmatige invoer."
7
+ "Cannot connect to Postcode.nl API: Server is missing SSL (https) support for CURL.","Kan geen connectie maken naar Postcode.nl API: Server mist SSL (https) ondersteuning voor CURL."
8
  "Postcode","Postcode"
9
  "Postcode (auto-validating)","Postcode (automatisch validerend)"
10
  "Housenumber","Huisnummer"
18
  "Postcode.nl API not configured.","Postcode.nl API niet configureerd."
19
  "Postcode.nl API not enabled.","Postcode.nl API niet ingeschakeld."
20
  "- disabled -","- uitgeschakeld -"
21
+ "Address validation","Adresvalidatie"
22
  "Fill out your postcode and housenumber to auto-complete your address. You can also manually set your address information.","Vul uw postcode en huisnummer in en uw adres wordt automatisch en foutloos aangevuld. Handmatig invullen kan natuurlijk ook."
23
  "Manual input","Handmatige invoer"
24
  "Fill out address information manually","Handmatig adres invullen"
js/postcodenl/api/lookup.js CHANGED
@@ -22,7 +22,17 @@ document.observe("dom:loaded", function()
22
  {
23
  if ($(fieldId))
24
  {
25
- if ($(fieldId).up('li'))
 
 
 
 
 
 
 
 
 
 
26
  {
27
  $(fieldId).up('li').addClassName('pcnl-hidden-field');
28
  }
@@ -43,7 +53,17 @@ document.observe("dom:loaded", function()
43
  {
44
  if ($(fieldId))
45
  {
46
- if ($(fieldId).up('li'))
 
 
 
 
 
 
 
 
 
 
47
  {
48
  $(fieldId).up('li').removeClassName('pcnl-hidden-field');
49
  }
@@ -224,10 +244,14 @@ document.observe("dom:loaded", function()
224
  if ($(prefix + countryFieldId).getValue() != 'NL' || postcode == '' || housenumber_mixed == '')
225
  return;
226
 
227
- var url = PCNLAPI_CONFIG.baseUrl +'postcodenl/json/lookup?postcode=' + postcode + '&houseNumber=' + housenumber + '&houseNumberAddition=' + housenumber_addition;
228
  new Ajax.Request(url,
229
  {
230
  method: 'get',
 
 
 
 
231
  onComplete: function(transport)
232
  {
233
  var json = transport.responseText.evalJSON();
@@ -250,7 +274,11 @@ document.observe("dom:loaded", function()
250
  // We're probably in the admin
251
  $(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>'});
252
  }
253
- else
 
 
 
 
254
  {
255
  $(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>'});
256
  }
@@ -267,6 +295,11 @@ document.observe("dom:loaded", function()
267
  // We're probably in the admin
268
  $(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>'});
269
  }
 
 
 
 
 
270
  else
271
  {
272
  $(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>'});
@@ -291,7 +324,10 @@ document.observe("dom:loaded", function()
291
  $(prefix + street1).setValue((json.street +' '+ json.houseNumber +' '+ (json.houseNumberAddition ? json.houseNumberAddition : housenumber_addition)).trim());
292
  }
293
  $(prefix +'city').setValue(json.city);
294
- $(prefix +'region').setValue(json.province);
 
 
 
295
  $(prefix +'postcode_housenumber').setValue(json.houseNumber);
296
 
297
  // Update address result text block
@@ -454,6 +490,33 @@ document.observe("dom:loaded", function()
454
  }
455
  $(prefix + street1).up('li').insert({before: '<li id="' + prefix + 'postcode_input:output" class="pcnl-hidden-field d_3"><div class="input-box"><label>'+ PCNLAPI_CONFIG.translations.outputLabel +'</label><div id="' + prefix + 'postcode_output" class="pcnl-address-text"></div></div></li>'});
456
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
457
  else
458
  {
459
  // Support for regular Magento 'one page' checkout
@@ -481,68 +544,14 @@ document.observe("dom:loaded", function()
481
  this.showFields([prefix +'postcode_input', prefix +'postcode_housenumber', prefix +'postcode_housenumber_addition'])
482
  }
483
 
484
- if (!$(prefix + 'postcode_input_checkbox').checked)
485
- {
486
- this.setFieldsReadonly([
487
- prefix + postcodeFieldId,
488
- prefix + street1,
489
- prefix + street2,
490
- prefix + street3,
491
- prefix + street4,
492
- prefix + 'city',
493
- prefix + 'region',
494
- ], true);
495
- this.hideFields([
496
- prefix + postcodeFieldId,
497
- prefix + street1,
498
- prefix + street2,
499
- prefix + street3,
500
- prefix + street4,
501
- prefix + 'city',
502
- prefix + 'region',
503
- prefix + countryFieldId,
504
- ]);
505
-
506
- // Set empty, will be corrected below
507
- $(prefix +'postcode_input').value = '';
508
- $(prefix +'postcode_housenumber').value = '';
509
- this.setFieldsReadonly([prefix +'postcode_input', prefix + 'postcode_housenumber', prefix + 'postcode_housenumber_addition'], false);
510
- if ($(prefix +'postcode_output') && $(prefix +'postcode_output').innerHTML != '')
511
- {
512
- this.showFields([prefix +'postcode_output']);
513
- }
514
- }
515
- else
516
  {
517
- this.removeValidationMessages(prefix);
518
-
519
- this.setFieldsReadonly([
520
- prefix + postcodeFieldId,
521
- prefix + street1,
522
- prefix + street2,
523
- prefix + street3,
524
- prefix + street4,
525
- prefix + 'city',
526
- prefix + 'region',
527
- ], false);
528
- this.showFields([
529
- prefix + postcodeFieldId,
530
- prefix + street1,
531
- prefix + street2,
532
- prefix + street3,
533
- prefix + street4,
534
- prefix + 'city',
535
- prefix + 'region',
536
- prefix + countryFieldId,
537
- ]);
538
-
539
- // Disable fields
540
- $(prefix +'postcode_input').setValue(PCNLAPI_CONFIG.translations.disabledText);
541
- $(prefix +'postcode_housenumber').setValue(PCNLAPI_CONFIG.translations.disabledText);
542
- this.setFieldsReadonly([prefix +'postcode_input', prefix + 'postcode_housenumber', prefix + 'postcode_housenumber_addition'], true);
543
- this.hideFields([prefix +'postcode_output']);
544
  }
545
-
546
  // We're in NL, checkbox is enabled
547
  $(prefix + 'postcode_input_checkbox').disabled = false;
548
 
@@ -586,6 +595,8 @@ document.observe("dom:loaded", function()
586
  $(prefix +'postcode_input_checkbox').disabled = true;
587
  }
588
 
 
 
589
  this.setFieldsReadonly([
590
  prefix +'city',
591
  prefix +'region',
@@ -599,11 +610,86 @@ document.observe("dom:loaded", function()
599
  this.setFieldsReadonly([prefix +'postcode_input', prefix +'postcode_housenumber', prefix +'postcode_housenumber_addition'], true);
600
  this.hideFields([prefix +'postcode_input', prefix +'postcode_housenumber', prefix +'postcode_housenumber_addition']);
601
 
 
 
602
  if ($(prefix +'showcase'))
603
  Element.remove($(prefix +'showcase'));
604
  }
605
  },
606
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
607
  /**
608
  * (re)Create the postcode housenumber addition dropdown select box.
609
  */
@@ -643,7 +729,16 @@ document.observe("dom:loaded", function()
643
  {
644
  // We're probably in the frontend
645
  $(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>'});
646
- $(prefix + 'postcode_housenumber').up('li').addClassName('pcnl-with-addition');
 
 
 
 
 
 
 
 
 
647
  }
648
 
649
  $(prefix +'postcode_housenumber_addition').observe('change', function(e) { pcnlapi.lookupPostcode(prefix, postcodeFieldId, countryFieldId, street1, street2, street3, street4, e); });
@@ -660,24 +755,34 @@ document.observe("dom:loaded", function()
660
  // 'Normal' Checkout pages (OneStepCheckout, Magento Default)
661
  if ($('billing:postcode'))
662
  {
663
- $('billing:country_id').observe('change', function () { pcnlapi.toggleCountryPostcode('billing:', 'postcode', 'country_id', 'street1', 'street2', 'street3', 'street4'); });
664
- $('shipping:country_id').observe('change', function () { pcnlapi.toggleCountryPostcode('shipping:', 'postcode', 'country_id', 'street1', 'street2', 'street3', 'street4'); });
665
-
666
- if (!$('billing:country_id') || $('billing:country_id').getValue() == 'NL')
667
- this.toggleCountryPostcode('billing:', 'postcode', 'country_id', 'street1', 'street2', 'street3', 'street4');
668
- if (!$('shipping:country_id') || $('shipping:country_id').getValue() == 'NL')
669
- this.toggleCountryPostcode('shipping:', 'postcode', 'country_id', 'street1', 'street2', 'street3', 'street4');
 
 
 
 
 
670
  }
671
  // GoMage LightCheckout
672
  if ($('billing_postcode'))
673
  {
674
- $('billing_country_id').observe('change', function () { pcnlapi.toggleCountryPostcode('billing_', 'postcode', 'country_id', 'street1', 'street2', 'street3', 'street4'); });
675
- $('shipping_country_id').observe('change', function () { pcnlapi.toggleCountryPostcode('shipping_', 'postcode', 'country_id', 'street1', 'street2', 'street3', 'street4'); });
676
-
677
- if (!$('billing_country_id') || $('billing_country_id').getValue() == 'NL')
678
- this.toggleCountryPostcode('billing_', 'postcode', 'country_id', 'street1', 'street2', 'street3', 'street4');
679
- if (!$('shipping_country_id') || $('shipping_country_id').getValue() == 'NL')
680
- this.toggleCountryPostcode('shipping_', 'postcode', 'country_id', 'street1', 'street2', 'street3', 'street4');
 
 
 
 
 
681
  }
682
 
683
  // Misc. account address edits
@@ -723,8 +828,10 @@ document.observe("dom:loaded", function()
723
  this.observeShippingAddress();
724
 
725
  // Re-observe blocks after they have been changed
726
- $('order-billing_address').observe('DOMNodeInserted', function(e) { pcnlapi.observeBillingAddress(); });
727
- $('order-shipping_address').observe('DOMNodeInserted', function(e) { pcnlapi.observeShippingAddress(); });
 
 
728
  }
729
  },
730
  observeAdminCustomerAddress: function ()
22
  {
23
  if ($(fieldId))
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'))
36
  {
37
  $(fieldId).up('li').addClassName('pcnl-hidden-field');
38
  }
53
  {
54
  if ($(fieldId))
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'))
67
  {
68
  $(fieldId).up('li').removeClassName('pcnl-hidden-field');
69
  }
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();
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
  }
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>'});
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
490
  }
491
  $(prefix + street1).up('li').insert({before: '<li id="' + prefix + 'postcode_input:output" class="pcnl-hidden-field d_3"><div class="input-box"><label>'+ PCNLAPI_CONFIG.translations.outputLabel +'</label><div id="' + prefix + 'postcode_output" class="pcnl-address-text"></div></div></li>'});
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
+ {
499
+ $(prefix + street1).up('div.full').insert({before: '<div id="' + prefix + 'postcode_input:info" class="full"><div><label class="pcnl-info-label">'+ PCNLAPI_CONFIG.translations.infoLabel +'</label><div class="pcnl-info-text">'+ PCNLAPI_CONFIG.translations.infoText +'</div></div></div>'});
500
+ }
501
+ $(prefix + street1).up('div.full').insert({before: '<div id="' + prefix + 'postcode_input:wrapper" class="two_fields"><div class="input-postcode short"><label for="' + prefix + 'postcode_input" class="required">'+ PCNLAPI_CONFIG.translations.postcodeInputLabel +'</label> <sup>*</sup><div class="data_area"><input type="text" title="'+ PCNLAPI_CONFIG.translations.postcodeInputTitle +'" id="' + prefix + 'postcode_input" value="" class="t1 required-entry" /></div></div>' +
502
+ '<div class="input-postcode pcnl-input-housenumber short"><label for="' + prefix + 'postcode_housenumber" class="required">'+ PCNLAPI_CONFIG.translations.houseNumberLabel +'</label> <sup>*</sup><div><input type="text" title="'+ PCNLAPI_CONFIG.translations.houseNumberTitle +'" name="billing[postcode_housenumber]" id="' + prefix + 'postcode_housenumber" value="" class="t1 pcnl-input-text-half required-entry" /></div></div></div>'});
503
+ if (!$(prefix +'postcode_input:checkbox'))
504
+ {
505
+ $(prefix + street1).up('div.full').insert({before: '<ul id="' + prefix + 'postcode_input:checkbox" class="pcnl-manual-checkbox"><li class="options"><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></li></ul>'});
506
+ $(prefix + 'postcode_input_checkbox').observe('click', function () { pcnlapi.toggleCountryPostcode(prefix, postcodeFieldId, countryFieldId, street1, street2, street3, street4); });
507
+ }
508
+ $(prefix + street1).up('div.full').insert({before: '<div id="' + prefix + 'postcode_input:output" class="full pcnl-hidden-field"><label>'+ PCNLAPI_CONFIG.translations.outputLabel +'</label><div class="data_area"><div id="' + prefix + 'postcode_output" class="pcnl-address-text"></div></div></div>'});
509
+
510
+ // Relocate telephone field, if it exists
511
+ if ($(prefix + 'telephone'))
512
+ {
513
+ var clone = $(prefix + 'telephone').up('div.short').clone(true);
514
+ $(prefix + 'telephone').up('div.short').remove();
515
+ // Move to after country selector
516
+ $(prefix + countryFieldId).up('div.full').insert({after: '<div class="two_fields" id="'+prefix + 'telephone-moved"></div><div class="clr"></div>'});
517
+ $(prefix + 'telephone-moved').insert(clone);
518
+ }
519
+ }
520
  else
521
  {
522
  // Support for regular Magento 'one page' checkout
544
  this.showFields([prefix +'postcode_input', prefix +'postcode_housenumber', prefix +'postcode_housenumber_addition'])
545
  }
546
 
547
+ this.toggleAddressFields(prefix, postcodeFieldId, countryFieldId, street1, street2, street3, street4);
548
+
549
+ // Previous value was not NL, switch manual off
550
+ if ($(prefix + 'postcode_input_checkbox').disabled)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
551
  {
552
+ $(prefix +'postcode_input_checkbox').checked = false;
553
+ this.toggleAddressFields(prefix, postcodeFieldId, countryFieldId, street1, street2, street3, street4);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
554
  }
 
555
  // We're in NL, checkbox is enabled
556
  $(prefix + 'postcode_input_checkbox').disabled = false;
557
 
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',
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
 
620
+ /**
621
+ * Toggle address field visibility, to be in line with the value of the 'manual input' checkbox.
622
+ */
623
+ toggleAddressFields: function(prefix, postcodeFieldId, countryFieldId, street1, street2, street3, street4, values)
624
+ {
625
+ if (!$(prefix + 'postcode_input_checkbox').checked)
626
+ {
627
+ this.setFieldsReadonly([
628
+ prefix + postcodeFieldId,
629
+ prefix + street1,
630
+ prefix + street2,
631
+ prefix + street3,
632
+ prefix + street4,
633
+ prefix + 'city',
634
+ prefix + 'region',
635
+ ], true);
636
+ this.hideFields([
637
+ prefix + postcodeFieldId,
638
+ prefix + street1,
639
+ prefix + street2,
640
+ prefix + street3,
641
+ prefix + street4,
642
+ prefix + 'city',
643
+ prefix + 'region',
644
+
645
+ ]);
646
+ if (!PCNLAPI_CONFIG.neverHideCountry)
647
+ {
648
+ this.hideFields([prefix + countryFieldId]);
649
+ }
650
+
651
+ // Set empty, will be corrected later
652
+ $(prefix +'postcode_input').value = '';
653
+ $(prefix +'postcode_housenumber').value = '';
654
+
655
+ this.setFieldsReadonly([prefix +'postcode_input', prefix + 'postcode_housenumber', prefix + 'postcode_housenumber_addition'], false);
656
+ if ($(prefix +'postcode_output') && $(prefix +'postcode_output').innerHTML != '')
657
+ {
658
+ this.showFields([prefix +'postcode_output']);
659
+ }
660
+ }
661
+ else
662
+ {
663
+ this.removeValidationMessages(prefix);
664
+
665
+ this.setFieldsReadonly([
666
+ prefix + postcodeFieldId,
667
+ prefix + street1,
668
+ prefix + street2,
669
+ prefix + street3,
670
+ prefix + street4,
671
+ prefix + 'city',
672
+ prefix + 'region',
673
+ ], false);
674
+ this.showFields([
675
+ prefix + postcodeFieldId,
676
+ prefix + street1,
677
+ prefix + street2,
678
+ prefix + street3,
679
+ prefix + street4,
680
+ prefix + 'city',
681
+ prefix + 'region',
682
+ prefix + countryFieldId,
683
+ ]);
684
+
685
+ // Disable fields
686
+ $(prefix +'postcode_input').setValue(PCNLAPI_CONFIG.translations.disabledText);
687
+ $(prefix +'postcode_housenumber').setValue(PCNLAPI_CONFIG.translations.disabledText);
688
+ this.setFieldsReadonly([prefix +'postcode_input', prefix + 'postcode_housenumber', prefix + 'postcode_housenumber_addition'], true);
689
+ this.hideFields([prefix +'postcode_output']);
690
+ }
691
+ },
692
+
693
  /**
694
  * (re)Create the postcode housenumber addition dropdown select box.
695
  */
729
  {
730
  // We're probably in the frontend
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
738
+ {
739
+ // Other checkout modules
740
+ $(prefix + 'postcode_housenumber').up('li').addClassName('pcnl-with-addition');
741
+ }
742
  }
743
 
744
  $(prefix +'postcode_housenumber_addition').observe('change', function(e) { pcnlapi.lookupPostcode(prefix, postcodeFieldId, countryFieldId, street1, street2, street3, street4, e); });
755
  // 'Normal' Checkout pages (OneStepCheckout, Magento Default)
756
  if ($('billing:postcode'))
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
+ {
766
+ $('shipping:country_id').observe('change', function () { pcnlapi.toggleCountryPostcode('shipping:', 'postcode', 'country_id', 'street1', 'street2', 'street3', 'street4'); });
767
+ if (!$('shipping:country_id') || $('shipping:country_id').getValue() == 'NL')
768
+ this.toggleCountryPostcode('shipping:', 'postcode', 'country_id', 'street1', 'street2', 'street3', 'street4');
769
+ }
770
  }
771
  // GoMage LightCheckout
772
  if ($('billing_postcode'))
773
  {
774
+ if ($('billing:country_id'))
775
+ {
776
+ $('billing_country_id').observe('change', function () { pcnlapi.toggleCountryPostcode('billing_', 'postcode', 'country_id', 'street1', 'street2', 'street3', 'street4'); });
777
+ if (!$('billing_country_id') || $('billing_country_id').getValue() == 'NL')
778
+ this.toggleCountryPostcode('billing_', 'postcode', 'country_id', 'street1', 'street2', 'street3', 'street4');
779
+ }
780
+ if ($('shipping:country_id'))
781
+ {
782
+ $('shipping_country_id').observe('change', function () { pcnlapi.toggleCountryPostcode('shipping_', 'postcode', 'country_id', 'street1', 'street2', 'street3', 'street4'); });
783
+ if (!$('shipping_country_id') || $('shipping_country_id').getValue() == 'NL')
784
+ this.toggleCountryPostcode('shipping_', 'postcode', 'country_id', 'street1', 'street2', 'street3', 'street4');
785
+ }
786
  }
787
 
788
  // Misc. account address edits
828
  this.observeShippingAddress();
829
 
830
  // Re-observe blocks after they have been changed
831
+ if ($('order-billing_address'))
832
+ $('order-billing_address').observe('DOMNodeInserted', function(e) { pcnlapi.observeBillingAddress(); });
833
+ if ($('order-shipping_address'))
834
+ $('order-shipping_address').observe('DOMNodeInserted', function(e) { pcnlapi.observeShippingAddress(); });
835
  }
836
  },
837
  observeAdminCustomerAddress: function ()
package.xml CHANGED
@@ -1,7 +1,7 @@
1
  <?xml version="1.0"?>
2
  <package>
3
  <name>PostcodeNl_Api</name>
4
- <version>1.0.4.1</version>
5
  <stability>stable</stability>
6
  <license>Simplified BSD License</license>
7
  <channel>community</channel>
@@ -16,11 +16,16 @@
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
- - Fixed a bug where some house numbers with no addition were not accepted as valid by Magento</notes>
 
 
 
 
 
20
  <authors><author><name>Postcode.nl Technical Support</name><user>auto-converted</user><email>tech@postcode.nl</email></author></authors>
21
- <date>2012-11-27</date>
22
- <time>14:07:30</time>
23
- <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="86d092299190f0c57ef73e9432278306"/></dir><dir name="controllers"><file name="JsonController.php" hash="884545e1c26207d86cd7683b60974a0e"/></dir><dir name="etc"><file name="config.xml" hash="89fb3b3af634348c5596d6e271f298a1"/><file name="system.xml" hash="c971d989e8bcf61b9316b666639844c7"/></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="2f8be9e6192b0d0ef02e9188bf0214c7"/></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="44e3f5799f64c34fc57f182949d672f0"/></dir></dir></dir><dir name="template"><dir name="postcodenl"><dir name="api"><file name="jsinit.phtml" hash="362e94a70a0b38e4bf8e3fafdf315aac"/></dir></dir></dir></dir></dir></dir></target><target name="magelocale"><dir name="en_US"><file name="PostcodeNl_Api.csv" hash="87b46a0e02dfc0ed616878d7a79b1bec"/></dir><dir name="nl_NL"><file name="PostcodeNl_Api.csv" hash="9f04e27805e115526e49bb06b360cdf4"/></dir></target><target name="mageweb"><dir name="js"><dir name="postcodenl"><dir name="api"><file name="lookup.js" hash="182b95e1319e574070a85b8d8af2ad1d"/></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>
24
  <compatible/>
25
  <dependencies/>
26
  </package>
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
  &#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>