Version Notes
Improved compatibility.
Download this release
Release Info
Developer | Magento Core Team |
Extension | PostcodeNl_Api |
Version | 1.0.1.0 |
Comparing to | |
See all releases |
Version 1.0.1.0
- app/code/community/PostcodeNl/Api/Block/Jsinit.php +13 -0
- app/code/community/PostcodeNl/Api/Helper/Data.php +4 -0
- app/code/community/PostcodeNl/Api/controllers/JsonController.php +66 -0
- app/code/community/PostcodeNl/Api/etc/config.xml +98 -0
- app/code/community/PostcodeNl/Api/etc/system.xml +78 -0
- app/design/adminhtml/default/default/layout/postcodenl/api/lookup.xml +39 -0
- app/design/adminhtml/default/default/template/postcodenl/api/jsinit.phtml +24 -0
- app/design/frontend/default/default/layout/postcodenl/api/lookup.xml +21 -0
- app/design/frontend/default/default/template/postcodenl/api/jsinit.phtml +24 -0
- app/etc/modules/PostcodeNl_Api.xml +9 -0
- app/locale/en_US/PostcodeNl_Api.csv +13 -0
- app/locale/nl_NL/PostcodeNl_Api.csv +13 -0
- js/postcodenl/api/lookup.js +372 -0
- package.xml +25 -0
- skin/adminhtml/default/default/postcodenl/api/css/lookup.css +30 -0
- skin/adminhtml/default/default/postcodenl/api/images/postcode-logo.png +0 -0
- skin/frontend/default/default/postcodenl/api/css/lookup.css +43 -0
- skin/frontend/default/default/postcodenl/api/images/postcode-logo.png +0 -0
app/code/community/PostcodeNl/Api/Block/Jsinit.php
ADDED
@@ -0,0 +1,13 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
class PostcodeNl_Api_Block_Jsinit extends Mage_Core_Block_Template
|
3 |
+
{
|
4 |
+
protected function _toHtml()
|
5 |
+
{
|
6 |
+
if (is_link(dirname(Mage::getModuleDir('', 'PostcodeNl_Api'))) && !Mage::getStoreConfig('dev/template/allow_symlink'))
|
7 |
+
{
|
8 |
+
throw new Mage_Core_Exception('Postcode.nl API Development: Symlinks not enabled! (set at Admin->System->Configuration->Advanced->Developer->Template Settings)');
|
9 |
+
}
|
10 |
+
|
11 |
+
return parent::_toHtml();
|
12 |
+
}
|
13 |
+
}
|
app/code/community/PostcodeNl/Api/Helper/Data.php
ADDED
@@ -0,0 +1,4 @@
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
class PostcodeNl_Api_Helper_Data extends Mage_Core_Helper_Abstract
|
3 |
+
{
|
4 |
+
}
|
app/code/community/PostcodeNl/Api/controllers/JsonController.php
ADDED
@@ -0,0 +1,66 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
class PostcodeNl_Api_JsonController extends Mage_Core_Controller_Front_Action
|
3 |
+
{
|
4 |
+
const API_TIMEOUT = 3;
|
5 |
+
|
6 |
+
public function lookupAction()
|
7 |
+
{
|
8 |
+
if (!Mage::getStoreConfig('postcodenl/config/enabled'))
|
9 |
+
{
|
10 |
+
echo json_encode(array('message' => $this->__('Postcode.nl API not enabled.')));
|
11 |
+
return;
|
12 |
+
}
|
13 |
+
|
14 |
+
$serviceUrl = Mage::getStoreConfig('postcodenl/config/api_url');
|
15 |
+
$serviceKey = Mage::getStoreConfig('postcodenl/config/api_key');
|
16 |
+
$serviceSecret = Mage::getStoreConfig('postcodenl/config/api_secret');
|
17 |
+
$serviceShowcase = Mage::getStoreConfig('postcodenl/config/api_showcase');
|
18 |
+
|
19 |
+
if (!$serviceUrl || !$serviceKey || !$serviceSecret)
|
20 |
+
{
|
21 |
+
echo json_encode(array('message' => $this->__('Postcode.nl API not configured.')));
|
22 |
+
return;
|
23 |
+
}
|
24 |
+
|
25 |
+
$url = $serviceUrl . '/rest/addresses/' . urlencode($_GET['postcode']). '/'. urlencode($_GET['houseNumber']) . '/'. urlencode($_GET['houseNumberAddition']);
|
26 |
+
$ch = curl_init();
|
27 |
+
curl_setopt($ch, CURLOPT_URL, $url);
|
28 |
+
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
|
29 |
+
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, self::API_TIMEOUT);
|
30 |
+
curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_ANY);
|
31 |
+
curl_setopt($ch, CURLOPT_USERPWD, $serviceKey .':'.$serviceSecret);
|
32 |
+
$jsonResponse = curl_exec($ch);
|
33 |
+
curl_close($ch);
|
34 |
+
|
35 |
+
$response = json_decode($jsonResponse, true);
|
36 |
+
|
37 |
+
if ($serviceShowcase)
|
38 |
+
{
|
39 |
+
echo $jsonResponse;
|
40 |
+
}
|
41 |
+
else
|
42 |
+
{
|
43 |
+
if (is_array($response) && isset($response['exceptionId']))
|
44 |
+
{
|
45 |
+
switch ($response['exceptionId'])
|
46 |
+
{
|
47 |
+
case 'PostcodeNl_Service_PostcodeAddress_NotFoundException':
|
48 |
+
echo json_encode(array('message' => $this->__('Unknown postcode + housenumber combination.')));
|
49 |
+
break;
|
50 |
+
default:
|
51 |
+
echo json_encode(array('message' => $this->__('Validation failed.')));
|
52 |
+
break;
|
53 |
+
}
|
54 |
+
}
|
55 |
+
else if (is_array($response) && isset($response['postcode']))
|
56 |
+
{
|
57 |
+
echo $jsonResponse;
|
58 |
+
}
|
59 |
+
else
|
60 |
+
{
|
61 |
+
echo json_encode(array('message' => $this->__('Validation failed.')));
|
62 |
+
}
|
63 |
+
}
|
64 |
+
}
|
65 |
+
|
66 |
+
}
|
app/code/community/PostcodeNl/Api/etc/config.xml
ADDED
@@ -0,0 +1,98 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?xml version="1.0"?>
|
2 |
+
<config>
|
3 |
+
<modules>
|
4 |
+
<PostcodeNl_Api>
|
5 |
+
<version>1.0.0.0</version>
|
6 |
+
</PostcodeNl_Api>
|
7 |
+
</modules>
|
8 |
+
<frontend>
|
9 |
+
<routers>
|
10 |
+
<postcodenl>
|
11 |
+
<use>standard</use>
|
12 |
+
<args>
|
13 |
+
<module>PostcodeNl_Api</module>
|
14 |
+
<frontName>postcodenl</frontName>
|
15 |
+
</args>
|
16 |
+
</postcodenl>
|
17 |
+
</routers>
|
18 |
+
<layout>
|
19 |
+
<updates>
|
20 |
+
<postcodenl>
|
21 |
+
<file>postcodenl/api/lookup.xml</file>
|
22 |
+
</postcodenl>
|
23 |
+
</updates>
|
24 |
+
</layout>
|
25 |
+
<translate>
|
26 |
+
<modules>
|
27 |
+
<postcodenl>
|
28 |
+
<files>
|
29 |
+
<default>PostcodeNl_Api.csv</default>
|
30 |
+
</files>
|
31 |
+
</postcodenl>
|
32 |
+
</modules>
|
33 |
+
</translate>
|
34 |
+
</frontend>
|
35 |
+
<global>
|
36 |
+
<helpers>
|
37 |
+
<postcodenl>
|
38 |
+
<class>PostcodeNl_Api_Helper</class>
|
39 |
+
</postcodenl>
|
40 |
+
</helpers>
|
41 |
+
<blocks>
|
42 |
+
<postcodenl>
|
43 |
+
<class>PostcodeNl_Api_Block</class>
|
44 |
+
</postcodenl>
|
45 |
+
</blocks>
|
46 |
+
</global>
|
47 |
+
<adminhtml>
|
48 |
+
<acl>
|
49 |
+
<all>
|
50 |
+
<title>Allow Everything</title>
|
51 |
+
</all>
|
52 |
+
<resources>
|
53 |
+
<admin>
|
54 |
+
<children>
|
55 |
+
<system>
|
56 |
+
<children>
|
57 |
+
<config>
|
58 |
+
<children>
|
59 |
+
<postcodenl translate="title" module="postcodenl">
|
60 |
+
<title>Postcode.nl API</title>
|
61 |
+
</postcodenl>
|
62 |
+
</children>
|
63 |
+
</config>
|
64 |
+
</children>
|
65 |
+
</system>
|
66 |
+
</children>
|
67 |
+
</admin>
|
68 |
+
</resources>
|
69 |
+
</acl>
|
70 |
+
<layout>
|
71 |
+
<updates>
|
72 |
+
<postcodenl>
|
73 |
+
<file>postcodenl/api/lookup.xml</file>
|
74 |
+
</postcodenl>
|
75 |
+
</updates>
|
76 |
+
</layout>
|
77 |
+
<translate>
|
78 |
+
<modules>
|
79 |
+
<postcodenl>
|
80 |
+
<files>
|
81 |
+
<default>PostcodeNl_Api.csv</default>
|
82 |
+
</files>
|
83 |
+
</postcodenl>
|
84 |
+
</modules>
|
85 |
+
</translate>
|
86 |
+
</adminhtml>
|
87 |
+
<default>
|
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>
|
94 |
+
<api_showcase>0</api_showcase>
|
95 |
+
</config>
|
96 |
+
</postcodenl>
|
97 |
+
</default>
|
98 |
+
</config>
|
app/code/community/PostcodeNl/Api/etc/system.xml
ADDED
@@ -0,0 +1,78 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?xml version="1.0"?>
|
2 |
+
<config>
|
3 |
+
<sections>
|
4 |
+
<postcodenl translate="label" module="postcodenl">
|
5 |
+
<label>Postcode.nl API</label>
|
6 |
+
<tab>sales</tab>
|
7 |
+
<frontend_type>text</frontend_type>
|
8 |
+
<sort_order>340</sort_order>
|
9 |
+
<show_in_default>1</show_in_default>
|
10 |
+
<show_in_website>1</show_in_website>
|
11 |
+
<show_in_store>1</show_in_store>
|
12 |
+
<groups>
|
13 |
+
<config translate="label">
|
14 |
+
<label>Configuration</label>
|
15 |
+
<frontend_type>text</frontend_type>
|
16 |
+
<sort_order>10</sort_order>
|
17 |
+
<show_in_default>1</show_in_default>
|
18 |
+
<show_in_website>1</show_in_website>
|
19 |
+
<show_in_store>1</show_in_store>
|
20 |
+
<fields>
|
21 |
+
<enabled translate="label">
|
22 |
+
<label>Enabled?</label>
|
23 |
+
<frontend_type>select</frontend_type>
|
24 |
+
<source_model>adminhtml/system_config_source_yesno</source_model>
|
25 |
+
<sort_order>10</sort_order>
|
26 |
+
<show_in_default>1</show_in_default>
|
27 |
+
<show_in_website>1</show_in_website>
|
28 |
+
<show_in_store>1</show_in_store>
|
29 |
+
</enabled>
|
30 |
+
<api_url translate="label">
|
31 |
+
<label>API URL</label>
|
32 |
+
<frontend_type>text</frontend_type>
|
33 |
+
<sort_order>20</sort_order>
|
34 |
+
<show_in_default>1</show_in_default>
|
35 |
+
<show_in_website>1</show_in_website>
|
36 |
+
<show_in_store>1</show_in_store>
|
37 |
+
<validate>validate-url</validate>
|
38 |
+
</api_url>
|
39 |
+
<api_key translate="label">
|
40 |
+
<label>API key</label>
|
41 |
+
<frontend_type>text</frontend_type>
|
42 |
+
<sort_order>30</sort_order>
|
43 |
+
<show_in_default>1</show_in_default>
|
44 |
+
<show_in_website>1</show_in_website>
|
45 |
+
<show_in_store>1</show_in_store>
|
46 |
+
</api_key>
|
47 |
+
<api_secret translate="label">
|
48 |
+
<label>API secret</label>
|
49 |
+
<frontend_type>text</frontend_type>
|
50 |
+
<sort_order>40</sort_order>
|
51 |
+
<show_in_default>1</show_in_default>
|
52 |
+
<show_in_website>1</show_in_website>
|
53 |
+
<show_in_store>1</show_in_store>
|
54 |
+
<comment>
|
55 |
+
<![CDATA[
|
56 |
+
To get your Postcode.nl API key and secret, please register at <a href="https://api.postcode.nl">Postcode.nl API</a>.
|
57 |
+
]]></comment>
|
58 |
+
</api_secret>
|
59 |
+
<api_showcase translate="label">
|
60 |
+
<label>Enable API Showcase</label>
|
61 |
+
<frontend_type>select</frontend_type>
|
62 |
+
<source_model>adminhtml/system_config_source_yesno</source_model>
|
63 |
+
<sort_order>50</sort_order>
|
64 |
+
<show_in_default>1</show_in_default>
|
65 |
+
<show_in_website>1</show_in_website>
|
66 |
+
<show_in_store>1</show_in_store>
|
67 |
+
<comment>
|
68 |
+
<![CDATA[
|
69 |
+
By enabling this option, you will see what additional information the Postcode.nl API has to offer, every time your information is enriched.
|
70 |
+
(this is not recommended in production environments)
|
71 |
+
]]></comment>
|
72 |
+
</api_showcase>
|
73 |
+
</fields>
|
74 |
+
</config>
|
75 |
+
</groups>
|
76 |
+
</postcodenl>
|
77 |
+
</sections>
|
78 |
+
</config>
|
app/design/adminhtml/default/default/layout/postcodenl/api/lookup.xml
ADDED
@@ -0,0 +1,39 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?xml version="1.0"?>
|
2 |
+
<layout version="0.1.0">
|
3 |
+
<adminhtml_sales_order_address>
|
4 |
+
<reference name="head">
|
5 |
+
<action method="addCss" ifconfig="postcodenl/config/enabled"><script>postcodenl/api/css/lookup.css</script></action>
|
6 |
+
<action method="addJs" ifconfig="postcodenl/config/enabled"><script>postcodenl/api/lookup.js</script></action>
|
7 |
+
</reference>
|
8 |
+
<reference name="content">
|
9 |
+
<block type="postcodenl/jsinit" name="postcodenl.jsinit" template="postcodenl/api/jsinit.phtml" />
|
10 |
+
</reference>
|
11 |
+
</adminhtml_sales_order_address>
|
12 |
+
<adminhtml_sales_order_create_index>
|
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="js">
|
18 |
+
<block type="postcodenl/jsinit" name="postcodenl.jsinit" template="postcodenl/api/jsinit.phtml" />
|
19 |
+
</reference>
|
20 |
+
</adminhtml_sales_order_create_index>
|
21 |
+
<adminhtml_sales_order_edit_index>
|
22 |
+
<reference name="head">
|
23 |
+
<action method="addCss" ifconfig="postcodenl/config/enabled"><script>postcodenl/api/css/lookup.css</script></action>
|
24 |
+
<action method="addJs" ifconfig="postcodenl/config/enabled"><script>postcodenl/api/lookup.js</script></action>
|
25 |
+
</reference>
|
26 |
+
<reference name="js">
|
27 |
+
<block type="postcodenl/jsinit" name="postcodenl.jsinit" template="postcodenl/api/jsinit.phtml" />
|
28 |
+
</reference>
|
29 |
+
</adminhtml_sales_order_edit_index>
|
30 |
+
<adminhtml_customer_edit>
|
31 |
+
<reference name="head">
|
32 |
+
<action method="addCss" ifconfig="postcodenl/config/enabled"><script>postcodenl/api/css/lookup.css</script></action>
|
33 |
+
<action method="addJs" ifconfig="postcodenl/config/enabled"><script>postcodenl/api/lookup.js</script></action>
|
34 |
+
</reference>
|
35 |
+
<reference name="js">
|
36 |
+
<block type="postcodenl/jsinit" name="postcodenl.jsinit" template="postcodenl/api/jsinit.phtml" />
|
37 |
+
</reference>
|
38 |
+
</adminhtml_customer_edit>
|
39 |
+
</layout>
|
app/design/adminhtml/default/default/template/postcodenl/api/jsinit.phtml
ADDED
@@ -0,0 +1,24 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<script type="text/javascript">
|
2 |
+
//<![CDATA[
|
3 |
+
var PCNLAPI_CONFIG = {
|
4 |
+
baseUrl: "<?php echo htmlspecialchars(Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_LINK)) ?>",
|
5 |
+
showcase: <?php echo Mage::getStoreConfig('postcodenl/config/api_showcase') ? 'true' : 'false' ?>,
|
6 |
+
translations: {
|
7 |
+
defaultError: "<?php echo htmlspecialchars($this->__('Unknown postcode + housenumber combination.')) ?>",
|
8 |
+
postcodeInputLabel: "<?php echo htmlspecialchars($this->__('Postcode (auto-validating)')) ?>",
|
9 |
+
postcodeInputTitle: "<?php echo htmlspecialchars($this->__('Postcode')) ?>",
|
10 |
+
houseNumberAdditionUnknown: "<?php echo htmlspecialchars($this->__('Housenumber addition `{addition}` is unknown.')) ?>",
|
11 |
+
houseNumberAdditionRequired: "<?php echo htmlspecialchars($this->__('Housenumber addition required.')) ?>",
|
12 |
+
houseNumberLabel: "<?php echo htmlspecialchars($this->__('Housenumber')) ?>",
|
13 |
+
houseNumberTitle: "<?php echo htmlspecialchars($this->__('Housenumber')) ?>",
|
14 |
+
houseNumberAdditionLabel: "<?php echo htmlspecialchars($this->__('Houseno addition')) ?>",
|
15 |
+
houseNumberAdditionTitle: "<?php echo htmlspecialchars($this->__('Housenumber addition')) ?>",
|
16 |
+
selectAddition: "<?php echo htmlspecialchars($this->__('Select...')) ?>",
|
17 |
+
noAdditionSelect: "<?php echo htmlspecialchars($this->__('No addition.')) ?>",
|
18 |
+
noAdditionSelectCustom: "<?php echo htmlspecialchars($this->__('Do not use any addition anyway.')) ?>",
|
19 |
+
additionSelectCustom: "<?php echo htmlspecialchars($this->__('Use `{addition}` anyway.')) ?>",
|
20 |
+
apiShowcase: "<?php echo htmlspecialchars($this->__('API Showcase')) ?>",
|
21 |
+
}
|
22 |
+
};
|
23 |
+
//]]>
|
24 |
+
</script>
|
app/design/frontend/default/default/layout/postcodenl/api/lookup.xml
ADDED
@@ -0,0 +1,21 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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>
|
6 |
+
<action method="addJs" ifconfig="postcodenl/config/enabled"><script>postcodenl/api/lookup.js</script></action>
|
7 |
+
</reference>
|
8 |
+
<reference name="content">
|
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 |
+
</layout>
|
app/design/frontend/default/default/template/postcodenl/api/jsinit.phtml
ADDED
@@ -0,0 +1,24 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<script type="text/javascript">
|
2 |
+
//<![CDATA[
|
3 |
+
var PCNLAPI_CONFIG = {
|
4 |
+
baseUrl: "<?php echo htmlspecialchars(Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_LINK)) ?>",
|
5 |
+
showcase: <?php echo Mage::getStoreConfig('postcodenl/config/api_showcase') ? 'true' : 'false' ?>,
|
6 |
+
translations: {
|
7 |
+
defaultError: "<?php echo htmlspecialchars($this->__('Unknown postcode + housenumber combination.')) ?>",
|
8 |
+
postcodeInputLabel: "<?php echo htmlspecialchars($this->__('Postcode (auto-validating)')) ?>",
|
9 |
+
postcodeInputTitle: "<?php echo htmlspecialchars($this->__('Postcode')) ?>",
|
10 |
+
houseNumberAdditionUnknown: "<?php echo htmlspecialchars($this->__('Housenumber addition `{addition}` is unknown.')) ?>",
|
11 |
+
houseNumberAdditionRequired: "<?php echo htmlspecialchars($this->__('Housenumber addition required.')) ?>",
|
12 |
+
houseNumberLabel: "<?php echo htmlspecialchars($this->__('Housenumber (with any additions)')) ?>",
|
13 |
+
houseNumberTitle: "<?php echo htmlspecialchars($this->__('Housenumber')) ?>",
|
14 |
+
houseNumberAdditionLabel: "<?php echo htmlspecialchars($this->__('Housenumber addition')) ?>",
|
15 |
+
houseNumberAdditionTitle: "<?php echo htmlspecialchars($this->__('Housenumber addition')) ?>",
|
16 |
+
selectAddition: "<?php echo htmlspecialchars($this->__('Select...')) ?>",
|
17 |
+
noAdditionSelect: "<?php echo htmlspecialchars($this->__('No addition.')) ?>",
|
18 |
+
noAdditionSelectCustom: "<?php echo htmlspecialchars($this->__('Do not use any addition anyway.')) ?>",
|
19 |
+
additionSelectCustom: "<?php echo htmlspecialchars($this->__('Use `{addition}` anyway.')) ?>",
|
20 |
+
apiShowcase: "<?php echo htmlspecialchars($this->__('API Showcase')) ?>",
|
21 |
+
}
|
22 |
+
};
|
23 |
+
//]]>
|
24 |
+
</script>
|
app/etc/modules/PostcodeNl_Api.xml
ADDED
@@ -0,0 +1,9 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?xml version="1.0"?>
|
2 |
+
<config>
|
3 |
+
<modules>
|
4 |
+
<PostcodeNl_Api>
|
5 |
+
<active>true</active>
|
6 |
+
<codePool>community</codePool>
|
7 |
+
</PostcodeNl_Api>
|
8 |
+
</modules>
|
9 |
+
</config>
|
app/locale/en_US/PostcodeNl_Api.csv
ADDED
@@ -0,0 +1,13 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
"Unknown postcode + housenumber combination.","Unknown postcode + housenumber combination."
|
2 |
+
"Housenumber addition `{addition}` is unknown.","Housenumber addition `{addition}` is unknown."
|
3 |
+
"Housenumber addition required.","Housenumber addition required."
|
4 |
+
"Housenumber","Housenumber"
|
5 |
+
"Houseno addition","Houseno addition"
|
6 |
+
"Housenumber addition","Housenumber addition"
|
7 |
+
"Select...","Select..."
|
8 |
+
"No addition.","No addition."
|
9 |
+
"Do not use any addition anyway.","Do not use any addition anyway."
|
10 |
+
"Use `{addition}` anyway.","Use `{addition}` anyway."
|
11 |
+
"Housenumber (with any additions)","Housenumber (with any additions)"
|
12 |
+
"Postcode.nl API not configured.","Postcode.nl API not configured."
|
13 |
+
"Postcode.nl API not enabled.","Postcode.nl API not enabled."
|
app/locale/nl_NL/PostcodeNl_Api.csv
ADDED
@@ -0,0 +1,13 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
"Unknown postcode + housenumber combination.","Onbekende postcode + huisnummer combinatie."
|
2 |
+
"Housenumber addition `{addition}` is unknown.","Huisnummer toevoeging `{addition}` is onbekend."
|
3 |
+
"Housenumber addition required.","Huisnummer toevoeging vereist."
|
4 |
+
"Housenumber","Huisnummer"
|
5 |
+
"Houseno addition","Huisnr toevoeging"
|
6 |
+
"Housenumber addition","Huisnummer toevoeging"
|
7 |
+
"Select...","Selecteer..."
|
8 |
+
"No addition.","Geen toevoeging."
|
9 |
+
"Do not use any addition anyway.","Gebruik toch geen toevoeging."
|
10 |
+
"Use `{addition}` anyway.","Gebruik toch `{addition}`."
|
11 |
+
"Housenumber (with any additions)","Huisnummer (met toevoeging)"
|
12 |
+
"Postcode.nl API not configured.","Postcode.nl API niet configureerd."
|
13 |
+
"Postcode.nl API not enabled.","Postcode.nl API niet ingeschakeld."
|
js/postcodenl/api/lookup.js
ADDED
@@ -0,0 +1,372 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
document.observe("dom:loaded", function() {
|
2 |
+
if (typeof PCNLAPI_CONFIG == 'undefined')
|
3 |
+
return;
|
4 |
+
|
5 |
+
function lookupPostcode(prefix, postcodeFieldId, countryFieldId, street1, street2, event)
|
6 |
+
{
|
7 |
+
if (!$(prefix + 'postcode_housenumber'))
|
8 |
+
{
|
9 |
+
return;
|
10 |
+
}
|
11 |
+
|
12 |
+
var postcode = $(prefix + 'postcode_input').getValue().replace(/\s+/, '');
|
13 |
+
var housenumber_mixed = $(prefix + 'postcode_housenumber').getValue().trim();
|
14 |
+
// Number, followed by non alphanumberic chars, and then additional number ("123 A", "123-rood", etc)
|
15 |
+
// or: Number, followed directly by a letter and then alphanumeric/space charcters ("123b3", "123berk 23", etc)
|
16 |
+
var housenumber_match = housenumber_mixed.match(/^([0-9]+)([^0-9a-zA-Z]+([0-9a-zA-Z ]+)|([a-zA-Z]([0-9a-zA-Z ]*)))?$/);
|
17 |
+
var housenumber_addition_select = $(prefix +'postcode_housenumber_addition') ? $(prefix +'postcode_housenumber_addition').getValue() : null;
|
18 |
+
|
19 |
+
var housenumber = housenumber_match ? housenumber_match[1].trim() : '';
|
20 |
+
|
21 |
+
var housenumber_addition = '';
|
22 |
+
|
23 |
+
if (!housenumber_match)
|
24 |
+
housenumber_addition = '';
|
25 |
+
else if (housenumber_match[3])
|
26 |
+
housenumber_addition = housenumber_match[3].trim();
|
27 |
+
else if (housenumber_match[4])
|
28 |
+
housenumber_addition = housenumber_match[4].trim();
|
29 |
+
|
30 |
+
if (housenumber_addition == '' && housenumber_addition_select != '__none__' && housenumber_addition_select != '__select__' && housenumber_addition_select != null)
|
31 |
+
housenumber_addition = housenumber_addition_select;
|
32 |
+
|
33 |
+
if ($(prefix + countryFieldId).getValue() != 'NL' || postcode == '' || housenumber_mixed == '')
|
34 |
+
return;
|
35 |
+
|
36 |
+
var url = PCNLAPI_CONFIG.baseUrl +'postcodenl/json/lookup?postcode=' + postcode + '&houseNumber=' + housenumber + '&houseNumberAddition=' + housenumber_addition;
|
37 |
+
new Ajax.Request(url, {
|
38 |
+
method: 'get',
|
39 |
+
onComplete: function(transport) {
|
40 |
+
var json = transport.responseText.evalJSON();
|
41 |
+
|
42 |
+
if (PCNLAPI_CONFIG.showcase)
|
43 |
+
{
|
44 |
+
if ($(prefix +'showcase'))
|
45 |
+
$(prefix +'showcase').remove();
|
46 |
+
|
47 |
+
var info = '';
|
48 |
+
for (var prop in json)
|
49 |
+
{
|
50 |
+
var name = prop.charAt(0).toUpperCase() + prop.slice(1);
|
51 |
+
info += '<dt>'+ name.escapeHTML() +'</dt><dd>'+ String(json[prop] === null ? '- none -' : json[prop]).escapeHTML() +'</dd>';
|
52 |
+
}
|
53 |
+
|
54 |
+
var map = '';
|
55 |
+
if (json.longitude && json.latitude)
|
56 |
+
{
|
57 |
+
map = '<iframe frameborder="0" scrolling="no" marginheight="0" marginwidth="0" class="map" src="http://maps.google.com/maps?t=h&q='+ json.latitude +','+ json.longitude +'+(Location found)&z=19&output=embed&iwloc=near"></iframe>';
|
58 |
+
}
|
59 |
+
|
60 |
+
if ($(prefix + countryFieldId).parentNode.tagName == 'TD')
|
61 |
+
{
|
62 |
+
// We're probably in the admin
|
63 |
+
$(prefix + street1).parentNode.parentNode.parentNode.insert({before: '<tr id="' + prefix + 'showcase"><td class="label">'+ PCNLAPI_CONFIG.translations.apiShowcase.escapeHTML() +'</label></td><td class="value"><h4 class="showcase">'+ PCNLAPI_CONFIG.translations.apiShowcase +'</h4><dl class="showcase">'+ info + '</dl></td></tr>'});
|
64 |
+
}
|
65 |
+
else
|
66 |
+
{
|
67 |
+
$(prefix + street1).parentNode.parentNode.insert({before: '<li id="' + prefix +'showcase" class="wide"><div class="input-box"><h4 class="showcase">'+ PCNLAPI_CONFIG.translations.apiShowcase.escapeHTML() +'</h4><dl class="showcase">'+ info + map + '</dl></div></li>'});
|
68 |
+
}
|
69 |
+
}
|
70 |
+
|
71 |
+
var advice = Validation.getAdvice('invalid-postcode', $(prefix +'postcode_housenumber'));
|
72 |
+
if (advice) {
|
73 |
+
Validation.hideAdvice($(prefix +'postcode_housenumber'), advice, 'invalid-postcode');
|
74 |
+
}
|
75 |
+
if ($(prefix +'postcode_housenumber_addition'))
|
76 |
+
{
|
77 |
+
var additionAdvice = Validation.getAdvice('invalid-addition', $(prefix +'postcode_housenumber_addition'));
|
78 |
+
if (additionAdvice) {
|
79 |
+
Validation.hideAdvice($(prefix +'postcode_housenumber_addition'), additionAdvice, 'invalid-addition');
|
80 |
+
}
|
81 |
+
}
|
82 |
+
if (json.postcode != undefined)
|
83 |
+
{
|
84 |
+
$(prefix + postcodeFieldId).setValue(json.postcode);
|
85 |
+
$(prefix + 'postcode_input').setValue(json.postcode);
|
86 |
+
$(prefix + street1).setValue((json.street +' '+ json.houseNumber +' '+ (json.houseNumberAddition ? json.houseNumberAddition : housenumber_addition)).trim());
|
87 |
+
$(prefix +'city').setValue(json.city);
|
88 |
+
$(prefix +'region').setValue(json.province);
|
89 |
+
|
90 |
+
if (json.houseNumberAddition == null && (housenumber_addition_select == housenumber_addition || (housenumber_addition_select == '__none__' && housenumber_addition == '')))
|
91 |
+
{
|
92 |
+
$(prefix +'postcode_housenumber').setValue(json.houseNumber);
|
93 |
+
|
94 |
+
var additionSelect = createPostcodeHouseNumberAddition(prefix, postcodeFieldId, countryFieldId, street1, street2, json.houseNumberAdditions, housenumber_addition_select);
|
95 |
+
if (event && event.element().id == prefix +'postcode_housenumber_addition')
|
96 |
+
additionSelect.setValue(housenumber_addition_select);
|
97 |
+
if (additionSelect.getValue() != housenumber_addition_select)
|
98 |
+
{
|
99 |
+
newAdvice = Validation.createAdvice('invalid-addition', $(prefix +'postcode_housenumber_addition'), false, (housenumber_addition != '' ? PCNLAPI_CONFIG.translations.houseNumberAdditionUnknown.replace('{addition}', housenumber_addition) : PCNLAPI_CONFIG.translations.houseNumberAdditionRequired));
|
100 |
+
Validation.showAdvice($(prefix +'postcode_housenumber_addition'), newAdvice, 'invalid-addition');
|
101 |
+
}
|
102 |
+
}
|
103 |
+
else if (json.houseNumberAddition == null)
|
104 |
+
{
|
105 |
+
$(prefix +'postcode_housenumber').setValue(json.houseNumber);
|
106 |
+
|
107 |
+
var additionSelect = createPostcodeHouseNumberAddition(prefix, postcodeFieldId, countryFieldId, street1, street2, json.houseNumberAdditions, housenumber_addition);
|
108 |
+
|
109 |
+
newAdvice = Validation.createAdvice('invalid-addition', $(prefix +'postcode_housenumber_addition'), false, (housenumber_addition != '' ? PCNLAPI_CONFIG.translations.houseNumberAdditionUnknown.replace('{addition}', housenumber_addition) : PCNLAPI_CONFIG.translations.houseNumberAdditionRequired));
|
110 |
+
Validation.showAdvice($(prefix +'postcode_housenumber_addition'), newAdvice, 'invalid-addition');
|
111 |
+
}
|
112 |
+
else
|
113 |
+
{
|
114 |
+
if (json.houseNumberAdditions.length > 1)
|
115 |
+
{
|
116 |
+
var additionSelect = createPostcodeHouseNumberAddition(prefix, postcodeFieldId, countryFieldId, street1, street2, json.houseNumberAdditions);
|
117 |
+
additionSelect.setValue(json.houseNumberAddition);
|
118 |
+
$(prefix +'postcode_housenumber').setValue(json.houseNumber);
|
119 |
+
}
|
120 |
+
else if ($(prefix +'postcode_housenumber_addition'))
|
121 |
+
{
|
122 |
+
$(prefix +'postcode_housenumber').setValue((json.houseNumber +' '+ json.houseNumberAddition).trim());
|
123 |
+
Element.remove($(prefix +'postcode_housenumber_addition'));
|
124 |
+
}
|
125 |
+
}
|
126 |
+
}
|
127 |
+
else if (json.message != undefined)
|
128 |
+
{
|
129 |
+
newAdvice = Validation.createAdvice('invalid-postcode', $(prefix +'postcode_housenumber'), false, json.message);
|
130 |
+
Validation.showAdvice($(prefix +'postcode_housenumber'), newAdvice, 'invalid-postcode');
|
131 |
+
|
132 |
+
if ($(prefix +'postcode_housenumber_addition'))
|
133 |
+
Element.remove($(prefix +'postcode_housenumber_addition'));
|
134 |
+
}
|
135 |
+
else
|
136 |
+
{
|
137 |
+
newAdvice = Validation.createAdvice('invalid-postcode', $(prefix +'postcode_housenumber'), false, '');
|
138 |
+
Validation.showAdvice($(prefix +'postcode_housenumber'), newAdvice, 'invalid-postcode');
|
139 |
+
|
140 |
+
if ($(prefix +'postcode_housenumber_addition'))
|
141 |
+
Element.remove($(prefix +'postcode_housenumber_addition'));
|
142 |
+
}
|
143 |
+
|
144 |
+
$(prefix + postcodeFieldId).fire('postcode:updated');
|
145 |
+
}
|
146 |
+
});
|
147 |
+
};
|
148 |
+
|
149 |
+
function toggleCountryPostcode(prefix, postcodeFieldId, countryFieldId, street1, street2) {
|
150 |
+
if (!$(prefix + countryFieldId))
|
151 |
+
alert(prefix + countryFieldId);
|
152 |
+
if ($(prefix + countryFieldId).getValue() == 'NL')
|
153 |
+
{
|
154 |
+
$(prefix +'city', prefix +'region', prefix + postcodeFieldId, prefix + street1, prefix + street2).invoke('setAttribute', 'readonly', true);
|
155 |
+
$(prefix +'city', prefix +'region', prefix + postcodeFieldId, prefix + street1, prefix + street2).invoke('addClassName', 'readonly');
|
156 |
+
$(prefix +'city', prefix +'region', prefix + postcodeFieldId, prefix + street1).invoke('removeClassName', 'required-entry');
|
157 |
+
if (!$(prefix +'postcode_input:wrapper'))
|
158 |
+
{
|
159 |
+
if ($(prefix + postcodeFieldId).parentNode.tagName == 'TD')
|
160 |
+
{
|
161 |
+
// We're probably in the admin
|
162 |
+
$($(prefix + street1).parentNode.parentNode.parentNode).insert({before: '<tr id="' + prefix + 'postcode_input:wrapper"><td class="label"><label for="' + prefix + 'postcode_input">'+ PCNLAPI_CONFIG.translations.postcodeInputLabel +' <span class="required">*</span></label></td><td class="value"><input type="text" title="'+ PCNLAPI_CONFIG.translations.postcodeInputTitle +'" id="' + prefix + 'postcode_input" value="" class="input-text required-entry" /></div></td></tr><tr id="' + prefix + 'postcode_housenumber:wrapper"><td class="label"><label for="' + prefix + 'postcode_housenumber">'+ PCNLAPI_CONFIG.translations.houseNumberLabel +' <span class="required">*</span></label></td><td class="value"><input type="text" title="'+ PCNLAPI_CONFIG.translations.houseNumberTitle +'" name="billing[postcode_housenumber]" id="' + prefix + 'postcode_housenumber" value="" class="input-text input-text-half required-entry" /></div></td></tr>'});
|
163 |
+
}
|
164 |
+
else
|
165 |
+
{
|
166 |
+
$(prefix + street1).parentNode.parentNode.insert({before: '<li id="' + prefix + 'postcode_input:wrapper"><div class="field"><label for="' + prefix + 'postcode_input" class="required"><em>*</em>'+ PCNLAPI_CONFIG.translations.postcodeInputLabel +'</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><div class="field"><label for="' + prefix + 'postcode_housenumber" class="required"><em>*</em>'+ PCNLAPI_CONFIG.translations.houseNumberLabel +'</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 input-text-half required-entry" /></div></div></li>'});
|
167 |
+
}
|
168 |
+
|
169 |
+
$(prefix +'postcode_input').observe('change', function(e) { lookupPostcode(prefix, postcodeFieldId, countryFieldId, street1, street2, e); });
|
170 |
+
$(prefix +'postcode_housenumber').observe('change', function(e) { lookupPostcode(prefix, postcodeFieldId, countryFieldId, street1, street2, e); });
|
171 |
+
}
|
172 |
+
else
|
173 |
+
{
|
174 |
+
$(prefix +'postcode_input:wrapper').show();
|
175 |
+
if ($(prefix +'postcode_housenumber_addition'))
|
176 |
+
$(prefix +'postcode_housenumber_addition').show();
|
177 |
+
}
|
178 |
+
|
179 |
+
if ($(prefix + postcodeFieldId).getValue() != '' && $(prefix +'postcode_input').getValue() == '')
|
180 |
+
{
|
181 |
+
$(prefix +'postcode_input').setValue($(prefix + postcodeFieldId).getValue());
|
182 |
+
|
183 |
+
var housenumber_match = $(prefix + street1).getValue().match(/([0-9]+)([^0-9a-zA-Z]+([0-9a-zA-Z ]+)|([a-zA-Z]([0-9a-zA-Z ]+)))?$/);
|
184 |
+
|
185 |
+
var housenumber = housenumber_match ? housenumber_match[1].trim() : '';
|
186 |
+
|
187 |
+
var housenumber_addition = '';
|
188 |
+
|
189 |
+
if (!housenumber_match)
|
190 |
+
housenumber_addition = '';
|
191 |
+
else if (housenumber_match[3])
|
192 |
+
housenumber_addition = housenumber_match[3].trim();
|
193 |
+
else if (housenumber_match[4])
|
194 |
+
housenumber_addition = housenumber_match[4].trim();
|
195 |
+
|
196 |
+
$(prefix +'postcode_housenumber').setValue(housenumber +' '+ housenumber_addition);
|
197 |
+
lookupPostcode(prefix, postcodeFieldId, countryFieldId, street1, street2);
|
198 |
+
}
|
199 |
+
}
|
200 |
+
else
|
201 |
+
{
|
202 |
+
$(prefix +'city', prefix +'region', prefix + postcodeFieldId, prefix + street1, prefix + street2).invoke('removeAttribute', 'readonly');
|
203 |
+
$(prefix +'city', prefix +'region', prefix + postcodeFieldId, prefix + street1, prefix + street2).invoke('removeClassName', 'readonly');
|
204 |
+
$(prefix +'city', prefix +'region', prefix + postcodeFieldId, prefix + street1).invoke('addClassName', 'required-entry');
|
205 |
+
Element.remove($(prefix +'postcode_input:wrapper'));
|
206 |
+
if ($(prefix +'postcode_housenumber:wrapper'))
|
207 |
+
Element.remove($(prefix +'postcode_housenumber:wrapper'));
|
208 |
+
if ($(prefix +'showcase'))
|
209 |
+
Element.remove($(prefix +'showcase'));
|
210 |
+
if ($(prefix +'postcode_housenumber_addition:wrapper'))
|
211 |
+
Element.remove($(prefix +'postcode_housenumber_addition:wrapper'));
|
212 |
+
else if ($(prefix +'postcode_housenumber_addition'))
|
213 |
+
Element.remove($(prefix +'postcode_housenumber_addition'));
|
214 |
+
}
|
215 |
+
}
|
216 |
+
|
217 |
+
function createPostcodeHouseNumberAddition(prefix, postcodeFieldId, countryFieldId, street1, street2, values, custom) {
|
218 |
+
if ($(prefix +'postcode_housenumber_addition:wrapper'))
|
219 |
+
Element.remove($(prefix +'postcode_housenumber_addition:wrapper'));
|
220 |
+
if ($(prefix +'postcode_housenumber_addition'))
|
221 |
+
Element.remove($(prefix +'postcode_housenumber_addition'));
|
222 |
+
|
223 |
+
var options = '';
|
224 |
+
if (custom != null)
|
225 |
+
{
|
226 |
+
if (custom == '')
|
227 |
+
custom = '__none__';
|
228 |
+
|
229 |
+
options += '<option value="__select__">'+ PCNLAPI_CONFIG.translations.selectAddition +'</option>';
|
230 |
+
options += '<option value="'+ custom.escapeHTML() +'">'+ (custom == '__none__' ? PCNLAPI_CONFIG.translations.noAdditionSelectCustom : PCNLAPI_CONFIG.translations.additionSelectCustom.replace('{addition}', custom.escapeHTML())) +'</option>';
|
231 |
+
}
|
232 |
+
else if (values.indexOf('') == -1)
|
233 |
+
{
|
234 |
+
options += '<option value="__none__">'+ PCNLAPI_CONFIG.translations.noAdditionSelectCustom.escapeHTML() +'</option>';
|
235 |
+
}
|
236 |
+
|
237 |
+
values.each(function(value) {
|
238 |
+
options += '<option value="'+ value.escapeHTML() +'">'+ (value == '' ? PCNLAPI_CONFIG.translations.noAdditionSelect : value ).escapeHTML() +'</option>';
|
239 |
+
});
|
240 |
+
|
241 |
+
if ($(prefix + countryFieldId).parentNode.tagName == 'TD')
|
242 |
+
{
|
243 |
+
// We're probably in the admin
|
244 |
+
$(prefix + 'postcode_housenumber').parentNode.parentNode.insert({after: '<tr id="' + prefix +'postcode_housenumber_addition:wrapper"><td class="label"><label for="'+ prefix +'postcode_housenumber_addition">'+ PCNLAPI_CONFIG.translations.houseNumberAdditionLabel +' <span class="required">*</span></label></td><td class="value"><select title="'+ PCNLAPI_CONFIG.translations.houseNumberAdditionTitle +'" name="'+ prefix + 'postcode_housenumber_addition" id="' + prefix + 'postcode_housenumber_addition" class="select">'+ options +'</select></td></tr>'});
|
245 |
+
}
|
246 |
+
else
|
247 |
+
{
|
248 |
+
// We're probably in the frontend
|
249 |
+
$(prefix + 'postcode_housenumber').insert({after: '<select title="'+ PCNLAPI_CONFIG.translations.houseNumberAdditionTitle +'" name="'+ prefix + 'postcode_housenumber_addition" id="' + prefix + 'postcode_housenumber_addition" class="validate-select input-text-half">'+ options +'</select>'});
|
250 |
+
}
|
251 |
+
|
252 |
+
$(prefix +'postcode_housenumber_addition').observe('change', function(e) { lookupPostcode(prefix, postcodeFieldId, countryFieldId, street1, street2, e); });
|
253 |
+
|
254 |
+
return $(prefix +'postcode_housenumber_addition');
|
255 |
+
}
|
256 |
+
|
257 |
+
|
258 |
+
// Checkout page
|
259 |
+
if ($('billing:postcode'))
|
260 |
+
{
|
261 |
+
$('billing:country_id').observe('change', function () {toggleCountryPostcode('billing:', 'postcode', 'country_id', 'street1', 'street2');});
|
262 |
+
$('shipping:country_id').observe('change', function () {toggleCountryPostcode('shipping:', 'postcode', 'country_id', 'street1', 'street2');});
|
263 |
+
|
264 |
+
if ($('billing:country_id').getValue() == 'NL')
|
265 |
+
toggleCountryPostcode('billing:', 'postcode', 'country_id', 'street1', 'street2');
|
266 |
+
if ($('shipping:country_id').getValue() == 'NL')
|
267 |
+
toggleCountryPostcode('shipping:', 'postcode', 'country_id', 'street1', 'street2');
|
268 |
+
}
|
269 |
+
|
270 |
+
// Misc. account address edits
|
271 |
+
if ($('zip') && $('street_1'))
|
272 |
+
{
|
273 |
+
$('zip').observe('change', function(e) {
|
274 |
+
lookupPostcode('', 'zip', 'country', 'street_1', 'street_2', e);
|
275 |
+
});
|
276 |
+
|
277 |
+
$('country').observe('change', function () {toggleCountryPostcode('', 'zip', 'country', 'street_1', 'street_2');});
|
278 |
+
|
279 |
+
if ($('country').getValue() == 'NL')
|
280 |
+
toggleCountryPostcode('', 'zip', 'country', 'street_1', 'street_2');
|
281 |
+
}
|
282 |
+
|
283 |
+
// Default admin address edits
|
284 |
+
if ($('postcode') && $('street0'))
|
285 |
+
{
|
286 |
+
$('postcode').observe('change', function(e) {
|
287 |
+
lookupPostcode('', 'postcode', 'country_id', 'street0', 'street1', e);
|
288 |
+
});
|
289 |
+
|
290 |
+
$('country_id').observe('change', function () {toggleCountryPostcode('', 'postcode', 'country_id', 'street0', 'street1');});
|
291 |
+
|
292 |
+
if ($('country_id').getValue() == 'NL')
|
293 |
+
toggleCountryPostcode('', 'postcode', 'country_id', 'street0', 'street1');
|
294 |
+
}
|
295 |
+
|
296 |
+
// User admin address edits
|
297 |
+
if ($('address_form_container'))
|
298 |
+
{
|
299 |
+
function observeAdminCustomerAddress()
|
300 |
+
{
|
301 |
+
var nr = 1;
|
302 |
+
while ($('_item'+ nr +'postcode'))
|
303 |
+
{
|
304 |
+
$('_item'+ nr +'postcode').observe('change', function(e) {
|
305 |
+
var localNr = nr;
|
306 |
+
return function () { lookupPostcode('_item'+ localNr, 'postcode', 'country_id', 'street0', 'street1', e);}
|
307 |
+
}());
|
308 |
+
|
309 |
+
$('_item'+ nr +'country_id').observe('change', function(e) {
|
310 |
+
var localNr = nr;
|
311 |
+
return function () { toggleCountryPostcode('_item'+ localNr, 'postcode', 'country_id', 'street0', 'street1');}
|
312 |
+
}());
|
313 |
+
|
314 |
+
if ($('_item'+ nr +'country_id').getValue() == 'NL')
|
315 |
+
toggleCountryPostcode('_item'+ nr, 'postcode', 'country_id', 'street0', 'street1');
|
316 |
+
|
317 |
+
nr++;
|
318 |
+
}
|
319 |
+
}
|
320 |
+
|
321 |
+
observeAdminCustomerAddress();
|
322 |
+
|
323 |
+
$('address_form_container').observe('DOMNodeInserted', function(e) { observeAdminCustomerAddress(); });
|
324 |
+
}
|
325 |
+
|
326 |
+
|
327 |
+
// Admin 'create order' & 'edit order' address editting
|
328 |
+
if ($('order-billing_address'))
|
329 |
+
{
|
330 |
+
function observeBillingAddress()
|
331 |
+
{
|
332 |
+
// Billing
|
333 |
+
if ($('order-billing_address_postcode'))
|
334 |
+
{
|
335 |
+
$('order-billing_address_postcode').observe('change', function(e) {
|
336 |
+
lookupPostcode('order-billing_address_', 'postcode', 'country_id', 'street0', 'street1', e);
|
337 |
+
});
|
338 |
+
$('order-billing_address_country_id').observe('change', function () {
|
339 |
+
toggleCountryPostcode('order-billing_address_', 'postcode', 'country_id', 'street0', 'street1');
|
340 |
+
});
|
341 |
+
if ($('order-billing_address_country_id').getValue() == 'NL')
|
342 |
+
toggleCountryPostcode('order-billing_address_', 'postcode', 'country_id', 'street0', 'street1');
|
343 |
+
$('order-billing_address_postcode').observe('postcode:updated', function(e) {
|
344 |
+
// Custom poke Magento billing-to-shipping copy order logic.
|
345 |
+
var event = { type: e.type, currentTarget: $('order-billing_address_street0'), target: $('order-billing_address_street0')};
|
346 |
+
order.changeAddressField(event);
|
347 |
+
});
|
348 |
+
}
|
349 |
+
}
|
350 |
+
|
351 |
+
function observeShippingAddress()
|
352 |
+
{
|
353 |
+
// Shipping
|
354 |
+
if (!$('order-shipping_same_as_billing').checked)
|
355 |
+
{
|
356 |
+
$('order-shipping_address_postcode').observe('change', function(e) {
|
357 |
+
lookupPostcode('order-shipping_address_', 'postcode', 'country_id', 'street0', 'street1', e);
|
358 |
+
});
|
359 |
+
$('order-shipping_address_country_id').observe('change', function () {toggleCountryPostcode('order-shipping_address_', 'postcode', 'country_id', 'street0', 'street1');});
|
360 |
+
if ($('order-shipping_address_country_id').getValue() == 'NL')
|
361 |
+
toggleCountryPostcode('order-shipping_address_', 'postcode', 'country_id', 'street0', 'street1');
|
362 |
+
}
|
363 |
+
}
|
364 |
+
|
365 |
+
observeBillingAddress();
|
366 |
+
observeShippingAddress();
|
367 |
+
|
368 |
+
// Re-observe blocks after they have been changed
|
369 |
+
$('order-billing_address').observe('DOMNodeInserted', function(e) { observeBillingAddress(); });
|
370 |
+
$('order-shipping_address').observe('DOMNodeInserted', function(e) { observeShippingAddress(); });
|
371 |
+
}
|
372 |
+
});
|
package.xml
ADDED
@@ -0,0 +1,25 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?xml version="1.0"?>
|
2 |
+
<package>
|
3 |
+
<name>PostcodeNl_Api</name>
|
4 |
+
<version>1.0.1.0</version>
|
5 |
+
<stability>stable</stability>
|
6 |
+
<license>Simplified BSD License</license>
|
7 |
+
<channel>community</channel>
|
8 |
+
<extends/>
|
9 |
+
<summary>Complement and validate Dutch addresses at Checkout with the free postcode Magento plugin from Postcode.nl.</summary>
|
10 |
+
<description>Complement and validate Dutch addresses at Checkout with the free postcode Magento plugin from Postcode.nl.
|
11 |
+

