-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpsaccountstoggle.php
More file actions
147 lines (119 loc) · 5.11 KB
/
psaccountstoggle.php
File metadata and controls
147 lines (119 loc) · 5.11 KB
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
<?php
/**
* 2009-2025 Tecnoacquisti.com
*
* For support feel free to contact us on our website at http://www.tecnoacquisti.com
*
* @author Arte e Informatica <helpdesk@tecnoacquisti.com>
* @copyright 2009-2025 Arte e Informatica
* @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0)
* @version 1.0.0
*/
if (!defined('_PS_VERSION_')) { exit; }
class PsAccountsToggle extends Module
{
public function __construct()
{
$this->name = 'psaccountstoggle';
$this->tab = 'administration';
$this->version = '1.0.1';
$this->author = 'Tecnoacquisti.com';
$this->need_instance = 0;
$this->bootstrap = true;
parent::__construct();
$this->displayName = $this->l('PS Accounts Toggle');
$this->description = $this->l('PS_ACCOUNTS_LOGIN_ENABLED is an internal, undocumented setting of the ps_accounts module used to enable the login flow through a PrestaShop Addons account. This module allows you to easily enable or disable this setting at will, without affecting the other features of ps_accounts.');
$this->ps_versions_compliancy = array('min' => '1.7', 'max' => _PS_VERSION_);
}
public function install()
{
return parent::install();
}
public function uninstall()
{
return parent::uninstall();
}
protected function checkPsAccountsInstalled()
{
$module = Module::getInstanceByName('ps_accounts');
return (bool) ($module && !empty($module->id));
}
public function getContent()
{
$output = '';
$installed = false;
if (Tools::isSubmit('submitPsAccountsToggle')) {
$this->postProcess();
$output .= $this->displayConfirmation($this->l('Saved settings.'));
// Optional: Clear smarty cache for security
try { Tools::clearSmartyCache(); } catch (\Exception $e) {}
}
if ($this->checkPsAccountsInstalled()) {
$installed = true;
}
$useSsl = (bool)Configuration::get('PS_SSL_ENABLED_EVERYWHERE') || (bool)Configuration::get('PS_SSL_ENABLED');
$shop_base_url = $this->context->link->getBaseLink((int)$this->context->shop->id, $useSsl);
$this->context->smarty->assign([
'ps_account' => $installed,
'module_dir' => $this->_path,
'shop_base_url' => $shop_base_url,
]);
$output .= $this->context->smarty->fetch($this->local_path . 'views/templates/admin/configure.tpl');
$output .= $this->renderForm();
$output .= $this->context->smarty->fetch($this->local_path . 'views/templates/admin/copyright.tpl');
return $output;
}
protected function postProcess()
{
$enabled = (bool)Tools::getValue('PS_ACCOUNTS_LOGIN_ENABLED');
Configuration::updateValue(
'PS_ACCOUNTS_LOGIN_ENABLED',
(string)(int)$enabled,
);
}
protected function renderForm()
{
$defaultLang = (int)Configuration::get('PS_LANG_DEFAULT');
// Value read respecting the current context
$ctx = Shop::getContext();
$idShop = ($ctx === Shop::CONTEXT_SHOP) ? (int)$this->context->shop->id : null;
$idGroup = ($ctx === Shop::CONTEXT_GROUP) ? (int)$this->context->shop->id_shop_group : null;
$current = Configuration::get('PS_ACCOUNTS_LOGIN_ENABLED', null, $idGroup, $idShop);
$fieldsForm = [
'form' => [
'legend' => ['title' => $this->l('PS Accounts Settings')],
'input' => [
[
'type' => 'switch',
'label' => $this->l('Enable PS Accounts login'),
'name' => 'PS_ACCOUNTS_LOGIN_ENABLED',
'is_bool' => true,
'desc' => $this->l('When OFF, login handled by the ps_accounts module is disabled, reverting to the standard PS login.'),
'values' => [
['id' => 'on', 'value' => 1, 'label' => $this->l('Yes')],
['id' => 'off', 'value' => 0, 'label' => $this->l('No')],
],
],
],
'submit' => [
'title' => $this->l('Save'),
'name' => 'submitPsAccountsToggle'
],
],
];
$helper = new HelperForm();
$helper->show_toolbar = false;
$helper->table = $this->table;
$helper->default_form_language = $defaultLang;
$helper->allow_employee_form_lang = (int)Configuration::get('PS_BO_ALLOW_EMPLOYEE_FORM_LANG');
$helper->module = $this;
$helper->identifier = $this->identifier;
$helper->submit_action = 'submitPsAccountsToggle';
$helper->currentIndex = AdminController::$currentIndex.'&configure='.$this->name;
$helper->token = Tools::getAdminTokenLite('AdminModules');
$helper->fields_value = [
'PS_ACCOUNTS_LOGIN_ENABLED' => (int)(bool)$current,
];
return $helper->generateForm([$fieldsForm]);
}
}