-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathchangeorderindex.php
More file actions
237 lines (210 loc) · 8.74 KB
/
changeorderindex.php
File metadata and controls
237 lines (210 loc) · 8.74 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
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
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
<?php
if (!defined('_PS_VERSION_')) {
exit;
}
class Changeorderindex extends Module
{
public function __construct()
{
$this->name = 'changeorderindex';
$this->tab = 'administration';
$this->version = '1.0.0';
$this->author = 'Łukasz Ryszkiewicz';
$this->author_uri = 'https://ryszkiewicz.cloud';
$this->need_instance = 0;
$this->ps_versions_compliancy = array(
'min' => '1.7',
'max' => _PS_VERSION_);
$this->bootstrap = true;
parent::__construct();
$this->displayName = $this->l('Change Order Index');
$this->description = $this->l('This module override Order class to change order reference.');
$this->confirmUninstall = $this->l('Uninstall module?');
}
public function install()
{
if (Shop::isFeatureActive()) {
Shop::setContext(Shop::CONTEXT_ALL);
}
return parent::install() &&
Configuration::updateValue('CHANGEORDERINDEX_OVERRIDE_ENABLED', false) &&
Configuration::updateValue('CHANGEORDERINDEX_PFX', "PFX") &&
Configuration::updateValue('CHANGEORDERINDEX_PFX_SEPARATOR', false);
}
public function uninstall()
{
Configuration::deleteByName('CHANGEORDERINDEX_OVERRIDE_ENABLED');
Configuration::deleteByName('CHANGEORDERINDEX_PFX');
Configuration::deleteByName('CHANGEORDERINDEX_PFX_SEPARATOR');
return parent::uninstall();
}
public function checkOverride()
{
return file_exists(_PS_ROOT_DIR_.'/override/classes/order/Order.php');
}
public function getContent()
{
$output = '';
if (Tools::isSubmit('submit_'.$this->name)) {
if ($this->postProcess()) {
$output .= $this->displayConfirmation($this->l('Settings saved'));
} else {
$output .= $this->displayWarning($this->l('Something went wrong! Check form values.'));
}
}
$vars = array(
$this->name . '_name' => $this->displayName,
$this->name . '_version' => $this->version,
$this->name . '_compliancy' => $this->ps_versions_compliancy['min'],
$this->name.'_enabled' => Module::isEnabled('changeorderindex'),
$this->name.'_override_enabled' => Configuration::get('CHANGEORDERINDEX_OVERRIDE_ENABLED'),
$this->name.'_preview'=> Order::generateReference(),
$this->name.'_short_desc'=> $this->description,
$this->name.'_overrideok'=> $this->checkOverride(),
$this->name.'_logo' => $this->getPathUri()."/logo.png",
);
$this->context->smarty->assign($vars);
$output .= $this->context->smarty->fetch($this->local_path . 'views/templates/admin/header.tpl');
$output .= $this->displayForm();
$output .= $this->context->smarty->fetch($this->local_path . 'views/templates/admin/footer.tpl');
return $output;
}
public function displayForm()
{
$fields_form = array(
'form' => array(
'legend' => array(
'title' => $this->l('Module settings'),
'icon' => 'icon-cogs'
),
'input' => array(
# Switch override
array(
'type' => 'switch',
'label' => $this->l('Enable override?'),
'name' => 'CHANGEORDERINDEX_OVERRIDE_ENABLED',
'is_bool' => true,
'desc' => $this->l('Set "Yes" to enable override orders class.
Override will not work if not enabled here even if file exists in /overrides directory.
'),
'values' => array(
array(
'id' => 'active_on',
'value' => true,
'label' => $this->l('On')
),
array(
'id' => 'active_off',
'value' => false,
'label' => $this->l('Off')
)
),
),
# Preview
array(
'name' => 'separator',
'type' => 'html',
'label' => $this->l('Next order reference').'<br>'.$this->l('number will be: '),
'html_content' => '
<div class="row">
<div class="panel" style="width:250px; padding:0 25px 0 25px">
<span style="font-size:36px;">'.Order::generateReference().'</span>
</div>
</div>
',
'ignore' => true
),
# Prefix
array(
'type' => 'text',
'label' => $this->l('Prefix'),
'class' => 't',
'name' => 'CHANGEORDERINDEX_PFX',
'desc' => $this->l('Prefix can be letters or numbers (max 3)'),
'size' => '3'
),
# Prefix separator
array(
'type' => 'switch',
'label' => $this->l('Use prefix separator?'),
'name' => 'CHANGEORDERINDEX_PFX_SEPARATOR',
'is_bool' => true,
'desc' => $this->l('Set "Yes" to enable "-" separator.'),
'values' => array(
array(
'id' => 'active_on',
'value' => true,
'label' => $this->l('On')
),
array(
'id' => 'active_off',
'value' => false,
'label' => $this->l('Off')
)
),
),
),
'submit' => array(
'title' => $this->l('Save')
)
),
);
$lang = new Language((int) Configuration::get('PS_LANG_DEFAULT'));
$helper = new HelperForm();
$helper->show_toolbar = true;
$helper->toolbar_scroll = true;
$helper->table = $this->table;
$helper->default_form_language = $lang->id;
$helper->module = $this;
$helper->allow_employee_form_lang = Configuration::get('PS_BO_ALLOW_EMPLOYEE_FORM_LANG') ?
Configuration::get('PS_BO_ALLOW_EMPLOYEE_FORM_LANG') : 0;
$helper->identifier = $this->identifier;
$helper->submit_action = 'submit_'.$this->name;
$helper->currentIndex = $this->context->link->getAdminLink('AdminModules', false).
'&configure='.$this->name.
'&tab_module='.$this->tab.
'&module_name='.$this->name;
$helper->token = Tools::getAdminTokenLite('AdminModules');
$helper->fields_value[
'CHANGEORDERINDEX_OVERRIDE_ENABLED'
] = Configuration::get('CHANGEORDERINDEX_OVERRIDE_ENABLED');
$helper->fields_value[
'CHANGEORDERINDEX_PFX'
] = Configuration::get('CHANGEORDERINDEX_PFX');
$helper->fields_value[
'CHANGEORDERINDEX_PFX_SEPARATOR'
] = Configuration::get('CHANGEORDERINDEX_PFX_SEPARATOR');
return $helper->generateForm(array($fields_form));
}
protected function postProcess()
{
$pfx = Tools::substr(
Tools::strtoupper(
preg_replace(
"/[^a-zA-Z0-9]+/",
"",
Tools::getValue('CHANGEORDERINDEX_PFX')
)
),
0,
3
);
if (Configuration::updateValue(
'CHANGEORDERINDEX_OVERRIDE_ENABLED',
(bool)Tools::getValue('CHANGEORDERINDEX_OVERRIDE_ENABLED')
) &&
Configuration::updateValue(
'CHANGEORDERINDEX_PFX',
$pfx
) &&
Configuration::updateValue(
'CHANGEORDERINDEX_PFX_SEPARATOR',
(bool)Tools::getValue('CHANGEORDERINDEX_PFX_SEPARATOR')
)
) {
return true;
} else {
return false;
}
}
}