|
12 |
+
• Reduce address errors 
|
13 |
+
• Reduce costs from undelivered mail and packages
|
14 |
+
• Offer extra service for your customers with easy address entry
|
15 |
+
• Improve sale conversion
|
16 |
+

|
17 |
+
The postcode Magento plugin from Postcode.nl is free of charge, with a limitation of 10,000 requests per year. The use of the Postcode.nl Magento plugin is subject to our Terms and Conditions.</description>
|
18 |
+
<notes>Improved compatibility.</notes>
|
19 |
+
<authors><author><name>Postcode.nl Technical Support</name><user>auto-converted</user><email>tech@postcode.nl</email></author></authors>
|
20 |
+
<date>2012-09-06</date>
|
21 |
+
<time>13:55:07</time>
|
22 |
+
<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="4c0ea49354041dd49049bc4ed24b3ed3"/></dir><dir name="etc"><file name="config.xml" hash="a1b4244120c47f02084de73488ce68c2"/><file name="system.xml" hash="e49a0d5fd68620e2f179a58e1de51671"/></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="8061e808dc71f96026e268d3463728fe"/></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="606b14bed6481aa253e60c89e75ed9e6"/></dir></dir></dir><dir name="template"><dir name="postcodenl"><dir name="api"><file name="jsinit.phtml" hash="fe4621dc415f62efd24bb7707df72cf7"/></dir></dir></dir></dir></dir></dir></target><target name="magelocale"><dir name="en_US"><file name="PostcodeNl_Api.csv" hash="4afeaaa3b5dd9fe76b5c0d72ebe504aa"/></dir><dir name="nl_NL"><file name="PostcodeNl_Api.csv" hash="890191bad671146a940d0c561ea27782"/></dir></target><target name="mageweb"><dir name="js"><dir name="postcodenl"><dir name="api"><file name="lookup.js" hash="1a2d3cee535ed0655b1518af26b5ae2f"/></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="bfb9ee43739cfec85954b1e810fc996c"/></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="b3565f5a31fb73b3d8c9d78c3226bdec"/></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>
|
23 |
+
<compatible/>
|
24 |
+
<dependencies/>
|
25 |
+
</package>
|
skin/adminhtml/default/default/postcodenl/api/css/lookup.css
ADDED
@@ -0,0 +1,30 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
input.readonly {
|
2 |
+
background-color: #EEE;
|
3 |
+
}
|
4 |
+
|
5 |
+
h4.showcase {
|
6 |
+
margin-top: 5px;
|
7 |
+
margin-bottom: 0px;
|
8 |
+
}
|
9 |
+
|
10 |
+
h4.showcase {
|
11 |
+
background: url(../images/postcode-logo.png) left center no-repeat;
|
12 |
+
padding-left: 146px;
|
13 |
+
height: 22px;
|
14 |
+
line-height: 25px;
|
15 |
+
}
|
16 |
+
|
17 |
+
dl.showcase {
|
18 |
+
padding: 4px;
|
19 |
+
border: 1px solid grey;
|
20 |
+
border-radius: 4px;
|
21 |
+
-moz-border-radius: 4px;
|
22 |
+
background: white;
|
23 |
+
}
|
24 |
+
|
25 |
+
dl.showcase dt {
|
26 |
+
font-weight: bold;
|
27 |
+
}
|
28 |
+
dl.showcase dd {
|
29 |
+
margin-left: 20px;
|
30 |
+
}
|
skin/adminhtml/default/default/postcodenl/api/images/postcode-logo.png
ADDED
Binary file
|
skin/frontend/default/default/postcodenl/api/css/lookup.css
ADDED
@@ -0,0 +1,43 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
input.readonly {
|
2 |
+
background-color: #EEE;
|
3 |
+
}
|
4 |
+
|
5 |
+
h4.showcase {
|
6 |
+
margin-bottom: 0px;
|
7 |
+
}
|
8 |
+
|
9 |
+
h4.showcase {
|
10 |
+
background: url(../images/postcode-logo.png) left center no-repeat;
|
11 |
+
padding-left: 146px;
|
12 |
+
height: 22px;
|
13 |
+
line-height: 25px;
|
14 |
+
}
|
15 |
+
|
16 |
+
dl.showcase {
|
17 |
+
padding: 4px;
|
18 |
+
border: 1px solid grey;
|
19 |
+
border-radius: 4px;
|
20 |
+
-moz-border-radius: 4px;
|
21 |
+
background: white;
|
22 |
+
position: relative;
|
23 |
+
}
|
24 |
+
|
25 |
+
dl.showcase iframe {
|
26 |
+
position: absolute;
|
27 |
+
top: 5px;
|
28 |
+
right: 5px;
|
29 |
+
width: 300px;
|
30 |
+
height: 300px;
|
31 |
+
border: 1px solid grey;
|
32 |
+
}
|
33 |
+
|
34 |
+
dl.showcase dt {
|
35 |
+
font-weight: bold;
|
36 |
+
}
|
37 |
+
dl.showcase dd {
|
38 |
+
margin-left: 20px;
|
39 |
+
}
|
40 |
+
|
41 |
+
.form-list .pos { width:70px; }
|
42 |
+
.form-list input.input-text-half { width:100px; }
|
43 |
+
.form-list select.input-text-half { margin-left:5px; width:149px; }
|
skin/frontend/default/default/postcodenl/api/images/postcode-logo.png
ADDED
Binary file
|