Newer
Older
<?php
/**
* This file contains package_quiqqer_coupons_ajax_create
*/
use QUI\ERP\Coupons\Handler;
use QUI\Utils\Security\Orthos;
/**
*
* @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;
if (!empty($attributes['amount'])) {
$amount = (int)$attributes['amount'];
unset($attributes['amount']);
}
$discountIds = [];
if (!empty($attributes['discountIds'])) {
$discountIds = explode(',', $attributes['discountIds']);
}
$couponCodes[] = Handler::createCouponCode($discountIds, $attributes);
} catch (\QUI\ERP\Coupons\CouponCodeException $Exception) {
QUI::getMessagesHandler()->addError(
QUI::getLocale()->get(
)
);
return false;
} catch (QUI\Permissions\Exception $Exception) {
throw $Exception;
} catch (\Exception $Exception) {
QUI\System\Log::writeException($Exception);
QUI::getMessagesHandler()->addError(
QUI::getLocale()->get(
'message.ajax.general_error'
)
);
return false;
}
QUI::getMessagesHandler()->addSuccess(
QUI::getLocale()->get(
'message.ajax.create.success'
)
);
return true;
},