-
Notifications
You must be signed in to change notification settings - Fork 0
/
postcodenl.php
99 lines (83 loc) · 2.65 KB
/
postcodenl.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
<?php
/**
* 2018, Apium
*
* @author Niels Wouda, Apium <[email protected]>
* @copyright 2018, Apium
*/
defined('_PS_VERSION_') || exit;
require_once 'vendor/autoload.php';
class PostcodeNL extends Module
{
public function __construct()
{
$this->name = 'postcodenl';
$this->version = '1.0.0';
$this->author = 'Apium';
$this->need_instance = false;
$this->bootstrap = true;
parent::__construct();
$this->displayName = $this->l('Postcode.nl auto-complete');
$this->description = $this->l('Completes the address forms via postcode.nl.');
$this->ps_versions_compliancy = array(
'min' => '1.6.0.0',
'max' => _PS_VERSION_
);
}
public function install()
{
return parent::install()
&& $this->registerHook('displayHeader')
&& $this->registerHook('displayPostcodeNL')
&& $this->registerHook('displayOverrideTemplate');
}
public function uninstall()
{
return parent::uninstall()
&& $this->unregisterHook('displayHeader')
&& $this->unregisterHook('displayPostcodeNL')
&& $this->unregisterHook('displayOverrideTemplate');
}
public function getContent()
{
$settingsForm = new \Apium\PostcodeNL\Module\SettingsForm($this);
return $settingsForm->process().$settingsForm->render();
}
public function hookDisplayHeader()
{
if (!$this->shouldAddProcessing() || !$this->active) {
return;
}
// Webpack is in control of CSS assets
$this->context->controller->addCSS($this->getPathUri().'views/css/front.styles.css');
$this->context->controller->addJS($this->getPathUri().'views/js/front.bundle.js');
Media::addJsDef([
'country_postcode_active' => Country::getByIso('NL')
]);
}
/**
* Used to override the address template. Change this template (in
* `/views/templates` to suit your particular theme. Default works for
* PS 1.6.x.
*/
public function hookDisplayOverrideTemplate($params)
{
if ($params['controller']->php_self == "address") {
return $this->local_path.'views/templates/hook/address.tpl';
}
return false;
}
public function hookDisplayPostcodeNL()
{
return $this->context->smarty->fetch(
$this->local_path.'views/templates/hook/postcodenl.tpl'
);
}
private function shouldAddProcessing()
{
return in_array(
$this->context->controller->php_self,
['address'] // TODO extend where necessary
);
}
}