/
ps_customeraccountlinks.php
151 lines (131 loc) · 5.13 KB
/
ps_customeraccountlinks.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
<?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 license@prestashop.com 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 <contact@prestashop.com>
* @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_Customeraccountlinks extends Module implements WidgetInterface
{
private $templateFile;
public function __construct()
{
$this->name = 'ps_customeraccountlinks';
$this->tab = 'front_office_features';
$this->author = 'PrestaShop';
$this->version = '3.2.0';
$this->need_instance = 0;
parent::__construct();
$this->displayName = $this->trans('My Account block', [], 'Modules.Customeraccountlinks.Admin');
$this->description = $this->trans('Welcome your customers with their personal information displayed right on your footer.', [], 'Modules.Customeraccountlinks.Admin');
$this->ps_versions_compliancy = ['min' => '1.7.4.0', 'max' => _PS_VERSION_];
$this->templateFile = 'module:ps_customeraccountlinks/ps_customeraccountlinks.tpl';
}
public function install()
{
return parent::install()
&& $this->registerHook('actionModuleRegisterHookAfter')
&& $this->registerHook('actionModuleUnRegisterHookAfter')
&& $this->registerHook('displayFooter')
;
}
public function uninstall()
{
return parent::uninstall();
}
public function hookActionModuleUnRegisterHookAfter($params)
{
if ('displayMyAccountBlock' === $params['hook_name']) {
$this->_clearCache('*');
}
}
public function hookActionModuleRegisterHookAfter($params)
{
if ($params['hook_name'] == 'displayMyAccountBlock') {
$this->_clearCache('*');
}
}
public function _clearCache($template, $cache_id = null, $compile_id = null)
{
parent::_clearCache($this->templateFile);
}
public function renderWidget($hookName = null, array $configuration = [])
{
$tpl_key = 'ps_customeraccountlinks';
if ($this->context->smarty->tpl_vars['customer']->value['addresses']) {
$tpl_key .= '_multiple';
}
if (!$this->isCached($this->templateFile, $this->getCacheId($tpl_key))) {
$this->smarty->assign($this->getWidgetVariables($hookName, $configuration));
}
return $this->fetch($this->templateFile, $this->getCacheId($tpl_key));
}
public function getWidgetVariables($hookName = null, array $configuration = [])
{
$link = $this->context->link;
$my_account_urls = [
2 => [
'title' => $this->trans('Orders', [], 'Admin.Global'),
'url' => $link->getPageLink('history', true),
],
3 => [
'title' => $this->trans('Credit slips', [], 'Modules.Customeraccountlinks.Admin'),
'url' => $link->getPageLink('order-slip', true),
],
4 => [
'title' => $this->trans('Addresses', [], 'Shop.Theme.Global'),
'url' => $link->getPageLink('addresses', true),
],
0 => [
'title' => $this->trans('Personal info', [], 'Modules.Customeraccountlinks.Admin'),
'url' => $link->getPageLink('identity', true),
],
];
if ((int) Configuration::get('PS_ORDER_RETURN')) {
$my_account_urls[1] = [
'title' => $this->trans('Merchandise returns', [], 'Modules.Customeraccountlinks.Admin'),
'url' => $link->getPageLink('order-follow', true),
];
}
if (CartRule::isFeatureActive()) {
$my_account_urls[5] = [
'title' => $this->trans('Vouchers', [], 'Shop.Theme.Customeraccount'),
'url' => $link->getPageLink('discount', true),
];
}
// Sort Account links base in his index
ksort($my_account_urls);
return [
/*
* @deprecated
*/
'my_account_urls' => $my_account_urls,
/*
* @deprecated
*/
'logout_url' => $link->getPageLink('index', true, null, 'mylogout'),
];
}
}