Skip to content

Commit e80706f

Browse files
committed
added signature and position
1 parent d8d626a commit e80706f

19 files changed

+1921
-2114
lines changed

Constants.php

+35
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
<?php
2+
3+
/**
4+
* NOTICE OF LICENSE
5+
*
6+
* This file is licenced under the Software License Agreement.
7+
* With the purchase or the installation of the software in your application
8+
* you accept the licence agreement.
9+
*
10+
* You must not modify, adapt or create derivative works of this source code
11+
*
12+
* @author sms77.io
13+
* @copyright 2019-present sms77 e.K.
14+
* @license LICENSE
15+
*/
16+
class Constants
17+
{
18+
public static $configuration = [
19+
'SMS77_API_KEY' => '',
20+
'SMS77_BULK' => '',
21+
'SMS77_FROM' => '',
22+
'SMS77_MSG_ON_DELIVERY' => false,
23+
'SMS77_MSG_ON_INVOICE' => false,
24+
'SMS77_MSG_ON_PAYMENT' => false,
25+
'SMS77_MSG_ON_SHIPMENT' => false,
26+
'SMS77_ON_DELIVERY' => 'Dear {0} {1}. Your order #{2} has been delivered. Enjoy your goods!',
27+
'SMS77_ON_INVOICE' => 'Dear {0} {1}. An invoice has been generated for your order #{2}. Log in to your account in order to have a look at it. Best regards!',
28+
'SMS77_ON_PAYMENT' => 'Dear {0} {1}. A payment has been made for your order #{2}. Log in to your account for more information. Best regards!',
29+
'SMS77_ON_SHIPMENT' => 'Dear {0} {1}. Your order #{2} has been shipped. Log in to your customer account for more information. Best regards!',
30+
'SMS77_SIGNATURE' => '',
31+
'SMS77_SIGNATURE_POSITION' => 'append',
32+
];
33+
34+
public static $signature_positions = ['append', 'prepend',];
35+
}

forms/BackendHelperForm.php renamed to Form.php

+63-50
Original file line numberDiff line numberDiff line change
@@ -13,33 +13,26 @@
1313
* @license LICENSE
1414
*/
1515

