-
Notifications
You must be signed in to change notification settings - Fork 22
/
Copy pathps_contactinfo.php
182 lines (157 loc) · 6.79 KB
/
ps_contactinfo.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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
<?php
/**
* Copyright since 2007 PrestaShop SA and Contributors
* PrestaShop is an International Registered Trademark & Property of PrestaShop SA
*
* NOTICE OF LICENSE
*
* This source file is subject to the Academic Free License 3.0 (AFL-3.0)
* that is bundled with this package in the file LICENSE.md.
* It is also available through the world-wide-web at this URL:
* https://opensource.org/licenses/AFL-3.0
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to [email protected] so we can send you a copy immediately.
*
* DISCLAIMER
*
* Do not edit or add to this file if you wish to upgrade PrestaShop to newer
* versions in the future. If you wish to customize PrestaShop for your
* needs please refer to https://devdocs.prestashop.com/ for more information.
*
* @author PrestaShop SA and Contributors <[email protected]>
* @copyright Since 2007 PrestaShop SA and Contributors
* @license https://opensource.org/licenses/AFL-3.0 Academic Free License 3.0 (AFL-3.0)
*/
if (!defined('_PS_VERSION_')) {
exit;
}
use PrestaShop\PrestaShop\Core\Module\WidgetInterface;
class Ps_Contactinfo extends Module implements WidgetInterface
{
private $templates = [
'light' => 'nav.tpl',
'rich' => 'ps_contactinfo-rich.tpl',
'default' => 'ps_contactinfo.tpl',
];
public function __construct()
{
$this->name = 'ps_contactinfo';
$this->author = 'PrestaShop';
$this->version = '3.3.3';
$this->bootstrap = true;
parent::__construct();
$this->displayName = $this->trans('Contact information', [], 'Modules.Contactinfo.Admin');
$this->description = $this->trans('Let your customers know how to reach you, display contact information on your store.', [], 'Modules.Contactinfo.Admin');
$this->ps_versions_compliancy = ['min' => '1.7.2.0', 'max' => _PS_VERSION_];
}
public function install()
{
return parent::install()
&& Configuration::updateValue('PS_CONTACT_INFO_DISPLAY_EMAIL', 1)
&& $this->registerHook([
'displayNav', // Standard hook
'displayNav1', // For Classic-inspired themes
'displayFooter',
'displayContactRightColumn',
'displayContactLeftColumn',
'displayContactContent',
'actionAdminStoresControllerUpdate_optionsAfter',
]);
}
public function renderWidget($hookName = null, array $configuration = [])
{
if ($hookName == null && isset($configuration['hook'])) {
$hookName = $configuration['hook'];
}
if (preg_match('/^displayNav\d*$/', $hookName)) {
$template_file = $this->templates['light'];
} elseif (in_array($hookName, ['displayContactLeftColumn', 'displayContactRightColumn', 'displayLeftColumn', 'displayRightColumn'])) {
$template_file = $this->templates['rich'];
} else {
$template_file = $this->templates['default'];
}
$this->smarty->assign($this->getWidgetVariables($hookName, $configuration));
return $this->fetch('module:' . $this->name . '/' . $template_file);
}
public function getWidgetVariables($hookName = null, array $configuration = [])
{
$address = $this->context->shop->getAddress();
$formattedAddress = AddressFormat::generateAddress($address, [], '<br />');
$contact_infos = [
'company' => Configuration::get('PS_SHOP_NAME'),
'address' => [
'formatted' => Validate::isCleanHtml($formattedAddress) ? $formattedAddress : '',
'address1' => $address->address1,
'address2' => $address->address2,
'postcode' => $address->postcode,
'city' => $address->city,
'state' => (!empty($address->id_state) ? (new State($address->id_state))->name[$this->context->language->id] : null),
'country' => (new Country($address->id_country))->name[$this->context->language->id],
],
'phone' => Configuration::get('PS_SHOP_PHONE'),
'fax' => Configuration::get('PS_SHOP_FAX'),
'email' => Configuration::get('PS_SHOP_EMAIL'),
'details' => Configuration::get('PS_SHOP_DETAILS'),
];
return [
'contact_infos' => $contact_infos,
'display_email' => Configuration::get('PS_CONTACT_INFO_DISPLAY_EMAIL'),
];
}
public function hookActionAdminStoresControllerUpdate_optionsAfter()
{
foreach ($this->templates as $template) {
$this->_clearCache($template);
}
return true;
}
public function getContent()
{
$output = [];
if (Tools::isSubmit('submitContactInfo')) {
Configuration::updateValue('PS_CONTACT_INFO_DISPLAY_EMAIL', (int) Tools::getValue('PS_CONTACT_INFO_DISPLAY_EMAIL'));
foreach ($this->templates as $template) {
$this->_clearCache($template);
}
$output[] = $this->displayConfirmation($this->trans('Settings updated.', [], 'Admin.Notifications.Success'));
Tools::redirectAdmin($this->context->link->getAdminLink('AdminModules', true) . '&conf=6&configure=' . $this->name . '&tab_module=' . $this->tab . '&module_name=' . $this->name);
}
$helper = new HelperForm();
$helper->submit_action = 'submitContactInfo';
$field = [
'type' => 'switch',
'label' => $this->trans('Display email address', [], 'Admin.Actions'),
'name' => 'PS_CONTACT_INFO_DISPLAY_EMAIL',
'desc' => $this->trans('Your theme needs to be compatible with this feature', [], 'Modules.Contactinfo.Admin'),
'values' => [
[
'id' => 'active_on',
'value' => 1,
'label' => $this->trans('Yes', [], 'Admin.Global'),
],
[
'id' => 'active_off',
'value' => 0,
'label' => $this->trans('No', [], 'Admin.Global'),
],
],
];
$helper->fields_value['PS_CONTACT_INFO_DISPLAY_EMAIL'] = Configuration::get('PS_CONTACT_INFO_DISPLAY_EMAIL');
$output[] = $helper->generateForm([
[
'form' => [
'legend' => [
'title' => $this->displayName,
'icon' => 'icon-share',
],
'input' => [$field],
'submit' => [
'title' => $this->trans('Save', [], 'Admin.Actions'),
],
],
],
]);
return implode($output);
}
}