Skip to content

Commit 6068654

Browse files
authored
Merge pull request #1 from sms77io/dev
BulkSMS: added options ; added refund event
2 parents 6fce7ac + 45fb2a2 commit 6068654

26 files changed

+703
-331
lines changed

.gitignore

100644100755
Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,2 @@
11
.idea/
2-
vendor/
3-
*.zip
4-
TODO
2+
vendor/

LICENSE

100644100755
File mode changed.

README.md

100644100755
Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
![Sms77.io Logo](https://www.sms77.io/wp-content/uploads/2019/07/sms77-Logo-400x79.png "sms77")
21
# sms77.io PrestaShop module
32

43
## Installation
@@ -23,6 +22,9 @@ Available message placeholders:
2322
- {1} => Last name
2423
- {2} => Order-ID (where available)
2524

26-
#### Screenshots
27-
#### Screenshots
28-
![Screenshot of plugin settings](https://tettra-production.s3.us-west-2.amazonaws.com/0d6efb4f154041e899af17bdcd19c1b5/bcac36a50716f4f73cd84020c4bf091d/d822b155a4112474fdb7aea5ee22465e/cb30d8dd64d0e83fcc7822a40f1703d9/mLBF1Q0g4SCVCXQSEfzElQAJBvxDiaqqTTSqY2lS.png "PrestaShop.Sms77: Settings")
25+
#### Implemented Events
26+
- SMS77_MSG_ON_DELIVERY (orderState->id = 5)
27+
- SMS77_MSG_ON_INVOICE (orderState->id = [1, 10, 13])
28+
- SMS77_MSG_ON_PAYMENT (orderState->id = [2, 11])
29+
- SMS77_MSG_ON_REFUND (orderState->id = 7)
30+
- SMS77_MSG_ON_SHIPMENT (orderState->id = 4)

classes/Constants.php

100644100755
Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,7 @@
1313
* @license LICENSE
1414
*/
1515

16-
abstract class Constants
17-
{
16+
abstract class Constants {
1817
const API_KEY = 'SMS77_API_KEY';
1918
const BULK = 'SMS77_BULK';
2019
const BULK_COUNTRIES = 'SMS77_BULK_COUNTRIES';
@@ -23,11 +22,13 @@ abstract class Constants
2322
const MSG_ON_DELIVERY = 'SMS77_MSG_ON_DELIVERY';
2423
const MSG_ON_INVOICE = 'SMS77_MSG_ON_INVOICE';
2524
const MSG_ON_PAYMENT = 'SMS77_MSG_ON_PAYMENT';
25+
const MSG_ON_REFUND = 'SMS77_MSG_ON_REFUND';
2626
const MSG_ON_SHIPMENT = 'SMS77_MSG_ON_SHIPMENT';
2727
const ON_DELIVERY = 'SMS77_ON_DELIVERY';
2828
const ON_INVOICE = 'SMS77_ON_INVOICE';
2929
const ON_PAYMENT = 'SMS77_ON_PAYMENT';
3030
const ON_SHIPMENT = 'SMS77_ON_SHIPMENT';
31+
const ON_REFUND = 'SMS77_ON_REFUND';
3132
const SIGNATURE = 'SMS77_SIGNATURE';
3233
const SIGNATURE_POSITION = 'SMS77_SIGNATURE_POSITION';
3334

@@ -38,14 +39,17 @@ abstract class Constants
3839
self::MSG_ON_DELIVERY => false,
3940
self::MSG_ON_INVOICE => false,
4041
self::MSG_ON_PAYMENT => false,
42+
self::MSG_ON_REFUND => false,
4143
self::MSG_ON_SHIPMENT => false,
4244
self::ON_DELIVERY => 'Dear {0} {1}. Your order #{2} has been delivered. Enjoy your goods!',
43-
self::ON_INVOICE => 'Dear {0} {1}. An invoice has been generated for your order #{2}.
44-
Log in to your account in order to have a look at it. Best regards!',
45-
self::ON_PAYMENT => 'Dear {0} {1}. A payment has been made for your order #{2}.
46-
Log in to your account for more information. Best regards!',
47-
self::ON_SHIPMENT => 'Dear {0} {1}. Your order #{2} has been shipped.
48-
Log in to your customer account for more information. Best regards!',
45+
self::ON_INVOICE => 'Dear {0} {1}. An invoice has been generated for your order #{2}.'
46+
. ' Log in to your account in order to have a look at it. Best regards!',
47+
self::ON_PAYMENT => 'Dear {0} {1}. A payment has been made for your order #{2}.'
48+
. ' Log in to your account for more information. Best regards!',
49+
self::ON_REFUND => 'Dear {0} {1}. A refund has been initiated for order #{2}.'
50+
. ' Log in to your account for more information. Best regards!',
51+
self::ON_SHIPMENT => 'Dear {0} {1}. Your order #{2} has been shipped.'
52+
. ' Log in to your customer account for more information. Best regards!',
4953
self::SIGNATURE => '',
5054
self::SIGNATURE_POSITION => 'append',
5155
];

classes/Form.php

100644100755
Lines changed: 42 additions & 78 deletions
Original file line numberDiff line numberDiff line change
@@ -1,48 +1,34 @@
11
<?php
22
/**
33
* NOTICE OF LICENSE
4-
*
54
* This file is licenced under the Software License Agreement.
65
* With the purchase or the installation of the software in your application
76
* you accept the licence agreement.
8-
*
97
* You must not modify, adapt or create derivative works of this source code
10-
*
118
* @author sms77.io
129
* @copyright 2019-present sms77 e.K.
1310
* @license LICENSE
1411
*/
1512

16-
require_once __DIR__ . "/../controllers/admin/Sms77AdminController.php";
17-
require_once __DIR__ . "/Constants.php";
18-
19-
class Form extends HelperForm
20-
{
13+
class Form extends HelperForm {
2114
public function __construct($name) {
2215
parent::__construct();
2316
$defaultLang = (int)Configuration::get('PS_LANG_DEFAULT');
2417
$this->allow_employee_form_lang = $defaultLang;
2518
$this->currentIndex = Sms77AdminController::$currentIndex . "&configure=$name";
2619
$this->default_form_language = $defaultLang;
2720

28-
$setFieldsValue = function ($k, $v) {
29-
$name = "config[$k]";
21+
foreach (Configuration::getMultiple(array_keys(Constants::CONFIGURATION))
22+
as $k => $v) {
23+
$optionName = "config[$k]";
3024

3125
if (is_array($v)) {
32-
$name .= '[]';
26+
$optionName .= '[]';
3327
}
3428

35-
$this->fields_value[$name] = $v;
36-
};
37-
38-
foreach (Configuration::getMultiple(array_keys(Constants::CONFIGURATION)) as $k => $v) {
39-
$setFieldsValue($k, $v);
29+
$this->fields_value[$optionName] = $v;
4030
}
4131

42-
$toName = function ($key) {
43-
return "config[$key]";
44-
};
45-
4632
$this->fields_form = [
4733
[
4834
'form' => [
@@ -57,7 +43,7 @@ public function __construct($name) {
5743
[
5844
'tab' => 'settings',
5945
'type' => 'text',
60-
'name' => $toName(Constants::API_KEY),
46+
'name' => FormUtil::toName(Constants::API_KEY),
6147
'label' => $this->l('API-Key'),
6248
'hint' => $this->l('Your sms77.io API-Key.'),
6349
'desc' => $this->l('An API-Key is needed for sending. Get yours now at sms77.io'),
@@ -84,10 +70,15 @@ public function __construct($name) {
8470
'Text on delivery?',
8571
'Send a text message after delivery?'
8672
),
73+
$this->makeBool(
74+
'REFUND',
75+
'Text on refund?',
76+
'Send a text message after refund initiation?'
77+
),
8778
[
8879
'tab' => 'settings',
8980
'type' => 'text',
90-
'name' => $toName(Constants::FROM),
81+
'name' => FormUtil::toName(Constants::FROM),
9182
'label' => $this->l('From'),
9283
'hint' => $this->l('Set a custom sender number or name.'),
9384
'desc' => $this->l('Max 11 alphanumeric or 16 numeric characters.'),
@@ -109,25 +100,18 @@ public function __construct($name) {
109100
'ON_DELIVERY',
110101
'Sets the text message sent to the customer after delivery.'
111102
),
103+
$this->makeTextarea(
104+
'ON_REFUND',
105+
'Sets the text message sent to the customer after refund.'
106+
),
112107
$this->makeTextarea(
113108
'SIGNATURE',
114109
'Sets a signature to add to all messages.'
115110
),
116-
[
117-
'tab' => 'settings',
118-
'type' => 'radio',
119-
'name' => $toName(Constants::SIGNATURE_POSITION),
120-
'label' => $this->l('Signature position'),
121-
'hint' => $this->l('Decides at which position the signature gets inserted.'),
122-
'desc' => $this->l('Decides at which position the signature gets inserted.'),
123-
'values' => array_map(function ($pos) {
124-
return [
125-
'id' => "sms77_config_signature_position_$pos",
126-
'label' => $pos,
127-
'value' => $pos,
128-
];
129-
}, Constants::SIGNATURE_POSITIONS),
130-
],
111+
FormUtil::signaturePosition(
112+
$this->l('Signature position'),
113+
$this->l('Decides at which position the signature gets inserted.'),
114+
'settings', true),
131115
],
132116
'submit' => [
133117
'title' => $this->l('Save'),
@@ -148,57 +132,37 @@ public function __construct($name) {
148132
'save' =>
149133
[
150134
'desc' => $this->l('Save'),
151-
'href' => Sms77AdminController::$currentIndex . "&configure=$name&save$name&token="
135+
'href' => Sms77AdminController::$currentIndex
136+
. "&configure=$name&save$name&token="
152137
. Tools::getAdminTokenLite('AdminModules'),
153138
],
154139
'back' => [
155-
'href' => Sms77AdminController::$currentIndex . '&token=' . Tools::getAdminTokenLite('AdminModules'),
140+
'href' => Sms77AdminController::$currentIndex
141+
. '&token=' . Tools::getAdminTokenLite('AdminModules'),
156142
'desc' => $this->l('Back to list'),
157143
],
158144
];
159145
$this->toolbar_scroll = true;
160146
}
161147

162-
private function makeTextarea($action, $trans, $tab = 'settings') {
163-
$trans = $this->l($trans);
164-
165-
return [
166-
'tab' => $tab,
167-
'type' => 'textarea',
168-
'name' => "config[SMS77_$action]",
169-
'label' => $trans,
170-
'hint' => $trans,
171-
'desc' => $trans,
172-
];
173-
}
174-
175-
private function makeSwitch($action, $label, $desc, $values, $isBool) {
176-
$descHit = $this->l($desc);
177-
178-
return [
179-
'tab' => 'settings',
180-
'type' => 'switch',
181-
'name' => "config[SMS77_$action]",
182-
'label' => $this->l($label),
183-
'desc' => $descHit,
184-
'hint' => $descHit,
185-
'is_bool' => $isBool,
186-
'values' => $values,
187-
];
188-
}
189-
148+
/**
149+
* @param string $action
150+
* @param string $label
151+
* @param string $desc
152+
* @return array
153+
*/
190154
private function makeBool($action, $label, $desc) {
191-
$sAction = Tools::strtolower($action);
155+
return FormUtil::makeSwitch("config[SMS77_MSG_ON_$action]",
156+
$label, Tools::strtolower($action), true, 'settings', $desc);
157+
}
192158

193-
return $this->makeSwitch("MSG_ON_$action", $label, $desc, [
194-
[
195-
'id' => 'on_' . $sAction . '_on',
196-
'value' => 1,
197-
],
198-
[
199-
'id' => 'on_' . $sAction . '_off',
200-
'value' => 0,
201-
],
202-
], true);
159+
/**
160+
* @param string $action
161+
* @param string $trans
162+
* @return array
163+
*/
164+
private function makeTextarea($action, $trans) {
165+
return FormUtil::makeTextarea(
166+
"config[SMS77_$action]", $trans, 'settings');
203167
}
204168
}

classes/FormUtil.php

Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
<?php
2+
/**
3+
* NOTICE OF LICENSE
4+
* This file is licenced under the Software License Agreement.
5+
* With the purchase or the installation of the software in your application
6+
* you accept the licence agreement.
7+
* You must not modify, adapt or create derivative works of this source code
8+
* @author sms77.io
9+
* @copyright 2019-present sms77 e.K.
10+
* @license LICENSE
11+
*/
12+
13+
class FormUtil {
14+
public static function signaturePosition($label, $hintDesc, $tab, $toName) {
15+
return [
16+
'tab' => $tab,
17+
'type' => 'radio',
18+
'name' => $toName
19+
? self::toName(Constants::SIGNATURE_POSITION)
20+
: Constants::SIGNATURE_POSITION,
21+
'label' => $label,
22+
'hint' => $hintDesc,
23+
'desc' => $hintDesc,
24+
'values' => array_map(static function($pos) {
25+
return [
26+
'id' => "sms77_config_signature_position_$pos",
27+
'label' => $pos,
28+
'value' => $pos,
29+
];
30+
}, Constants::SIGNATURE_POSITIONS),
31+
];
32+
}
33+
34+
public static function toName($key) {
35+
return "config[$key]";
36+
}
37+
38+
/**
39+
* @param string $name
40+
* @param string $text
41+
* @param string | null $tab
42+
* @return array
43+
*/
44+
public static function makeTextarea($name, $text, $tab) {
45+
return [
46+
'desc' => $text,
47+
'hint' => $text,
48+
'label' => $text,
49+
'name' => $name,
50+
'tab' => $tab,
51+
'type' => 'textarea',
52+
];
53+
}
54+
55+
/**
56+
* @param string $name
57+
* @param string $label
58+
* @param string $shortAction
59+
* @param boolean $isBool
60+
* @param string | null $tab
61+
* @param string|null $desc
62+
* @return array
63+
*/
64+
public static function makeSwitch($name, $label, $shortAction = null,
65+
$isBool = false, $tab = null, $desc = null) {
66+
if (!$shortAction) {
67+
$shortAction = $name;
68+
}
69+
70+
$values = [
71+
[
72+
'id' => $shortAction . '_on',
73+
'value' => 1,
74+
],
75+
[
76+
'id' => $shortAction . '_off',
77+
'value' => 0,
78+
],
79+
];
80+
81+
return [
82+
'desc' => $desc,
83+
'hint' => $desc,
84+
'is_bool' => $isBool,
85+
'label' => $label,
86+
'name' => $name,
87+
'tab' => $tab,
88+
'type' => 'switch',
89+
'values' => $values,
90+
];
91+
}
92+
}

classes/OrderPersonalizer.php

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
<?php
2+
/**
3+
* NOTICE OF LICENSE
4+
*
5+
* This file is licenced under the Software License Agreement.
6+
* With the purchase or the installation of the software in your application
7+
* you accept the licence agreement.
8+
*
9+
* You must not modify, adapt or create derivative works of this source code
10+
*
11+
* @author sms77.io
12+
* @copyright 2019-present sms77 e.K.
13+
* @license LICENSE
14+
*/
15+
16+
class OrderPersonalizer extends Personalizer {
17+
/**
18+
* OrderPersonalizer constructor.
19+
* @param string $action
20+
* @param array $address
21+
* @param int $orderId
22+
*/
23+
public function __construct($action, $address, $orderId) {
24+
parent::__construct(Configuration::get("SMS77_ON_$action"));
25+
26+
$this->addAddress($address);
27+
28+
$this->addPlaceholders([$orderId]);
29+
30+
$this->fillPlaceholders();
31+
}
32+
}

0 commit comments

Comments
 (0)