16-
class BackendHelperForm extends HelperForm
16+
class Form extends HelperForm
1717
{
1818
public function __construct($name)
1919
{
20-
parent::__construct($name);
21-
22-
$defaultLang = Configuration::get('PS_LANG_DEFAULT');
20+
parent::__construct();
2321

22+
$defaultLang = (int)Configuration::get('PS_LANG_DEFAULT');
2423
$this->allow_employee_form_lang = $defaultLang;
25-
2624
$this->currentIndex = AdminController::$currentIndex . "&configure=$name";
27-
2825
$this->default_form_language = $defaultLang;
2926

30-
$this->fields_value = [
31-
'config[SMS77_API_KEY]' => Configuration::get('SMS77_API_KEY'),
32-
'config[SMS77_ON_INVOICE]' => Configuration::get('SMS77_ON_INVOICE'),
33-
'config[SMS77_ON_DELIVERY]' => Configuration::get('SMS77_ON_DELIVERY'),
34-
'config[SMS77_ON_SHIPMENT]' => Configuration::get('SMS77_ON_SHIPMENT'),
35-
'config[SMS77_ON_PAYMENT]' => Configuration::get('SMS77_ON_PAYMENT'),
36-
'config[SMS77_MSG_ON_DELIVERY]' => Configuration::get('SMS77_MSG_ON_DELIVERY'),
37-
'config[SMS77_MSG_ON_INVOICE]' => Configuration::get('SMS77_MSG_ON_INVOICE'),
38-
'config[SMS77_MSG_ON_SHIPMENT]' => Configuration::get('SMS77_MSG_ON_SHIPMENT'),
39-
'config[SMS77_MSG_ON_PAYMENT]' => Configuration::get('SMS77_MSG_ON_PAYMENT'),
40-
'config[SMS77_FROM]' => Configuration::get('SMS77_FROM'),
41-
'config[SMS77_ON_GENERIC]' => Configuration::get('SMS77_ON_GENERIC'),
42-
];
27+
$configuration = Configuration::getMultiple(array_keys(Constants::$configuration));
28+
29+
foreach ($configuration as $k => $v) {
30+
$configuration["config[$k]"] = $v;
31+
32+
unset($configuration[$k]);
33+
}
34+
35+
$this->fields_value = $configuration;
4336

4437
$this->fields_form = [
4538
[
@@ -62,22 +55,22 @@ public function __construct($name)
6255
'required' => true,
6356
],
6457

65-
$this->makeSwitch(
58+
$this->makeBool(
6659
'INVOICE',
6760
'Text on invoice generation?',
6861
'Send a text message after an invoice has been created?'
6962
),
70-
$this->makeSwitch(
63+
$this->makeBool(
7164
'PAYMENT',
7265
'Text on payment?',
7366
'Send a text message after payment has been received?'
7467
),
75-
$this->makeSwitch(
68+
$this->makeBool(
7669
'SHIPMENT',
7770
'Text on shipment?',
7871
'Send a text message after shipment?'
7972
),
80-
$this->makeSwitch(
73+
$this->makeBool(
8174
'DELIVERY',
8275
'Text on delivery?',
8376
'Send a text message after delivery?'
@@ -92,23 +85,42 @@ public function __construct($name)
9285
'size' => 16,
9386
],
9487
$this->makeTextarea(
95-
'INVOICE',
88+
'ON_INVOICE',
9689
'Sets the text message sent to the customer after invoice generation.'
9790
),
9891
$this->makeTextarea(
99-
'PAYMENT',
92+
'ON_PAYMENT',
10093
'Sets the text message sent to the customer after payment.'
10194
),
10295
$this->makeTextarea(
103-
'SHIPMENT',
96+
'ON_SHIPMENT',
10497
'Sets the text message sent to the customer after shipment.'
10598
),
10699
$this->makeTextarea(
107-
'DELIVERY',
100+
'ON_DELIVERY',
108101
'Sets the text message sent to the customer after delivery.'
109102
),
110103
$this->makeTextarea(
111-
'GENERIC',
104+
'SIGNATURE',
105+
'Sets a signature to add to all messages.'
106+
),
107+
[
108+
'tab' => 'settings',
109+
'type' => 'radio',
110+
'name' => 'config[SMS77_SIGNATURE_POSITION]',
111+
'label' => $this->l('Signature position'),
112+
'hint' => $this->l('Decides at which position the signature gets inserted.'),
113+
'desc' => $this->l('Decides at which position the signature gets inserted.'),
114+
'values' => array_map(function ($pos) {
115+
return [
116+
'id' => "sms77_config_signature_position_$pos",
117+
'label' => $pos,
118+
'value' => $pos,
119+
];
120+
}, Constants::$signature_positions),
121+
],
122+
$this->makeTextarea(
123+
'BULK',
112124
'Send out any message to all of your customers.',
113125
'bulk'
114126
),
@@ -122,18 +134,14 @@ public function __construct($name)
122134
];
123135

124136
$this->module = $this;
125-
126137
$this->name = $name;
127-
128138
$this->name_controller = $name;
129-
130139
$this->title = $name;
131140

132141
$this->token = Tools::getAdminTokenLite('AdminModules');
133142

134143
$this->show_toolbar = true;
135-
136-
$this->submit_action = 'submit' . $name;
144+
$this->submit_action = "submit$name";
137145

138146
$this->toolbar_btn = [
139147
'save' =>
@@ -158,37 +166,42 @@ private function makeTextarea($action, $trans, $tab = 'settings')
158166
return [
159167
'tab' => $tab,
160168
'type' => 'textarea',
161-
'name' => "config[SMS77_ON_$action]",
169+
'name' => "config[SMS77_$action]",
162170
'label' => $trans,
163171
'hint' => $trans,
164172
'desc' => $trans,
165173
];
166174
}
167175

168-
private function makeSwitch($action, $label, $desc, $tab = 'settings')
176+
private function makeSwitch($action, $label, $desc, $values, $isBool)
169177
{
170178
$descHit = $this->l($desc);
171179

172180
return [
173-
'tab' => $tab,
181+
'tab' => 'settings',
174182
'type' => 'switch',
175-
'name' => "config[SMS77_MSG_ON_$action]",
183+
'name' => "config[SMS77_$action]",
176184
'label' => $this->l($label),
177185
'desc' => $descHit,
178186
'hint' => $descHit,
179-
'is_bool' => true,
180-
'values' => [
181-
[
182-
'id' => 'on_' . Tools::strtolower($action) . '_on',
183-
'value' => 1,
184-
'label' => $this->l('Yes'),
185-
],
186-
[
187-
'id' => 'on_' . Tools::strtolower($action) . '_off',
188-
'value' => 0,
189-
'label' => $this->l('No'),
190-
],
191-
],
187+
'is_bool' => $isBool,
188+
'values' => $values,
192189
];
193190
}
191+
192+
private function makeBool($action, $label, $desc)
193+
{
194+
$sAction = Tools::strtolower($action);
195+
196+
return $this->makeSwitch("MSG_ON_$action", $label, $desc, [
197+
[
198+
'id' => 'on_' . $sAction . '_on',
199+
'value' => 1
200+
],
201+
[
202+
'id' => 'on_' . $sAction . '_off',
203+
'value' => 0
204+
],
205+
], true);
206+
}
194207
}

composer.json

+3-2
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
}
99
],
1010
"config": {
11+
"preferred-install": "disgt",
1112
"prepend-autoloader": false
1213
},
1314
"description": "Sms77.io API module for PrestaShop applications.",
@@ -22,7 +23,7 @@
2223
"prefer-stable": true,
2324
"require": {
2425
"php": ">=5.6.0",
25-
"sms77/api": "dev-master",
26+
"sms77/api": "1.0.0",
2627
"giggsey/libphonenumber-for-php": "^8.11"
2728
},
2829
"support": {
@@ -32,4 +33,4 @@
3233
"docs": "https://github.com/sms77io/prestashop-module"
3334
},
3435
"type": "prestashop-module"
35-
}
36+
}

forms/index.php

-23
This file was deleted.

logo.png

100644100755
File mode changed.

0 commit comments

Comments
 (0)