Newer
Older
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
<?php
/**
* This file contains package_quiqqer_coupons_ajax_create
*/
use QUI\ERP\Coupons\Handler;
use QUI\Utils\Security\Orthos;
/**
* Create new InviteCode(s)
*
* @param array $attributes
* @return bool - success
*/
QUI::$Ajax->registerFunction(
'package_quiqqer_coupons_ajax_create',
function ($attributes) {
$attributes = Orthos::clearArray(json_decode($attributes, true));
try {
$amount = 1;
$inviteCodes = array();
if (!empty($attributes['amount'])) {
$amount = (int)$attributes['amount'];
unset($attributes['amount']);
}
for ($i = 0; $i < $amount; $i++) {
$inviteCodes[] = Handler::createCouponCode($attributes);
}
} catch (\QUI\ERP\Coupons\CouponCodeException $Exception) {
QUI::getMessagesHandler()->addError(
QUI::getLocale()->get(
'quiqqer/invitecode',
'message.ajax.create.error',
array(
'error' => $Exception->getMessage()
)
)
);
return false;
} catch (QUI\Permissions\Exception $Exception) {
throw $Exception;
} catch (\Exception $Exception) {
QUI\System\Log::writeException($Exception);
QUI::getMessagesHandler()->addError(
QUI::getLocale()->get(
'quiqqer/invitecode',
'message.ajax.general_error'
)
);
return false;
}
QUI::getMessagesHandler()->addSuccess(
QUI::getLocale()->get(
'quiqqer/invitecode',
'message.ajax.create.success'
)
);
return true;
},
array('attributes'),
'Permission::checkAdminUser'
);