Newer
Older
<?php
/**
* This file contains package_quiqqer_coupons_ajax_create
*/
use QUI\ERP\Coupons\Handler;
use QUI\Utils\Security\Orthos;
/**
* Edit a CouponCode
*
* @param array $attributes
* @return bool - success
*/
QUI::$Ajax->registerFunction(
'package_quiqqer_coupons_ajax_edit',
function ($id, $attributes) {
$id = (int)$id;
$attributes = Orthos::clearArray(\json_decode($attributes, true));
try {
$discountIds = [];
if (!empty($attributes['discountIds'])) {
$discountIds = \explode(',', $attributes['discountIds']);
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
}
$couponCodes[] = Handler::editCouponCode($id, $discountIds, $attributes);
} catch (\QUI\ERP\Coupons\CouponCodeException $Exception) {
QUI::getMessagesHandler()->addError(
QUI::getLocale()->get(
'quiqqer/coupons',
'message.ajax.edit.error',
[
'id' => $id,
'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/coupons',
'message.ajax.general_error'
)
);
return false;
}
QUI::getMessagesHandler()->addSuccess(
QUI::getLocale()->get(
'quiqqer/coupons',
'message.ajax.edit.success',
[
'id' => $id
]
)
);
return true;
},
['id', 'attributes'],
'Permission::checkAdminUser'
);